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