Added isModified method to Resource, Reservation.
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / dataschema / ReservationTest.java
CommitLineData
9a78ca13
MT
1/*\r
2 * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
3 *\r
4 * Project Smart Reservation System.\r
5 *\r
6 * Distributable under GPL license. See terms of license at gnu.org.\r
7 */\r
496127a5 8package ch.bfh.ti.srs.dataschema;\r
9a78ca13
MT
9\r
10import static org.junit.Assert.assertEquals;\r
912c75db 11import static org.junit.Assert.assertFalse;\r
a49c468f 12import static org.junit.Assert.assertNotEquals;\r
912c75db 13import static org.junit.Assert.assertTrue;\r
a49c468f
MT
14\r
15import java.util.UUID;\r
9a78ca13
MT
16\r
17import org.junit.Before;\r
18import org.junit.Test;\r
19\r
20import ch.bfh.ti.daterange.DateFactory;\r
21import ch.bfh.ti.daterange.DateRange;\r
22import ch.bfh.ti.daterange.DateRangeFactory;\r
23import ch.bfh.ti.srs.dataschema.Reservation;\r
24import ch.bfh.ti.srs.dataschema.Resource;\r
25import ch.bfh.ti.srs.dataschema.User;\r
26\r
27public class ReservationTest {\r
28\r
29 private DateRangeFactory factory;\r
a49c468f 30\r
9a78ca13
MT
31 @Before\r
32 public void setUp() throws Exception {\r
33 String className = System.getProperty("daterangefactory.name",\r
34 "ch.bfh.ti.daterange.impl.pojo.DateRangeFactory");\r
35 Class<?> clazz = Class.forName(className);\r
36 factory = (DateRangeFactory) clazz.newInstance();\r
37 }\r
a49c468f 38\r
9a78ca13
MT
39 @Test\r
40 public void createReservationTest() throws Exception {\r
41 User testUser = new User("TestUser", "pass");\r
42 Resource testResource = new Resource("N321", "class room");\r
a49c468f
MT
43 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
44 DateFactory.createDate(2015, 11, 13));\r
66cc653d
D
45 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
46 "TestReservation");\r
47\r
a49c468f
MT
48 assertNotEquals(null, testReservation.getId());\r
49 assertNotEquals(null, testReservation.getGroupId());\r
9a78ca13
MT
50 assertEquals(testUser, testReservation.getUser());\r
51 assertEquals(testResource, testReservation.getResource());\r
52 assertEquals(testDr, testReservation.getDateRange());\r
81c3aac6 53 assertEquals("TestReservation", testReservation.getRemark());\r
a49c468f 54 }\r
66cc653d 55\r
912c75db
MT
56 @Test(expected = IllegalArgumentException.class)\r
57 public void createReservationInvalidUserTest() throws Exception {\r
58 Resource testResource = new Resource("N321", "class room");\r
59 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
60 DateFactory.createDate(2015, 11, 13));\r
61 Reservation testReservation = new Reservation(UUID.randomUUID(), null, testResource, testDr, "TestReservation");\r
62 }\r
63\r
64 @Test(expected = IllegalArgumentException.class)\r
65 public void createReservationInvalidResourceTest() throws Exception {\r
66 User testUser = new User("TestUser", "pass");\r
67 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
68 DateFactory.createDate(2015, 11, 13));\r
69 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, null, testDr, "TestReservation");\r
70 }\r
71\r
9a78ca13
MT
72 @Test\r
73 public void setAndGetNameTest() throws Exception {\r
74 User testUser = new User("TestUser", "pass");\r
75 Resource testResource = new Resource("N321", "class room");\r
a49c468f
MT
76 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
77 DateFactory.createDate(2015, 11, 13));\r
66cc653d
D
78 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
79 "TestReservation");\r
a49c468f 80\r
81c3aac6
MT
81 testReservation.setRemark("otherTestReservation");\r
82 assertEquals("otherTestReservation", testReservation.getRemark());\r
9a78ca13 83 }\r
a49c468f 84\r
9a78ca13
MT
85 @Test\r
86 public void setAndGetUserTest() throws Exception {\r
87 User testUser = new User("TestUser", "pass");\r
88 Resource testResource = new Resource("N321", "class room");\r
a49c468f
MT
89 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
90 DateFactory.createDate(2015, 11, 13));\r
66cc653d
D
91 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
92 "TestReservation");\r
a49c468f 93\r
9a78ca13
MT
94 User otherTestUser = new User("otherTestUser", "pass");\r
95 testReservation.setUser(otherTestUser);\r
96 assertEquals(otherTestUser, testReservation.getUser());\r
97 }\r
a49c468f 98\r
9a78ca13
MT
99 @Test\r
100 public void setAndGetResourceTest() throws Exception {\r
101 User testUser = new User("TestUser", "pass");\r
102 Resource testResource = new Resource("N321", "class room");\r
a49c468f
MT
103 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
104 DateFactory.createDate(2015, 11, 13));\r
66cc653d
D
105 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
106 "TestReservation");\r
a49c468f 107\r
912c75db
MT
108 Resource otherTestResource = new Resource("N421", "lecture hall");\r
109 testReservation.setResource(otherTestResource);\r
110 assertEquals(otherTestResource, testReservation.getResource());\r
9a78ca13 111 }\r
a49c468f 112\r
9a78ca13
MT
113 @Test\r
114 public void setAndGetDateRangeTest() throws Exception {\r
115 User testUser = new User("TestUser", "pass");\r
116 Resource testResource = new Resource("N321", "class room");\r
a49c468f
MT
117 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
118 DateFactory.createDate(2015, 11, 13));\r
66cc653d
D
119 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
120 "TestReservation");\r
a49c468f
MT
121\r
122 DateRange otherTestDr = factory.createDateRange(DateFactory.createDate(2015, 12, 9),\r
123 DateFactory.createDate(2015, 12, 13));\r
9a78ca13
MT
124 testReservation.setDateRange(otherTestDr);\r
125 assertEquals(otherTestDr, testReservation.getDateRange());\r
126 }\r
912c75db
MT
127\r
128 @Test\r
129 public void isModifiedTest() throws Exception {\r
130 User testUser = new User("TestUser", "pass");\r
131 Resource testResource = new Resource("N321", "class room");\r
132 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
133 DateFactory.createDate(2015, 11, 13));\r
134 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
135 "TestReservation");\r
136 Reservation clonedTestReservation = testReservation.clone();\r
137 \r
138 assertTrue(testReservation.isModified(null));\r
139 assertFalse(testReservation.isModified(testReservation));\r
140 assertFalse(testReservation.isModified(clonedTestReservation));\r
141 \r
142 User otherTestUser = new User("otherTestUser", "pass");\r
143 clonedTestReservation.setUser(otherTestUser);\r
144 assertTrue(testReservation.isModified(clonedTestReservation));\r
145 \r
146 clonedTestReservation.setUser(testUser);\r
147 assertFalse(testReservation.isModified(clonedTestReservation));\r
148\r
149 Resource otherTestResource = new Resource("N421", "lecture hall");\r
150 clonedTestReservation.setResource(otherTestResource);\r
151 assertTrue(testReservation.isModified(clonedTestReservation));\r
152 \r
153 clonedTestReservation.setResource(testResource);\r
154 assertFalse(testReservation.isModified(clonedTestReservation));\r
155 \r
156 DateRange otherTestDr = factory.createDateRange(DateFactory.createDate(2015, 12, 9),\r
157 DateFactory.createDate(2015, 12, 13));\r
158 clonedTestReservation.setDateRange(otherTestDr);\r
159 assertTrue(testReservation.isModified(clonedTestReservation));\r
160 \r
161 clonedTestReservation.setDateRange(testDr);\r
162 assertFalse(testReservation.isModified(clonedTestReservation));\r
163 \r
164 clonedTestReservation.setRemark("some other remark");\r
165 assertTrue(testReservation.isModified(clonedTestReservation));\r
166 }\r
9a78ca13 167}\r