removed all checkstyle errors, updated sprint backlog
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / dataschema / ReservationTest.java
1 /*
2 * Copyright (c) 2015 Berner Fachhochschule, Switzerland.
3 *
4 * Project Smart Reservation System.
5 *
6 * Distributable under GPL license. See terms of license at gnu.org.
7 */
8 package ch.bfh.ti.srs.dataschema;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotEquals;
12
13 import java.util.UUID;
14
15 import org.junit.Before;
16 import org.junit.Test;
17
18 import ch.bfh.ti.daterange.DateFactory;
19 import ch.bfh.ti.daterange.DateRange;
20 import ch.bfh.ti.daterange.DateRangeFactory;
21 import ch.bfh.ti.srs.dataschema.Reservation;
22 import ch.bfh.ti.srs.dataschema.Resource;
23 import ch.bfh.ti.srs.dataschema.User;
24
25 public class ReservationTest {
26
27 private DateRangeFactory factory;
28
29 @Before
30 public void setUp() throws Exception {
31 String className = System.getProperty("daterangefactory.name",
32 "ch.bfh.ti.daterange.impl.pojo.DateRangeFactory");
33 Class<?> clazz = Class.forName(className);
34 factory = (DateRangeFactory) clazz.newInstance();
35 }
36
37 @Test
38 public void createReservationTest() throws Exception {
39 User testUser = new User("TestUser", "pass");
40 Resource testResource = new Resource("N321", "class room");
41 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),
42 DateFactory.createDate(2015, 11, 13));
43 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,
44 "TestReservation");
45
46 assertNotEquals(null, testReservation.getId());
47 assertNotEquals(null, testReservation.getGroupId());
48 assertEquals(testUser, testReservation.getUser());
49 assertEquals(testResource, testReservation.getResource());
50 assertEquals(testDr, testReservation.getDateRange());
51 assertEquals("TestReservation", testReservation.getRemark());
52 }
53
54 @Test
55 public void setAndGetNameTest() throws Exception {
56 User testUser = new User("TestUser", "pass");
57 Resource testResource = new Resource("N321", "class room");
58 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),
59 DateFactory.createDate(2015, 11, 13));
60 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,
61 "TestReservation");
62
63 testReservation.setRemark("otherTestReservation");
64 assertEquals("otherTestReservation", testReservation.getRemark());
65 }
66
67 @Test
68 public void setAndGetUserTest() throws Exception {
69 User testUser = new User("TestUser", "pass");
70 Resource testResource = new Resource("N321", "class room");
71 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),
72 DateFactory.createDate(2015, 11, 13));
73 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,
74 "TestReservation");
75
76 User otherTestUser = new User("otherTestUser", "pass");
77 testReservation.setUser(otherTestUser);
78 assertEquals(otherTestUser, testReservation.getUser());
79 }
80
81 @Test
82 public void setAndGetResourceTest() throws Exception {
83 User testUser = new User("TestUser", "pass");
84 Resource testResource = new Resource("N321", "class room");
85 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),
86 DateFactory.createDate(2015, 11, 13));
87 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,
88 "TestReservation");
89
90 Resource OtherTestResource = new Resource("N421", "lecture hall");
91 testReservation.setResource(OtherTestResource);
92 assertEquals(OtherTestResource, testReservation.getResource());
93 }
94
95 @Test
96 public void setAndGetDateRangeTest() throws Exception {
97 User testUser = new User("TestUser", "pass");
98 Resource testResource = new Resource("N321", "class room");
99 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),
100 DateFactory.createDate(2015, 11, 13));
101 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,
102 "TestReservation");
103
104 DateRange otherTestDr = factory.createDateRange(DateFactory.createDate(2015, 12, 9),
105 DateFactory.createDate(2015, 12, 13));
106 testReservation.setDateRange(otherTestDr);
107 assertEquals(otherTestDr, testReservation.getDateRange());
108 }
109 }