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