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