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