SessionController added/updated
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / controller / UserControllerTest.java
CommitLineData
1ec0e01f
M
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
e3535133 8package ch.bfh.ti.srs.controller;\r
1ec0e01f 9\r
9e071834
M
10import static org.junit.Assert.assertEquals;\r
11import static org.junit.Assert.assertFalse;\r
12import static org.junit.Assert.assertTrue;\r
1ec0e01f 13\r
5a196189
M
14import java.util.ArrayList;\r
15import java.util.Date;\r
5a196189
M
16import java.util.List;\r
17import java.util.Map;\r
5a196189
M
18import java.util.UUID;\r
19\r
1ec0e01f
M
20import org.junit.Test;\r
21\r
5a196189
M
22import ch.bfh.ti.daterange.DateRange;\r
23import ch.bfh.ti.daterange.impl.pojo.DateRangeImpl;\r
e3535133
M
24import ch.bfh.ti.srs.datahandler.DataHandler;\r
25import ch.bfh.ti.srs.datahandler.DataHandlerForTests;\r
5a196189
M
26import ch.bfh.ti.srs.dataschema.Reservation;\r
27import ch.bfh.ti.srs.dataschema.Resource;\r
28import ch.bfh.ti.srs.dataschema.User;\r
e3535133 29\r
1ec0e01f
M
30/**\r
31 * @author Michael Grossen\r
32 */\r
33public class UserControllerTest {\r
1ec0e01f 34 @Test\r
66cc653d 35 public void addUserTest() throws Exception {\r
1f7b5004 36 DataHandler dh = new DataHandlerForTests();\r
b2fc6c71
M
37 SessionController sc = new SessionController();\r
38 UserController uc = new UserController(dh,sc);\r
66cc653d 39\r
da277fcf 40 //uc.setDataHandler(dh);\r
1f7b5004
M
41 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
42 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
43 uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
44 uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
45 }\r
66cc653d
D
46\r
47 @Test(expected = Exception.class)\r
48 public void addUserExceptionTest() throws Exception {\r
1f7b5004 49 DataHandler dh = new DataHandlerForTests();\r
b2fc6c71
M
50 SessionController sc = new SessionController();\r
51 UserController uc = new UserController(dh,sc);\r
da277fcf 52 uc.setDataHandler(null);\r
66cc653d 53\r
1f7b5004
M
54 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
55 }\r
30d10517 56 \r
5a196189 57 @Test\r
66cc653d 58 public void getUserTest() throws Exception {\r
5a196189 59 DataHandler dh = new DataHandlerForTests();\r
da277fcf 60 UserController uc = new UserController(dh);\r
66cc653d 61\r
da277fcf 62 //uc.setDataHandler(dh);\r
5a196189
M
63 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
64 uc.logIn("TestUser1", "pass1");\r
65 assertEquals("grosm9@bfh.ch", uc.getUser("TestUser1").getMail());\r
66 }\r
66cc653d
D
67\r
68 @Test(expected = Exception.class)\r
69 public void getUserExceptionTest() throws Exception {\r
5a196189 70 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
71 UserController uc = new UserController(dh);\r
72 uc.setDataHandler(null);\r
66cc653d 73\r
5a196189
M
74 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
75 uc.logIn("TestUser1", "pass1");\r
76 assertEquals("grosm9@bfh.ch", uc.getUser("TestUser1").getMail());\r
77 }\r
30d10517 78 \r
66cc653d
D
79 @Test(expected = Exception.class)\r
80 public void getUserExpectionTest() throws Exception {\r
da277fcf
M
81 DataHandler dh = new DataHandlerForTests();\r
82 UserController uc = new UserController(dh);\r
83 uc.setDataHandler(null);\r
5a196189
M
84 uc.getUser(null);\r
85 }\r
30d10517 86 \r
47d70ad5 87 @SuppressWarnings("deprecation")\r
5a196189 88 @Test\r
66cc653d 89 public void getReservationTests() throws Exception {\r
5a196189 90 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
91 UserController uc = new UserController(dh);\r
92 //uc.setDataHandler(dh);\r
5a196189
M
93 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
94 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
95 uc.logIn("TestUser1", "pass1");\r
66cc653d 96\r
5a196189 97 UUID groupId = UUID.randomUUID();\r
66cc653d
D
98 Date start = new Date(2015, 11, 28, 11, 00, 00);\r
99 Date finish = new Date(2015, 11, 28, 11, 30, 00);\r
5a196189 100 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 101\r
5a196189
M
102 Resource resource1 = new Resource("Room101", "Class room");\r
103 Resource resource2 = new Resource("Room101", "Class room");\r
104 Resource resource3 = new Resource("Room101", "Class room");\r
105 dh.addResource(resource1);\r
106 dh.addResource(resource2);\r
107 dh.addResource(resource3);\r
66cc653d 108\r
5a196189 109 User testUser2 = uc.getUser("TestUser2");\r
66cc653d
D
110\r
111 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
112 "Test reservation1");\r
113 Reservation reservation2 = new Reservation(groupId, uc.getLoggedUser(), resource2, dateRange,\r
114 "Test reservation2");\r
5a196189
M
115 Reservation reservation3 = new Reservation(groupId, testUser2, resource3, dateRange, "Test reservation3");\r
116 dh.addReservation(reservation1);\r
117 dh.addReservation(reservation2);\r
118 dh.addReservation(reservation3);\r
66cc653d 119\r
5a196189
M
120 Map<Reservation, Boolean> loggedUserReservation = uc.getUserReservations(null);\r
121 Map<Reservation, Boolean> reservationMap = uc.getUserReservations(testUser2);\r
122 Map<Reservation, Boolean> reservationDateRangeMap = uc.getReservationsInDateRange(dateRange);\r
123 Map<Reservation, Boolean> reservationGroupMap = uc.getReservationGroup(groupId);\r
66cc653d 124\r
5a196189 125 assertEquals(reservationDateRangeMap, reservationGroupMap);\r
66cc653d 126\r
5a196189
M
127 assertTrue(loggedUserReservation.containsKey(reservation1));\r
128 assertTrue(loggedUserReservation.containsKey(reservation2));\r
129 assertFalse(loggedUserReservation.containsKey(reservation3));\r
130 assertTrue(reservationMap.containsKey(reservation3));\r
66cc653d 131\r
5a196189 132 for (Map.Entry<Reservation, Boolean> entry : reservationDateRangeMap.entrySet()) {\r
66cc653d 133 if (entry.getKey().getUser().getUserName().equals("TestUser1")) {\r
5a196189
M
134 assertTrue(entry.getValue());\r
135 assertEquals(entry.getKey().getId(), uc.getReservation(entry.getKey().getId()).getId());\r
66cc653d 136 } else {\r
5a196189
M
137 assertFalse(entry.getValue());\r
138 assertEquals(entry.getKey().getId(), uc.getReservation(entry.getKey().getId()).getId());\r
139 }\r
140 }\r
141 assertEquals(null, uc.getReservation(UUID.randomUUID()));\r
142 }\r
66cc653d
D
143\r
144 @Test(expected = Exception.class)\r
145 public void getReservationGroupException1Test() throws Exception {\r
da277fcf
M
146 DataHandler dh = new DataHandlerForTests();\r
147 UserController uc = new UserController(dh);\r
148 uc.setDataHandler(null);\r
5a196189
M
149 uc.getReservationGroup(null);\r
150 }\r
66cc653d
D
151\r
152 @Test(expected = IllegalArgumentException.class)\r
153 public void getReservationGroupException2Test() throws Exception {\r
5a196189 154 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
155 UserController uc = new UserController(dh);\r
156 //uc.setDataHandler(dh);\r
5a196189
M
157 uc.getReservationGroup(null);\r
158 }\r
66cc653d
D
159\r
160 @Test(expected = Exception.class)\r
161 public void getUserReservationException1Test() throws Exception {\r
da277fcf
M
162 DataHandler dh = new DataHandlerForTests();\r
163 UserController uc = new UserController(dh);\r
164 uc.setDataHandler(null);\r
5a196189
M
165 uc.getUserReservations(null);\r
166 }\r
66cc653d
D
167\r
168 @Test(expected = Exception.class)\r
169 public void getUserReservationException2Test() throws Exception {\r
5a196189 170 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
171 UserController uc = new UserController(dh);\r
172 //uc.setDataHandler(dh);\r
5a196189
M
173 uc.getUserReservations(null);\r
174 }\r
66cc653d
D
175\r
176 @Test(expected = Exception.class)\r
177 public void getReservationException1Test() throws Exception {\r
da277fcf
M
178 DataHandler dh = new DataHandlerForTests();\r
179 UserController uc = new UserController(dh);\r
5a196189
M
180 uc.getReservation(null);\r
181 }\r
66cc653d
D
182\r
183 @Test(expected = Exception.class)\r
184 public void getReservationException2Test() throws Exception {\r
5a196189 185 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
186 UserController uc = new UserController(dh);\r
187 //uc.setDataHandler(dh);\r
5a196189
M
188 uc.getReservation(null);\r
189 }\r
66cc653d
D
190\r
191 @Test(expected = Exception.class)\r
192 public void getReservationsInDateRangeException1Test() throws Exception {\r
da277fcf 193 UserController uc = new UserController(null);\r
5a196189
M
194 uc.getReservationsInDateRange(null);\r
195 }\r
66cc653d
D
196\r
197 @Test(expected = Exception.class)\r
198 public void getReservationsInDateRangeException2Test() throws Exception {\r
5a196189 199 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
200 UserController uc = new UserController(dh);\r
201 //uc.setDataHandler(dh);\r
5a196189
M
202 uc.getReservationsInDateRange(null);\r
203 }\r
66cc653d 204\r
47d70ad5 205 @SuppressWarnings("deprecation")\r
b18afc77 206 @Test\r
66cc653d 207 public void makeReservationTest() throws Exception {\r
5a196189 208 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
209 UserController uc = new UserController(dh);\r
210 //uc.setDataHandler(dh);\r
5a196189
M
211 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
212 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
213 uc.logIn("TestUser1", "pass1");\r
66cc653d 214\r
5a196189
M
215 Resource resource1 = new Resource("Room101", "Class room");\r
216 Resource resource2 = new Resource("Room101", "Class room");\r
217 Resource resource3 = new Resource("Room101", "Class room");\r
218 dh.addResource(resource1);\r
219 dh.addResource(resource2);\r
220 dh.addResource(resource3);\r
66cc653d 221\r
5a196189 222 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
223 for (int i = 1; i < 10; i++) {\r
224 dtList.add(new DateRangeImpl(new Date(2015, 12, 2 + i, 11, 00, 00), new Date(2015, 12, 2 + i, 11, 00, 00)));\r
5a196189 225 }\r
66cc653d 226\r
5a196189
M
227 assertEquals(null, uc.makeReservation(uc.getLoggedUser(), resource1, dtList, "remark"));\r
228 assertEquals(null, uc.makeReservation(null, resource2, dtList, "remark"));\r
229 }\r
66cc653d 230\r
47d70ad5 231 @SuppressWarnings("deprecation")\r
b18afc77 232 @Test\r
66cc653d 233 public void makeInvalidReservationTest() throws Exception {\r
5a196189 234 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
235 UserController uc = new UserController(dh);\r
236 //uc.setDataHandler(dh);\r
5a196189
M
237 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
238 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
239 uc.logIn("TestUser1", "pass1");\r
66cc653d 240\r
5a196189
M
241 Resource resource1 = new Resource("Room101", "Class room");\r
242 Resource resource2 = new Resource("Room101", "Class room");\r
243 Resource resource3 = new Resource("Room101", "Class room");\r
244 dh.addResource(resource1);\r
245 dh.addResource(resource2);\r
246 dh.addResource(resource3);\r
66cc653d 247\r
5a196189 248 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
249 for (int i = 1; i < 10; i++) {\r
250 dtList.add(new DateRangeImpl(new Date(2015, 12, 2 + i, 11, 00, 00), new Date(2015, 12, 2 + i, 12, 00, 00)));\r
5a196189 251 }\r
66cc653d 252\r
b18afc77
M
253 List<DateRange> conflictingList = new ArrayList<DateRange>();\r
254 // Conflicts\r
66cc653d
D
255 conflictingList.add(new DateRangeImpl(new Date(2015, 12, 4, 11, 00, 00), new Date(2015, 12, 4, 12, 00, 00)));\r
256 conflictingList.add(new DateRangeImpl(new Date(2015, 12, 4, 11, 15, 00), new Date(2015, 12, 4, 11, 45, 00)));\r
257 conflictingList.add(new DateRangeImpl(new Date(2015, 12, 4, 10, 00, 00), new Date(2015, 12, 4, 17, 00, 00)));\r
258 conflictingList.add(new DateRangeImpl(new Date(2015, 12, 4, 11, 30, 00), new Date(2015, 12, 4, 12, 30, 00)));\r
259\r
b18afc77 260 // OK\r
66cc653d
D
261 conflictingList.add(new DateRangeImpl(new Date(2015, 12, 4, 10, 30, 00), new Date(2015, 12, 4, 10, 59, 59)));\r
262 conflictingList.add(new DateRangeImpl(new Date(2015, 12, 4, 12, 00, 01), new Date(2015, 12, 4, 12, 45, 00)));\r
b18afc77 263\r
66cc653d 264 assertEquals(null, uc.makeReservation(uc.getLoggedUser(), resource1, dtList, "remark"));\r
b18afc77 265 assertEquals(4, uc.makeReservation(uc.getLoggedUser(), resource1, conflictingList, null).size());\r
5a196189
M
266 }\r
267\r
47d70ad5 268 @SuppressWarnings("deprecation")\r
66cc653d
D
269 @Test(expected = IllegalArgumentException.class)\r
270 public void makeReservationException1Test() throws Exception {\r
5a196189 271 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
272 UserController uc = new UserController(dh);\r
273 //uc.setDataHandler(dh);\r
5a196189
M
274 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
275 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
276 uc.logIn("TestUser1", "pass1");\r
66cc653d 277\r
5a196189
M
278 Resource resource1 = new Resource("Room101", "Class room");\r
279 Resource resource2 = new Resource("Room101", "Class room");\r
280 Resource resource3 = new Resource("Room101", "Class room");\r
281 dh.addResource(resource1);\r
282 dh.addResource(resource2);\r
283 dh.addResource(resource3);\r
66cc653d 284\r
5a196189 285 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
286 for (int i = 1; i < 10; i++) {\r
287 dtList.add(new DateRangeImpl(new Date(2015, 12, 2 + i, 11, 00, 00), new Date(2015, 12, 2 + i, 12, 00, 00)));\r
5a196189 288 }\r
66cc653d 289\r
5a196189
M
290 uc.logOut();\r
291 assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
292 }\r
293\r
47d70ad5 294 @SuppressWarnings("deprecation")\r
66cc653d
D
295 @Test(expected = IllegalArgumentException.class)\r
296 public void makeReservationException2Test() throws Exception {\r
5a196189 297 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
298 UserController uc = new UserController(dh);\r
299 //uc.setDataHandler(dh);\r
5a196189
M
300 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
301 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
302 uc.logIn("TestUser1", "pass1");\r
66cc653d 303\r
5a196189
M
304 Resource resource1 = new Resource("Room101", "Class room");\r
305 Resource resource2 = new Resource("Room101", "Class room");\r
306 Resource resource3 = new Resource("Room101", "Class room");\r
307 dh.addResource(resource1);\r
308 dh.addResource(resource2);\r
309 dh.addResource(resource3);\r
66cc653d 310\r
5a196189 311 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
312 for (int i = 1; i < 10; i++) {\r
313 dtList.add(new DateRangeImpl(new Date(2015, 12, 2 + i, 11, 00, 00), new Date(2015, 12, 2 + i, 12, 00, 00)));\r
5a196189 314 }\r
66cc653d 315\r
5a196189
M
316 assertEquals(null, uc.makeReservation(null, null, dtList, "remark"));\r
317 }\r
318\r
47d70ad5 319 @SuppressWarnings("deprecation")\r
66cc653d
D
320 @Test(expected = IllegalArgumentException.class)\r
321 public void makeReservationException3Test() throws Exception {\r
5a196189 322 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
323 UserController uc = new UserController(dh);\r
324 //uc.setDataHandler(dh);\r
5a196189
M
325 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
326 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
327 uc.logIn("TestUser1", "pass1");\r
66cc653d 328\r
5a196189
M
329 Resource resource1 = new Resource("Room101", "Class room");\r
330 Resource resource2 = new Resource("Room101", "Class room");\r
331 Resource resource3 = new Resource("Room101", "Class room");\r
332 dh.addResource(resource1);\r
333 dh.addResource(resource2);\r
334 dh.addResource(resource3);\r
66cc653d 335\r
5a196189 336 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
337 for (int i = 1; i < 10; i++) {\r
338 dtList.add(new DateRangeImpl(new Date(2015, 12, 2 + i, 11, 00, 00), new Date(2015, 12, 2 + i, 12, 00, 00)));\r
5a196189 339 }\r
66cc653d 340\r
5a196189
M
341 assertEquals(null, uc.makeReservation(null, resource1, null, "remark"));\r
342 }\r
343\r
66cc653d
D
344 @Test(expected = IllegalArgumentException.class)\r
345 public void makeReservationException4Test() throws Exception {\r
5a196189 346 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
347 UserController uc = new UserController(dh);\r
348 //uc.setDataHandler(dh);\r
5a196189
M
349 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
350 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
351 uc.logIn("TestUser1", "pass1");\r
66cc653d 352\r
5a196189
M
353 Resource resource1 = new Resource("Room101", "Class room");\r
354 Resource resource2 = new Resource("Room101", "Class room");\r
355 Resource resource3 = new Resource("Room101", "Class room");\r
356 dh.addResource(resource1);\r
357 dh.addResource(resource2);\r
358 dh.addResource(resource3);\r
66cc653d 359\r
5a196189 360 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d 361\r
5a196189
M
362 assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
363 }\r
66cc653d 364\r
47d70ad5 365 @SuppressWarnings("deprecation")\r
5a196189 366 @Test\r
66cc653d 367 public void changeReservationTest() throws Exception {\r
5a196189 368 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
369 UserController uc = new UserController(dh);\r
370 //uc.setDataHandler(dh);\r
5a196189
M
371 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
372 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
373 uc.logIn("TestUser1", "pass1");\r
66cc653d 374\r
5a196189 375 UUID groupId = UUID.randomUUID();\r
66cc653d
D
376 DateRange dateRange = new DateRangeImpl(new Date(2015, 12, 7, 14, 00, 00), new Date(2015, 12, 7, 15, 00, 00));\r
377\r
5a196189
M
378 Resource resource1 = new Resource("Room101", "Class room");\r
379 dh.addResource(resource1);\r
66cc653d 380\r
66cc653d
D
381 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
382 "Test reservation1");\r
5a196189 383 dh.addReservation(reservation1);\r
66cc653d 384\r
5a196189 385 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
66cc653d
D
386 DateRange newDateRange = new DateRangeImpl(new Date(2015, 12, 7, 20, 00, 00),\r
387 new Date(2015, 12, 8, 02, 00, 00));\r
5a196189
M
388 reservationClone.setDateRange(newDateRange);\r
389 uc.changeReservation(reservationClone);\r
66cc653d 390\r
5a196189
M
391 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
392 }\r
66cc653d 393\r
47d70ad5 394 @SuppressWarnings("deprecation")\r
66cc653d
D
395 @Test(expected = Exception.class)\r
396 public void changeReservationException1Test() throws Exception {\r
5a196189 397 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
398 UserController uc = new UserController(dh);\r
399 //uc.setDataHandler(dh);\r
5a196189
M
400 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
401 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
402 uc.logIn("TestUser1", "pass1");\r
66cc653d 403\r
5a196189
M
404 UUID groupId = UUID.randomUUID();\r
405 Date start = new Date();\r
406 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 407 Date finish = (Date) start.clone();\r
5a196189
M
408 finish.setMinutes(start.getMinutes() + 30);\r
409 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 410\r
5a196189
M
411 Resource resource1 = new Resource("Room101", "Class room");\r
412 dh.addResource(resource1);\r
66cc653d 413\r
66cc653d
D
414 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
415 "Test reservation1");\r
5a196189 416 dh.addReservation(reservation1);\r
66cc653d 417\r
5a196189
M
418 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
419 start.setDate(start.getDate() + 1);\r
420 finish.setDate(finish.getDate() + 1);\r
421 DateRange newDateRange = new DateRangeImpl(start, finish);\r
422 reservationClone.setDateRange(newDateRange);\r
66cc653d 423\r
5a196189
M
424 uc.setDataHandler(null);\r
425 uc.changeReservation(reservationClone);\r
66cc653d 426\r
5a196189
M
427 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
428 }\r
66cc653d 429\r
47d70ad5 430 @SuppressWarnings("deprecation")\r
66cc653d
D
431 @Test(expected = Exception.class)\r
432 public void changeReservationException2Test() throws Exception {\r
5a196189 433 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
434 UserController uc = new UserController(dh);\r
435 //uc.setDataHandler(dh);\r
5a196189
M
436 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
437 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
438 uc.logIn("TestUser1", "pass1");\r
66cc653d 439\r
5a196189
M
440 UUID groupId = UUID.randomUUID();\r
441 Date start = new Date();\r
442 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 443 Date finish = (Date) start.clone();\r
5a196189
M
444 finish.setMinutes(start.getMinutes() + 30);\r
445 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 446\r
5a196189
M
447 Resource resource1 = new Resource("Room101", "Class room");\r
448 dh.addResource(resource1);\r
66cc653d 449\r
66cc653d
D
450 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
451 "Test reservation1");\r
5a196189 452 dh.addReservation(reservation1);\r
66cc653d 453\r
5a196189
M
454 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
455 start.setDate(start.getDate() + 1);\r
456 finish.setDate(finish.getDate() + 1);\r
457 DateRange newDateRange = new DateRangeImpl(start, finish);\r
458 reservationClone.setDateRange(newDateRange);\r
66cc653d 459\r
5a196189
M
460 uc.logOut();\r
461 uc.changeReservation(reservationClone);\r
66cc653d 462\r
5a196189
M
463 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
464 }\r
66cc653d 465\r
47d70ad5 466 @SuppressWarnings("deprecation")\r
66cc653d
D
467 @Test(expected = IllegalArgumentException.class)\r
468 public void changeReservationException3Test() throws Exception {\r
5a196189 469 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
470 UserController uc = new UserController(dh);\r
471 //uc.setDataHandler(dh);\r
5a196189
M
472 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
473 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
474 uc.logIn("TestUser1", "pass1");\r
66cc653d 475\r
5a196189
M
476 UUID groupId = UUID.randomUUID();\r
477 Date start = new Date();\r
478 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 479 Date finish = (Date) start.clone();\r
5a196189
M
480 finish.setMinutes(start.getMinutes() + 30);\r
481 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 482\r
5a196189
M
483 Resource resource1 = new Resource("Room101", "Class room");\r
484 dh.addResource(resource1);\r
66cc653d 485\r
66cc653d
D
486 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
487 "Test reservation1");\r
5a196189 488 dh.addReservation(reservation1);\r
66cc653d 489\r
5a196189
M
490 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
491 start.setDate(start.getDate() + 1);\r
492 finish.setDate(finish.getDate() + 1);\r
493 DateRange newDateRange = new DateRangeImpl(start, finish);\r
494 reservationClone.setDateRange(newDateRange);\r
66cc653d 495\r
5a196189 496 uc.changeReservation(null);\r
66cc653d 497\r
5a196189
M
498 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
499 }\r
66cc653d 500\r
47d70ad5 501 @SuppressWarnings("deprecation")\r
66cc653d
D
502 @Test(expected = Exception.class)\r
503 public void changeReservationException4Test() throws Exception {\r
5a196189 504 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
505 UserController uc = new UserController(dh);\r
506 //uc.setDataHandler(dh);\r
5a196189
M
507 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
508 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
509 uc.logIn("TestUser1", "pass1");\r
66cc653d 510\r
5a196189
M
511 UUID groupId = UUID.randomUUID();\r
512 Date start = new Date();\r
513 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 514 Date finish = (Date) start.clone();\r
5a196189
M
515 finish.setMinutes(start.getMinutes() + 30);\r
516 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 517\r
5a196189
M
518 Resource resource1 = new Resource("Room101", "Class room");\r
519 dh.addResource(resource1);\r
66cc653d 520\r
66cc653d
D
521 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
522 "Test reservation1");\r
5a196189 523 dh.addReservation(reservation1);\r
66cc653d 524\r
5a196189
M
525 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
526 start.setDate(start.getDate() + 1);\r
527 finish.setDate(finish.getDate() + 1);\r
528 DateRange newDateRange = new DateRangeImpl(start, finish);\r
529 reservationClone.setDateRange(newDateRange);\r
66cc653d 530\r
5a196189
M
531 uc.logOut();\r
532 uc.logIn("TestUser2", "pass2");\r
533 uc.changeReservation(reservationClone);\r
66cc653d 534\r
5a196189
M
535 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
536 }\r
66cc653d 537\r
47d70ad5 538 @SuppressWarnings("deprecation")\r
5a196189 539 @Test\r
66cc653d 540 public void deleteReservationTest() throws Exception {\r
5a196189 541 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
542 UserController uc = new UserController(dh);\r
543 //uc.setDataHandler(dh);\r
5a196189
M
544 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
545 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
546 uc.logIn("TestUser1", "pass1");\r
66cc653d 547\r
5a196189
M
548 UUID groupId = UUID.randomUUID();\r
549 Date start = new Date();\r
550 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 551 Date finish = (Date) start.clone();\r
5a196189
M
552 finish.setMinutes(start.getMinutes() + 30);\r
553 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 554\r
5a196189
M
555 Resource resource1 = new Resource("Room101", "Class room");\r
556 dh.addResource(resource1);\r
66cc653d 557\r
66cc653d
D
558 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
559 "Test reservation1");\r
5a196189 560 dh.addReservation(reservation1);\r
66cc653d 561\r
5a196189 562 uc.deleteReservation(reservation1);\r
66cc653d 563\r
5a196189
M
564 assertEquals(null, uc.getReservation(reservation1.getId()));\r
565 }\r
66cc653d 566\r
47d70ad5 567 @SuppressWarnings("deprecation")\r
66cc653d
D
568 @Test(expected = Exception.class)\r
569 public void deleteReservationException1Test() throws Exception {\r
5a196189 570 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
571 UserController uc = new UserController(dh);\r
572 //uc.setDataHandler(dh);\r
5a196189
M
573 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
574 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
575 uc.logIn("TestUser1", "pass1");\r
66cc653d 576\r
5a196189
M
577 UUID groupId = UUID.randomUUID();\r
578 Date start = new Date();\r
579 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 580 Date finish = (Date) start.clone();\r
5a196189
M
581 finish.setMinutes(start.getMinutes() + 30);\r
582 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 583\r
5a196189
M
584 Resource resource1 = new Resource("Room101", "Class room");\r
585 dh.addResource(resource1);\r
66cc653d 586\r
66cc653d
D
587 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
588 "Test reservation1");\r
5a196189 589 dh.addReservation(reservation1);\r
66cc653d 590\r
5a196189
M
591 uc.setDataHandler(null);\r
592 uc.deleteReservation(reservation1);\r
66cc653d 593\r
5a196189
M
594 assertEquals(null, uc.getReservation(reservation1.getId()));\r
595 }\r
66cc653d 596\r
47d70ad5 597 @SuppressWarnings("deprecation")\r
66cc653d
D
598 @Test(expected = Exception.class)\r
599 public void deleteReservationException2Test() throws Exception {\r
5a196189 600 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
601 UserController uc = new UserController(dh);\r
602 //uc.setDataHandler(dh);\r
5a196189
M
603 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
604 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
605 uc.logIn("TestUser1", "pass1");\r
66cc653d 606\r
5a196189
M
607 UUID groupId = UUID.randomUUID();\r
608 Date start = new Date();\r
609 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 610 Date finish = (Date) start.clone();\r
5a196189
M
611 finish.setMinutes(start.getMinutes() + 30);\r
612 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 613\r
5a196189
M
614 Resource resource1 = new Resource("Room101", "Class room");\r
615 dh.addResource(resource1);\r
66cc653d 616\r
66cc653d
D
617 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
618 "Test reservation1");\r
5a196189 619 dh.addReservation(reservation1);\r
66cc653d 620\r
5a196189
M
621 uc.logOut();\r
622 uc.deleteReservation(reservation1);\r
66cc653d 623\r
5a196189
M
624 assertEquals(null, uc.getReservation(reservation1.getId()));\r
625 }\r
66cc653d 626\r
47d70ad5 627 @SuppressWarnings("deprecation")\r
66cc653d
D
628 @Test(expected = IllegalArgumentException.class)\r
629 public void deleteReservationException3Test() throws Exception {\r
5a196189 630 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
631 UserController uc = new UserController(dh);\r
632 //uc.setDataHandler(dh);\r
5a196189
M
633 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
634 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
635 uc.logIn("TestUser1", "pass1");\r
66cc653d 636\r
5a196189
M
637 UUID groupId = UUID.randomUUID();\r
638 Date start = new Date();\r
639 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 640 Date finish = (Date) start.clone();\r
5a196189
M
641 finish.setMinutes(start.getMinutes() + 30);\r
642 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 643\r
5a196189
M
644 Resource resource1 = new Resource("Room101", "Class room");\r
645 dh.addResource(resource1);\r
66cc653d 646\r
66cc653d
D
647 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
648 "Test reservation1");\r
5a196189 649 dh.addReservation(reservation1);\r
66cc653d 650\r
5a196189 651 uc.deleteReservation(null);\r
66cc653d 652\r
5a196189
M
653 assertEquals(null, uc.getReservation(reservation1.getId()));\r
654 }\r
66cc653d 655\r
47d70ad5 656 @SuppressWarnings("deprecation")\r
66cc653d
D
657 @Test(expected = Exception.class)\r
658 public void deleteReservationException4Test() throws Exception {\r
5a196189 659 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
660 UserController uc = new UserController(dh);\r
661 //uc.setDataHandler(dh);\r
5a196189
M
662 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
663 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
664 uc.logIn("TestUser1", "pass1");\r
66cc653d 665\r
5a196189
M
666 UUID groupId = UUID.randomUUID();\r
667 Date start = new Date();\r
668 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 669 Date finish = (Date) start.clone();\r
5a196189
M
670 finish.setMinutes(start.getMinutes() + 30);\r
671 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 672\r
5a196189
M
673 Resource resource1 = new Resource("Room101", "Class room");\r
674 dh.addResource(resource1);\r
66cc653d 675\r
66cc653d
D
676 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
677 "Test reservation1");\r
5a196189 678 dh.addReservation(reservation1);\r
66cc653d 679\r
5a196189
M
680 uc.logOut();\r
681 uc.logIn("TestUser2", "pass2");\r
682 uc.deleteReservation(reservation1);\r
66cc653d 683\r
5a196189
M
684 assertEquals(null, uc.getReservation(reservation1.getId()));\r
685 }\r
66cc653d 686\r
47d70ad5 687 @SuppressWarnings("deprecation")\r
5a196189 688 @Test\r
66cc653d 689 public void getResourcesTest() throws Exception {\r
5a196189 690 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
691 UserController uc = new UserController(dh);\r
692 //uc.setDataHandler(dh);\r
5a196189
M
693 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
694 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
695 uc.logIn("TestUser1", "pass1");\r
66cc653d 696\r
5a196189
M
697 Date start = new Date();\r
698 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 699 Date finish = (Date) start.clone();\r
5a196189 700 finish.setMinutes(start.getMinutes() + 30);\r
66cc653d 701\r
5a196189
M
702 Resource resource1 = new Resource("Room101", "Class room");\r
703 Resource resource2 = new Resource("Room101", "Class room");\r
704 Resource resource3 = new Resource("Room101", "Class room");\r
705 dh.addResource(resource1);\r
706 dh.addResource(resource2);\r
707 dh.addResource(resource3);\r
66cc653d 708\r
5a196189 709 List<Resource> resList = uc.getResources();\r
66cc653d
D
710\r
711 assertEquals(3, resList.size());\r
5a196189 712 }\r
66cc653d 713\r
47d70ad5 714 @SuppressWarnings("deprecation")\r
66cc653d
D
715 @Test(expected = Exception.class)\r
716 public void getResourcesExceptionTest() throws Exception {\r
5a196189 717 DataHandler dh = new DataHandlerForTests();\r
da277fcf
M
718 UserController uc = new UserController(dh);\r
719 //uc.setDataHandler(dh);\r
5a196189
M
720 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
721 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
722 uc.logIn("TestUser1", "pass1");\r
66cc653d 723\r
5a196189
M
724 Date start = new Date();\r
725 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 726 Date finish = (Date) start.clone();\r
5a196189 727 finish.setMinutes(start.getMinutes() + 30);\r
66cc653d 728\r
5a196189
M
729 Resource resource1 = new Resource("Room101", "Class room");\r
730 Resource resource2 = new Resource("Room101", "Class room");\r
731 Resource resource3 = new Resource("Room101", "Class room");\r
732 dh.addResource(resource1);\r
733 dh.addResource(resource2);\r
734 dh.addResource(resource3);\r
66cc653d 735\r
5a196189
M
736 uc.setDataHandler(null);\r
737 List<Resource> resList = uc.getResources();\r
66cc653d
D
738\r
739 assertEquals(3, resList.size());\r
5a196189 740 }\r
1ec0e01f 741}\r