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
1ec0e01f
M
1/*\r
2 * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
3 *\r
4 * Project Smart Reservation System.\r
5 *\r
6 * Distributable under GPL license. See terms of license at gnu.org.\r
7 */\r
e3535133 8package ch.bfh.ti.srs.controller;\r
1ec0e01f 9\r
9e071834
M
10import static org.junit.Assert.assertEquals;\r
11import static org.junit.Assert.assertFalse;\r
12import static org.junit.Assert.assertTrue;\r
1ec0e01f 13\r
5a196189
M
14import java.util.ArrayList;\r
15import java.util.Date;\r
5a196189
M
16import java.util.List;\r
17import java.util.Map;\r
c1191616 18import java.util.Set;\r
5a196189
M
19import java.util.UUID;\r
20\r
1ec0e01f
M
21import org.junit.Test;\r
22\r
5a196189
M
23import ch.bfh.ti.daterange.DateRange;\r
24import ch.bfh.ti.daterange.impl.pojo.DateRangeImpl;\r
e3535133
M
25import ch.bfh.ti.srs.datahandler.DataHandler;\r
26import ch.bfh.ti.srs.datahandler.DataHandlerForTests;\r
5a196189
M
27import ch.bfh.ti.srs.dataschema.Reservation;\r
28import ch.bfh.ti.srs.dataschema.Resource;\r
29import ch.bfh.ti.srs.dataschema.User;\r
e3535133 30\r
1ec0e01f
M
31/**\r
32 * @author Michael Grossen\r
33 */\r
34public class UserControllerTest {\r
1ec0e01f 35 @Test\r
66cc653d 36 public void addUserTest() throws Exception {\r
1f7b5004 37 DataHandler dh = new DataHandlerForTests();\r
c1191616 38 SessionController sc = new SessionController(dh);\r
66cc653d 39\r
c1191616
M
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
b07a6f5c
M
44 \r
45 UserController uc = new UserController(dh, sc);\r
46 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
1f7b5004 47 }\r
66cc653d
D
48\r
49 @Test(expected = Exception.class)\r
b07a6f5c 50 public void addUserExceptionTest1() throws Exception {\r
c1191616 51 SessionController sc = new SessionController(null);\r
66cc653d 52\r
c1191616 53 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
1f7b5004 54 }\r
b07a6f5c
M
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
30d10517 62 \r
5a196189 63 @Test\r
66cc653d 64 public void getUserTest() throws Exception {\r
5a196189 65 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
5a196189
M
75 assertEquals("grosm9@bfh.ch", uc.getUser("TestUser1").getMail());\r
76 }\r
66cc653d
D
77\r
78 @Test(expected = Exception.class)\r
79 public void getUserExceptionTest() throws Exception {\r
5a196189 80 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
81 SessionController sc = new SessionController(dh);\r
82 UserController uc = new UserController(null,sc);\r
66cc653d 83\r
5a196189
M
84 assertEquals("grosm9@bfh.ch", uc.getUser("TestUser1").getMail());\r
85 }\r
30d10517 86 \r
66cc653d
D
87 @Test(expected = Exception.class)\r
88 public void getUserExpectionTest() throws Exception {\r
da277fcf 89 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
da277fcf 99 uc.setDataHandler(null);\r
5a196189
M
100 uc.getUser(null);\r
101 }\r
30d10517 102 \r
47d70ad5 103 @SuppressWarnings("deprecation")\r
5a196189 104 @Test\r
66cc653d 105 public void getReservationTests() throws Exception {\r
5a196189 106 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
5a196189 118 UUID groupId = UUID.randomUUID();\r
66cc653d
D
119 Date start = new Date(2015, 11, 28, 11, 00, 00);\r
120 Date finish = new Date(2015, 11, 28, 11, 30, 00);\r
5a196189 121 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 122\r
5a196189
M
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
66cc653d 129\r
5a196189 130 User testUser2 = uc.getUser("TestUser2");\r
66cc653d 131\r
c1191616 132 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 133 "Test reservation1");\r
c1191616 134 Reservation reservation2 = new Reservation(groupId, sc.getLoggedUser(), resource2, dateRange,\r
66cc653d 135 "Test reservation2");\r
5a196189
M
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
66cc653d 140\r
5a196189
M
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
66cc653d 145\r
5a196189 146 assertEquals(reservationDateRangeMap, reservationGroupMap);\r
c1191616 147 \r
5a196189
M
148 assertTrue(loggedUserReservation.containsKey(reservation1));\r
149 assertTrue(loggedUserReservation.containsKey(reservation2));\r
150 assertFalse(loggedUserReservation.containsKey(reservation3));\r
151 assertTrue(reservationMap.containsKey(reservation3));\r
66cc653d 152\r
5a196189 153 for (Map.Entry<Reservation, Boolean> entry : reservationDateRangeMap.entrySet()) {\r
66cc653d 154 if (entry.getKey().getUser().getUserName().equals("TestUser1")) {\r
5a196189
M
155 assertTrue(entry.getValue());\r
156 assertEquals(entry.getKey().getId(), uc.getReservation(entry.getKey().getId()).getId());\r
66cc653d 157 } else {\r
5a196189
M
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
66cc653d
D
164\r
165 @Test(expected = Exception.class)\r
166 public void getReservationGroupException1Test() throws Exception {\r
da277fcf 167 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
168 SessionController sc = new SessionController(dh);\r
169 UserController uc = new UserController(dh,sc);\r
170 \r
da277fcf 171 uc.setDataHandler(null);\r
5a196189
M
172 uc.getReservationGroup(null);\r
173 }\r
66cc653d
D
174\r
175 @Test(expected = IllegalArgumentException.class)\r
176 public void getReservationGroupException2Test() throws Exception {\r
5a196189 177 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
178 SessionController sc = new SessionController(dh);\r
179 UserController uc = new UserController(dh,sc);\r
180 \r
5a196189
M
181 uc.getReservationGroup(null);\r
182 }\r
66cc653d
D
183\r
184 @Test(expected = Exception.class)\r
185 public void getUserReservationException1Test() throws Exception {\r
da277fcf 186 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
187 SessionController sc = new SessionController(dh);\r
188 UserController uc = new UserController(dh,sc);\r
189 \r
da277fcf 190 uc.setDataHandler(null);\r
5a196189
M
191 uc.getUserReservations(null);\r
192 }\r
66cc653d
D
193\r
194 @Test(expected = Exception.class)\r
195 public void getUserReservationException2Test() throws Exception {\r
5a196189 196 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
197 SessionController sc = new SessionController(dh);\r
198 UserController uc = new UserController(dh,sc);\r
199 \r
5a196189
M
200 uc.getUserReservations(null);\r
201 }\r
66cc653d
D
202\r
203 @Test(expected = Exception.class)\r
204 public void getReservationException1Test() throws Exception {\r
da277fcf 205 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
206 SessionController sc = new SessionController(dh);\r
207 UserController uc = new UserController(dh,sc);\r
208 \r
5a196189
M
209 uc.getReservation(null);\r
210 }\r
66cc653d
D
211\r
212 @Test(expected = Exception.class)\r
213 public void getReservationException2Test() throws Exception {\r
5a196189 214 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
215 SessionController sc = new SessionController(dh);\r
216 UserController uc = new UserController(dh,sc);\r
217 \r
5a196189
M
218 uc.getReservation(null);\r
219 }\r
66cc653d
D
220\r
221 @Test(expected = Exception.class)\r
222 public void getReservationsInDateRangeException1Test() throws Exception {\r
c1191616
M
223 DataHandler dh = new DataHandlerForTests();\r
224 SessionController sc = new SessionController(dh);\r
225 UserController uc = new UserController(dh,sc);\r
226 \r
5a196189
M
227 uc.getReservationsInDateRange(null);\r
228 }\r
66cc653d
D
229\r
230 @Test(expected = Exception.class)\r
231 public void getReservationsInDateRangeException2Test() throws Exception {\r
5a196189 232 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
233 SessionController sc = new SessionController(dh);\r
234 UserController uc = new UserController(dh,sc);\r
235 \r
5a196189
M
236 uc.getReservationsInDateRange(null);\r
237 }\r
66cc653d 238\r
47d70ad5 239 @SuppressWarnings("deprecation")\r
b18afc77 240 @Test\r
66cc653d 241 public void makeReservationTest() throws Exception {\r
5a196189 242 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 253\r
5a196189
M
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
66cc653d 260\r
5a196189 261 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
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
5a196189 264 }\r
66cc653d 265\r
c1191616 266 assertEquals(null, uc.makeReservation(sc.getLoggedUser(), resource1, dtList, "remark"));\r
5a196189
M
267 assertEquals(null, uc.makeReservation(null, resource2, dtList, "remark"));\r
268 }\r
66cc653d 269\r
47d70ad5 270 @SuppressWarnings("deprecation")\r
b18afc77 271 @Test\r
66cc653d 272 public void makeInvalidReservationTest() throws Exception {\r
5a196189 273 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 284\r
5a196189
M
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
66cc653d 291\r
5a196189 292 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
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
5a196189 295 }\r
66cc653d 296\r
b18afc77
M
297 List<DateRange> conflictingList = new ArrayList<DateRange>();\r
298 // Conflicts\r
66cc653d
D
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
b18afc77 304 // OK\r
66cc653d
D
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
b18afc77 307\r
c1191616
M
308 assertEquals(null, uc.makeReservation(sc.getLoggedUser(), resource1, dtList, "remark"));\r
309 assertEquals(4, uc.makeReservation(sc.getLoggedUser(), resource1, conflictingList, null).size());\r
5a196189
M
310 }\r
311\r
47d70ad5 312 @SuppressWarnings("deprecation")\r
66cc653d
D
313 @Test(expected = IllegalArgumentException.class)\r
314 public void makeReservationException1Test() throws Exception {\r
5a196189 315 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 326\r
5a196189
M
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
66cc653d 333\r
5a196189 334 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
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
5a196189 337 }\r
66cc653d 338\r
c1191616 339 sc.logOut();\r
5a196189
M
340 assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
341 }\r
342\r
47d70ad5 343 @SuppressWarnings("deprecation")\r
66cc653d
D
344 @Test(expected = IllegalArgumentException.class)\r
345 public void makeReservationException2Test() throws Exception {\r
5a196189 346 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 357\r
5a196189
M
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
66cc653d 364\r
5a196189 365 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
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
5a196189 368 }\r
66cc653d 369\r
5a196189
M
370 assertEquals(null, uc.makeReservation(null, null, dtList, "remark"));\r
371 }\r
372\r
47d70ad5 373 @SuppressWarnings("deprecation")\r
c1191616 374 @Test(expected = Exception.class)\r
66cc653d 375 public void makeReservationException3Test() throws Exception {\r
5a196189 376 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 387\r
5a196189
M
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
66cc653d 394\r
5a196189 395 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
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
5a196189 398 }\r
66cc653d 399\r
c1191616 400 assertEquals(null, uc.makeReservation(uc.getUser("TestUser2"), resource1, null, "remark"));\r
5a196189
M
401 }\r
402\r
66cc653d
D
403 @Test(expected = IllegalArgumentException.class)\r
404 public void makeReservationException4Test() throws Exception {\r
5a196189 405 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 416\r
5a196189
M
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
66cc653d 423\r
5a196189 424 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d 425\r
5a196189
M
426 assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
427 }\r
b07a6f5c
M
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
66cc653d 455\r
b07a6f5c
M
456 assertEquals(null, uc.makeReservation(null, resource1, null, "remark"));\r
457 }\r
458 \r
47d70ad5 459 @SuppressWarnings("deprecation")\r
5a196189 460 @Test\r
66cc653d 461 public void changeReservationTest() throws Exception {\r
5a196189 462 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 473\r
5a196189 474 UUID groupId = UUID.randomUUID();\r
66cc653d
D
475 DateRange dateRange = new DateRangeImpl(new Date(2015, 12, 7, 14, 00, 00), new Date(2015, 12, 7, 15, 00, 00));\r
476\r
5a196189
M
477 Resource resource1 = new Resource("Room101", "Class room");\r
478 dh.addResource(resource1);\r
66cc653d 479\r
c1191616 480 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 481 "Test reservation1");\r
5a196189 482 dh.addReservation(reservation1);\r
66cc653d 483\r
5a196189 484 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
66cc653d
D
485 DateRange newDateRange = new DateRangeImpl(new Date(2015, 12, 7, 20, 00, 00),\r
486 new Date(2015, 12, 8, 02, 00, 00));\r
5a196189
M
487 reservationClone.setDateRange(newDateRange);\r
488 uc.changeReservation(reservationClone);\r
66cc653d 489\r
5a196189
M
490 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
491 }\r
66cc653d 492\r
47d70ad5 493 @SuppressWarnings("deprecation")\r
66cc653d
D
494 @Test(expected = Exception.class)\r
495 public void changeReservationException1Test() throws Exception {\r
5a196189 496 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 507\r
5a196189
M
508 UUID groupId = UUID.randomUUID();\r
509 Date start = new Date();\r
510 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 511 Date finish = (Date) start.clone();\r
5a196189
M
512 finish.setMinutes(start.getMinutes() + 30);\r
513 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 514\r
5a196189
M
515 Resource resource1 = new Resource("Room101", "Class room");\r
516 dh.addResource(resource1);\r
66cc653d 517\r
c1191616 518 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 519 "Test reservation1");\r
5a196189 520 dh.addReservation(reservation1);\r
66cc653d 521\r
5a196189
M
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
66cc653d 527\r
5a196189
M
528 uc.setDataHandler(null);\r
529 uc.changeReservation(reservationClone);\r
66cc653d 530\r
5a196189
M
531 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
532 }\r
66cc653d 533\r
47d70ad5 534 @SuppressWarnings("deprecation")\r
66cc653d
D
535 @Test(expected = Exception.class)\r
536 public void changeReservationException2Test() throws Exception {\r
5a196189 537 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 548\r
5a196189
M
549 UUID groupId = UUID.randomUUID();\r
550 Date start = new Date();\r
551 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 552 Date finish = (Date) start.clone();\r
5a196189
M
553 finish.setMinutes(start.getMinutes() + 30);\r
554 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 555\r
5a196189
M
556 Resource resource1 = new Resource("Room101", "Class room");\r
557 dh.addResource(resource1);\r
66cc653d 558\r
c1191616 559 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 560 "Test reservation1");\r
5a196189 561 dh.addReservation(reservation1);\r
66cc653d 562\r
5a196189
M
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
66cc653d 568\r
c1191616 569 sc.logOut();\r
5a196189 570 uc.changeReservation(reservationClone);\r
66cc653d 571\r
5a196189
M
572 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
573 }\r
66cc653d 574\r
47d70ad5 575 @SuppressWarnings("deprecation")\r
66cc653d
D
576 @Test(expected = IllegalArgumentException.class)\r
577 public void changeReservationException3Test() throws Exception {\r
5a196189 578 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 589\r
5a196189
M
590 UUID groupId = UUID.randomUUID();\r
591 Date start = new Date();\r
592 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 593 Date finish = (Date) start.clone();\r
5a196189
M
594 finish.setMinutes(start.getMinutes() + 30);\r
595 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 596\r
5a196189
M
597 Resource resource1 = new Resource("Room101", "Class room");\r
598 dh.addResource(resource1);\r
66cc653d 599\r
c1191616 600 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 601 "Test reservation1");\r
5a196189 602 dh.addReservation(reservation1);\r
66cc653d 603\r
5a196189
M
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
66cc653d 609\r
5a196189 610 uc.changeReservation(null);\r
66cc653d 611\r
5a196189
M
612 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
613 }\r
66cc653d 614\r
47d70ad5 615 @SuppressWarnings("deprecation")\r
66cc653d
D
616 @Test(expected = Exception.class)\r
617 public void changeReservationException4Test() throws Exception {\r
5a196189 618 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 629\r
5a196189
M
630 UUID groupId = UUID.randomUUID();\r
631 Date start = new Date();\r
632 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 633 Date finish = (Date) start.clone();\r
5a196189
M
634 finish.setMinutes(start.getMinutes() + 30);\r
635 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 636\r
5a196189
M
637 Resource resource1 = new Resource("Room101", "Class room");\r
638 dh.addResource(resource1);\r
66cc653d 639\r
c1191616 640 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 641 "Test reservation1");\r
5a196189 642 dh.addReservation(reservation1);\r
66cc653d 643\r
5a196189
M
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
66cc653d 649\r
c1191616
M
650 sc.logOut();\r
651 sc.logIn("TestUser2", "pass2");\r
5a196189 652 uc.changeReservation(reservationClone);\r
66cc653d 653\r
5a196189
M
654 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
655 }\r
66cc653d 656\r
47d70ad5 657 @SuppressWarnings("deprecation")\r
5a196189 658 @Test\r
66cc653d 659 public void deleteReservationTest() throws Exception {\r
5a196189 660 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 671\r
5a196189
M
672 UUID groupId = UUID.randomUUID();\r
673 Date start = new Date();\r
674 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 675 Date finish = (Date) start.clone();\r
5a196189
M
676 finish.setMinutes(start.getMinutes() + 30);\r
677 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 678\r
5a196189
M
679 Resource resource1 = new Resource("Room101", "Class room");\r
680 dh.addResource(resource1);\r
66cc653d 681\r
c1191616 682 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 683 "Test reservation1");\r
5a196189 684 dh.addReservation(reservation1);\r
66cc653d 685\r
5a196189 686 uc.deleteReservation(reservation1);\r
66cc653d 687\r
5a196189
M
688 assertEquals(null, uc.getReservation(reservation1.getId()));\r
689 }\r
66cc653d 690\r
47d70ad5 691 @SuppressWarnings("deprecation")\r
66cc653d
D
692 @Test(expected = Exception.class)\r
693 public void deleteReservationException1Test() throws Exception {\r
5a196189 694 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 705\r
5a196189
M
706 UUID groupId = UUID.randomUUID();\r
707 Date start = new Date();\r
708 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 709 Date finish = (Date) start.clone();\r
5a196189
M
710 finish.setMinutes(start.getMinutes() + 30);\r
711 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 712\r
5a196189
M
713 Resource resource1 = new Resource("Room101", "Class room");\r
714 dh.addResource(resource1);\r
66cc653d 715\r
c1191616 716 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 717 "Test reservation1");\r
5a196189 718 dh.addReservation(reservation1);\r
66cc653d 719\r
5a196189
M
720 uc.setDataHandler(null);\r
721 uc.deleteReservation(reservation1);\r
66cc653d 722\r
5a196189
M
723 assertEquals(null, uc.getReservation(reservation1.getId()));\r
724 }\r
66cc653d 725\r
47d70ad5 726 @SuppressWarnings("deprecation")\r
66cc653d
D
727 @Test(expected = Exception.class)\r
728 public void deleteReservationException2Test() throws Exception {\r
5a196189 729 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 740\r
5a196189
M
741 UUID groupId = UUID.randomUUID();\r
742 Date start = new Date();\r
743 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 744 Date finish = (Date) start.clone();\r
5a196189
M
745 finish.setMinutes(start.getMinutes() + 30);\r
746 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 747\r
5a196189
M
748 Resource resource1 = new Resource("Room101", "Class room");\r
749 dh.addResource(resource1);\r
66cc653d 750\r
c1191616 751 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 752 "Test reservation1");\r
5a196189 753 dh.addReservation(reservation1);\r
66cc653d 754\r
c1191616 755 sc.logOut();\r
5a196189 756 uc.deleteReservation(reservation1);\r
66cc653d 757\r
5a196189
M
758 assertEquals(null, uc.getReservation(reservation1.getId()));\r
759 }\r
66cc653d 760\r
47d70ad5 761 @SuppressWarnings("deprecation")\r
66cc653d
D
762 @Test(expected = IllegalArgumentException.class)\r
763 public void deleteReservationException3Test() throws Exception {\r
5a196189 764 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 775\r
5a196189
M
776 UUID groupId = UUID.randomUUID();\r
777 Date start = new Date();\r
778 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 779 Date finish = (Date) start.clone();\r
5a196189
M
780 finish.setMinutes(start.getMinutes() + 30);\r
781 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 782\r
5a196189
M
783 Resource resource1 = new Resource("Room101", "Class room");\r
784 dh.addResource(resource1);\r
66cc653d 785\r
c1191616 786 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 787 "Test reservation1");\r
5a196189 788 dh.addReservation(reservation1);\r
66cc653d 789\r
5a196189 790 uc.deleteReservation(null);\r
66cc653d 791\r
5a196189
M
792 assertEquals(null, uc.getReservation(reservation1.getId()));\r
793 }\r
66cc653d 794\r
47d70ad5 795 @SuppressWarnings("deprecation")\r
66cc653d
D
796 @Test(expected = Exception.class)\r
797 public void deleteReservationException4Test() throws Exception {\r
5a196189 798 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 809\r
5a196189
M
810 UUID groupId = UUID.randomUUID();\r
811 Date start = new Date();\r
812 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 813 Date finish = (Date) start.clone();\r
5a196189
M
814 finish.setMinutes(start.getMinutes() + 30);\r
815 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 816\r
5a196189
M
817 Resource resource1 = new Resource("Room101", "Class room");\r
818 dh.addResource(resource1);\r
66cc653d 819\r
c1191616 820 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 821 "Test reservation1");\r
5a196189 822 dh.addReservation(reservation1);\r
66cc653d 823\r
c1191616
M
824 sc.logOut();\r
825 sc.logIn("TestUser2", "pass2");\r
5a196189 826 uc.deleteReservation(reservation1);\r
66cc653d 827\r
5a196189
M
828 assertEquals(null, uc.getReservation(reservation1.getId()));\r
829 }\r
66cc653d 830\r
47d70ad5 831 @SuppressWarnings("deprecation")\r
5a196189 832 @Test\r
66cc653d 833 public void getResourcesTest() throws Exception {\r
5a196189 834 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 845\r
5a196189
M
846 Date start = new Date();\r
847 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 848 Date finish = (Date) start.clone();\r
5a196189 849 finish.setMinutes(start.getMinutes() + 30);\r
66cc653d 850\r
5a196189
M
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
66cc653d 857\r
5a196189 858 List<Resource> resList = uc.getResources();\r
66cc653d
D
859\r
860 assertEquals(3, resList.size());\r
5a196189 861 }\r
66cc653d 862\r
47d70ad5 863 @SuppressWarnings("deprecation")\r
66cc653d
D
864 @Test(expected = Exception.class)\r
865 public void getResourcesExceptionTest() throws Exception {\r
5a196189 866 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 877\r
5a196189
M
878 Date start = new Date();\r
879 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 880 Date finish = (Date) start.clone();\r
5a196189 881 finish.setMinutes(start.getMinutes() + 30);\r
66cc653d 882\r
5a196189
M
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
66cc653d 889\r
5a196189
M
890 uc.setDataHandler(null);\r
891 List<Resource> resList = uc.getResources();\r
66cc653d
D
892\r
893 assertEquals(3, resList.size());\r
5a196189 894 }\r
1ec0e01f 895}\r