DataHandlerForTestsTest updated
[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 136 Reservation reservation3 = new Reservation(groupId, testUser2, resource3, dateRange, "Test reservation3");\r
e9cb7ca9 137 Reservation reservation4 = new Reservation(UUID.randomUUID(), testUser2, resource3, dateRange, "Test reservation3");\r
5a196189
M
138 dh.addReservation(reservation1);\r
139 dh.addReservation(reservation2);\r
140 dh.addReservation(reservation3);\r
e9cb7ca9 141 dh.addReservation(reservation4);\r
66cc653d 142\r
5a196189
M
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
66cc653d 147\r
5a196189 148 assertEquals(reservationDateRangeMap, reservationGroupMap);\r
c1191616 149 \r
5a196189
M
150 assertTrue(loggedUserReservation.containsKey(reservation1));\r
151 assertTrue(loggedUserReservation.containsKey(reservation2));\r
152 assertFalse(loggedUserReservation.containsKey(reservation3));\r
153 assertTrue(reservationMap.containsKey(reservation3));\r
66cc653d 154\r
5a196189 155 for (Map.Entry<Reservation, Boolean> entry : reservationDateRangeMap.entrySet()) {\r
66cc653d 156 if (entry.getKey().getUser().getUserName().equals("TestUser1")) {\r
5a196189
M
157 assertTrue(entry.getValue());\r
158 assertEquals(entry.getKey().getId(), uc.getReservation(entry.getKey().getId()).getId());\r
66cc653d 159 } else {\r
5a196189
M
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
66cc653d
D
166\r
167 @Test(expected = Exception.class)\r
168 public void getReservationGroupException1Test() throws Exception {\r
da277fcf 169 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
170 SessionController sc = new SessionController(dh);\r
171 UserController uc = new UserController(dh,sc);\r
172 \r
da277fcf 173 uc.setDataHandler(null);\r
5a196189
M
174 uc.getReservationGroup(null);\r
175 }\r
66cc653d
D
176\r
177 @Test(expected = IllegalArgumentException.class)\r
178 public void getReservationGroupException2Test() throws Exception {\r
5a196189 179 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
180 SessionController sc = new SessionController(dh);\r
181 UserController uc = new UserController(dh,sc);\r
182 \r
5a196189
M
183 uc.getReservationGroup(null);\r
184 }\r
66cc653d
D
185\r
186 @Test(expected = Exception.class)\r
187 public void getUserReservationException1Test() throws Exception {\r
da277fcf 188 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
189 SessionController sc = new SessionController(dh);\r
190 UserController uc = new UserController(dh,sc);\r
191 \r
da277fcf 192 uc.setDataHandler(null);\r
5a196189
M
193 uc.getUserReservations(null);\r
194 }\r
66cc653d
D
195\r
196 @Test(expected = Exception.class)\r
197 public void getUserReservationException2Test() throws Exception {\r
5a196189 198 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
199 SessionController sc = new SessionController(dh);\r
200 UserController uc = new UserController(dh,sc);\r
201 \r
5a196189
M
202 uc.getUserReservations(null);\r
203 }\r
66cc653d
D
204\r
205 @Test(expected = Exception.class)\r
206 public void getReservationException1Test() throws Exception {\r
da277fcf 207 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
208 SessionController sc = new SessionController(dh);\r
209 UserController uc = new UserController(dh,sc);\r
210 \r
5a196189
M
211 uc.getReservation(null);\r
212 }\r
66cc653d
D
213\r
214 @Test(expected = Exception.class)\r
215 public void getReservationException2Test() throws Exception {\r
5a196189 216 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
217 SessionController sc = new SessionController(dh);\r
218 UserController uc = new UserController(dh,sc);\r
219 \r
5a196189
M
220 uc.getReservation(null);\r
221 }\r
66cc653d
D
222\r
223 @Test(expected = Exception.class)\r
224 public void getReservationsInDateRangeException1Test() throws Exception {\r
c1191616
M
225 DataHandler dh = new DataHandlerForTests();\r
226 SessionController sc = new SessionController(dh);\r
227 UserController uc = new UserController(dh,sc);\r
228 \r
5a196189
M
229 uc.getReservationsInDateRange(null);\r
230 }\r
66cc653d
D
231\r
232 @Test(expected = Exception.class)\r
233 public void getReservationsInDateRangeException2Test() throws Exception {\r
5a196189 234 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
235 SessionController sc = new SessionController(dh);\r
236 UserController uc = new UserController(dh,sc);\r
237 \r
5a196189
M
238 uc.getReservationsInDateRange(null);\r
239 }\r
66cc653d 240\r
47d70ad5 241 @SuppressWarnings("deprecation")\r
b18afc77 242 @Test\r
66cc653d 243 public void makeReservationTest() throws Exception {\r
5a196189 244 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 255\r
5a196189
M
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
66cc653d 262\r
5a196189 263 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
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
5a196189 266 }\r
66cc653d 267\r
c1191616 268 assertEquals(null, uc.makeReservation(sc.getLoggedUser(), resource1, dtList, "remark"));\r
5a196189
M
269 assertEquals(null, uc.makeReservation(null, resource2, dtList, "remark"));\r
270 }\r
66cc653d 271\r
47d70ad5 272 @SuppressWarnings("deprecation")\r
b18afc77 273 @Test\r
66cc653d 274 public void makeInvalidReservationTest() throws Exception {\r
5a196189 275 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 286\r
5a196189
M
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
66cc653d 293\r
5a196189 294 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
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
5a196189 297 }\r
66cc653d 298\r
b18afc77
M
299 List<DateRange> conflictingList = new ArrayList<DateRange>();\r
300 // Conflicts\r
66cc653d
D
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
b18afc77 306 // OK\r
66cc653d
D
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
b18afc77 309\r
c1191616
M
310 assertEquals(null, uc.makeReservation(sc.getLoggedUser(), resource1, dtList, "remark"));\r
311 assertEquals(4, uc.makeReservation(sc.getLoggedUser(), resource1, conflictingList, null).size());\r
5a196189
M
312 }\r
313\r
47d70ad5 314 @SuppressWarnings("deprecation")\r
66cc653d
D
315 @Test(expected = IllegalArgumentException.class)\r
316 public void makeReservationException1Test() throws Exception {\r
5a196189 317 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 328\r
5a196189
M
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
66cc653d 335\r
5a196189 336 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
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
5a196189 339 }\r
66cc653d 340\r
c1191616 341 sc.logOut();\r
5a196189
M
342 assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
343 }\r
344\r
47d70ad5 345 @SuppressWarnings("deprecation")\r
66cc653d
D
346 @Test(expected = IllegalArgumentException.class)\r
347 public void makeReservationException2Test() throws Exception {\r
5a196189 348 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 359\r
5a196189
M
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
66cc653d 366\r
5a196189 367 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
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
5a196189 370 }\r
66cc653d 371\r
5a196189
M
372 assertEquals(null, uc.makeReservation(null, null, dtList, "remark"));\r
373 }\r
374\r
47d70ad5 375 @SuppressWarnings("deprecation")\r
c1191616 376 @Test(expected = Exception.class)\r
66cc653d 377 public void makeReservationException3Test() throws Exception {\r
5a196189 378 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 389\r
5a196189
M
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
66cc653d 396\r
5a196189 397 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
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
5a196189 400 }\r
66cc653d 401\r
c1191616 402 assertEquals(null, uc.makeReservation(uc.getUser("TestUser2"), resource1, null, "remark"));\r
5a196189
M
403 }\r
404\r
66cc653d
D
405 @Test(expected = IllegalArgumentException.class)\r
406 public void makeReservationException4Test() throws Exception {\r
5a196189 407 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 418\r
5a196189
M
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
66cc653d 425\r
5a196189 426 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d 427\r
5a196189
M
428 assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
429 }\r
b07a6f5c
M
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
66cc653d 457\r
b07a6f5c
M
458 assertEquals(null, uc.makeReservation(null, resource1, null, "remark"));\r
459 }\r
460 \r
47d70ad5 461 @SuppressWarnings("deprecation")\r
5a196189 462 @Test\r
66cc653d 463 public void changeReservationTest() throws Exception {\r
5a196189 464 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 475\r
5a196189 476 UUID groupId = UUID.randomUUID();\r
66cc653d
D
477 DateRange dateRange = new DateRangeImpl(new Date(2015, 12, 7, 14, 00, 00), new Date(2015, 12, 7, 15, 00, 00));\r
478\r
5a196189
M
479 Resource resource1 = new Resource("Room101", "Class room");\r
480 dh.addResource(resource1);\r
66cc653d 481\r
c1191616 482 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 483 "Test reservation1");\r
5a196189 484 dh.addReservation(reservation1);\r
66cc653d 485\r
5a196189 486 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
66cc653d
D
487 DateRange newDateRange = new DateRangeImpl(new Date(2015, 12, 7, 20, 00, 00),\r
488 new Date(2015, 12, 8, 02, 00, 00));\r
5a196189
M
489 reservationClone.setDateRange(newDateRange);\r
490 uc.changeReservation(reservationClone);\r
66cc653d 491\r
5a196189
M
492 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
493 }\r
66cc653d 494\r
47d70ad5 495 @SuppressWarnings("deprecation")\r
66cc653d
D
496 @Test(expected = Exception.class)\r
497 public void changeReservationException1Test() throws Exception {\r
5a196189 498 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 509\r
5a196189
M
510 UUID groupId = UUID.randomUUID();\r
511 Date start = new Date();\r
512 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 513 Date finish = (Date) start.clone();\r
5a196189
M
514 finish.setMinutes(start.getMinutes() + 30);\r
515 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 516\r
5a196189
M
517 Resource resource1 = new Resource("Room101", "Class room");\r
518 dh.addResource(resource1);\r
66cc653d 519\r
c1191616 520 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 521 "Test reservation1");\r
5a196189 522 dh.addReservation(reservation1);\r
66cc653d 523\r
5a196189
M
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
66cc653d 529\r
5a196189
M
530 uc.setDataHandler(null);\r
531 uc.changeReservation(reservationClone);\r
66cc653d 532\r
5a196189
M
533 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
534 }\r
66cc653d 535\r
47d70ad5 536 @SuppressWarnings("deprecation")\r
66cc653d
D
537 @Test(expected = Exception.class)\r
538 public void changeReservationException2Test() throws Exception {\r
5a196189 539 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 550\r
5a196189
M
551 UUID groupId = UUID.randomUUID();\r
552 Date start = new Date();\r
553 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 554 Date finish = (Date) start.clone();\r
5a196189
M
555 finish.setMinutes(start.getMinutes() + 30);\r
556 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 557\r
5a196189
M
558 Resource resource1 = new Resource("Room101", "Class room");\r
559 dh.addResource(resource1);\r
66cc653d 560\r
c1191616 561 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 562 "Test reservation1");\r
5a196189 563 dh.addReservation(reservation1);\r
66cc653d 564\r
5a196189
M
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
66cc653d 570\r
c1191616 571 sc.logOut();\r
5a196189 572 uc.changeReservation(reservationClone);\r
66cc653d 573\r
5a196189
M
574 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
575 }\r
66cc653d 576\r
47d70ad5 577 @SuppressWarnings("deprecation")\r
66cc653d
D
578 @Test(expected = IllegalArgumentException.class)\r
579 public void changeReservationException3Test() throws Exception {\r
5a196189 580 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 591\r
5a196189
M
592 UUID groupId = UUID.randomUUID();\r
593 Date start = new Date();\r
594 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 595 Date finish = (Date) start.clone();\r
5a196189
M
596 finish.setMinutes(start.getMinutes() + 30);\r
597 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 598\r
5a196189
M
599 Resource resource1 = new Resource("Room101", "Class room");\r
600 dh.addResource(resource1);\r
66cc653d 601\r
c1191616 602 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 603 "Test reservation1");\r
5a196189 604 dh.addReservation(reservation1);\r
66cc653d 605\r
5a196189
M
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
66cc653d 611\r
5a196189 612 uc.changeReservation(null);\r
66cc653d 613\r
5a196189
M
614 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
615 }\r
66cc653d 616\r
47d70ad5 617 @SuppressWarnings("deprecation")\r
66cc653d
D
618 @Test(expected = Exception.class)\r
619 public void changeReservationException4Test() throws Exception {\r
5a196189 620 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 631\r
5a196189
M
632 UUID groupId = UUID.randomUUID();\r
633 Date start = new Date();\r
634 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 635 Date finish = (Date) start.clone();\r
5a196189
M
636 finish.setMinutes(start.getMinutes() + 30);\r
637 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 638\r
5a196189
M
639 Resource resource1 = new Resource("Room101", "Class room");\r
640 dh.addResource(resource1);\r
66cc653d 641\r
c1191616 642 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 643 "Test reservation1");\r
5a196189 644 dh.addReservation(reservation1);\r
66cc653d 645\r
5a196189
M
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
66cc653d 651\r
c1191616
M
652 sc.logOut();\r
653 sc.logIn("TestUser2", "pass2");\r
5a196189 654 uc.changeReservation(reservationClone);\r
66cc653d 655\r
5a196189
M
656 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
657 }\r
66cc653d 658\r
47d70ad5 659 @SuppressWarnings("deprecation")\r
5a196189 660 @Test\r
66cc653d 661 public void deleteReservationTest() throws Exception {\r
5a196189 662 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 673\r
5a196189
M
674 UUID groupId = UUID.randomUUID();\r
675 Date start = new Date();\r
676 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 677 Date finish = (Date) start.clone();\r
5a196189
M
678 finish.setMinutes(start.getMinutes() + 30);\r
679 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 680\r
5a196189
M
681 Resource resource1 = new Resource("Room101", "Class room");\r
682 dh.addResource(resource1);\r
66cc653d 683\r
c1191616 684 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 685 "Test reservation1");\r
5a196189 686 dh.addReservation(reservation1);\r
66cc653d 687\r
5a196189 688 uc.deleteReservation(reservation1);\r
66cc653d 689\r
5a196189
M
690 assertEquals(null, uc.getReservation(reservation1.getId()));\r
691 }\r
66cc653d 692\r
47d70ad5 693 @SuppressWarnings("deprecation")\r
66cc653d
D
694 @Test(expected = Exception.class)\r
695 public void deleteReservationException1Test() throws Exception {\r
5a196189 696 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 707\r
5a196189
M
708 UUID groupId = UUID.randomUUID();\r
709 Date start = new Date();\r
710 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 711 Date finish = (Date) start.clone();\r
5a196189
M
712 finish.setMinutes(start.getMinutes() + 30);\r
713 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 714\r
5a196189
M
715 Resource resource1 = new Resource("Room101", "Class room");\r
716 dh.addResource(resource1);\r
66cc653d 717\r
c1191616 718 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 719 "Test reservation1");\r
5a196189 720 dh.addReservation(reservation1);\r
66cc653d 721\r
5a196189
M
722 uc.setDataHandler(null);\r
723 uc.deleteReservation(reservation1);\r
66cc653d 724\r
5a196189
M
725 assertEquals(null, uc.getReservation(reservation1.getId()));\r
726 }\r
66cc653d 727\r
47d70ad5 728 @SuppressWarnings("deprecation")\r
66cc653d
D
729 @Test(expected = Exception.class)\r
730 public void deleteReservationException2Test() throws Exception {\r
5a196189 731 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 742\r
5a196189
M
743 UUID groupId = UUID.randomUUID();\r
744 Date start = new Date();\r
745 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 746 Date finish = (Date) start.clone();\r
5a196189
M
747 finish.setMinutes(start.getMinutes() + 30);\r
748 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 749\r
5a196189
M
750 Resource resource1 = new Resource("Room101", "Class room");\r
751 dh.addResource(resource1);\r
66cc653d 752\r
c1191616 753 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 754 "Test reservation1");\r
5a196189 755 dh.addReservation(reservation1);\r
66cc653d 756\r
c1191616 757 sc.logOut();\r
5a196189 758 uc.deleteReservation(reservation1);\r
66cc653d 759\r
5a196189
M
760 assertEquals(null, uc.getReservation(reservation1.getId()));\r
761 }\r
66cc653d 762\r
47d70ad5 763 @SuppressWarnings("deprecation")\r
66cc653d
D
764 @Test(expected = IllegalArgumentException.class)\r
765 public void deleteReservationException3Test() throws Exception {\r
5a196189 766 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 777\r
5a196189
M
778 UUID groupId = UUID.randomUUID();\r
779 Date start = new Date();\r
780 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 781 Date finish = (Date) start.clone();\r
5a196189
M
782 finish.setMinutes(start.getMinutes() + 30);\r
783 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 784\r
5a196189
M
785 Resource resource1 = new Resource("Room101", "Class room");\r
786 dh.addResource(resource1);\r
66cc653d 787\r
c1191616 788 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 789 "Test reservation1");\r
5a196189 790 dh.addReservation(reservation1);\r
66cc653d 791\r
5a196189 792 uc.deleteReservation(null);\r
66cc653d 793\r
5a196189
M
794 assertEquals(null, uc.getReservation(reservation1.getId()));\r
795 }\r
66cc653d 796\r
47d70ad5 797 @SuppressWarnings("deprecation")\r
66cc653d
D
798 @Test(expected = Exception.class)\r
799 public void deleteReservationException4Test() throws Exception {\r
5a196189 800 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 811\r
5a196189
M
812 UUID groupId = UUID.randomUUID();\r
813 Date start = new Date();\r
814 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 815 Date finish = (Date) start.clone();\r
5a196189
M
816 finish.setMinutes(start.getMinutes() + 30);\r
817 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 818\r
5a196189
M
819 Resource resource1 = new Resource("Room101", "Class room");\r
820 dh.addResource(resource1);\r
66cc653d 821\r
c1191616 822 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 823 "Test reservation1");\r
5a196189 824 dh.addReservation(reservation1);\r
66cc653d 825\r
c1191616
M
826 sc.logOut();\r
827 sc.logIn("TestUser2", "pass2");\r
5a196189 828 uc.deleteReservation(reservation1);\r
66cc653d 829\r
5a196189
M
830 assertEquals(null, uc.getReservation(reservation1.getId()));\r
831 }\r
66cc653d 832\r
47d70ad5 833 @SuppressWarnings("deprecation")\r
5a196189 834 @Test\r
66cc653d 835 public void getResourcesTest() throws Exception {\r
5a196189 836 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 847\r
5a196189
M
848 Date start = new Date();\r
849 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 850 Date finish = (Date) start.clone();\r
5a196189 851 finish.setMinutes(start.getMinutes() + 30);\r
66cc653d 852\r
5a196189
M
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
66cc653d 859\r
5a196189 860 List<Resource> resList = uc.getResources();\r
66cc653d
D
861\r
862 assertEquals(3, resList.size());\r
5a196189 863 }\r
66cc653d 864\r
47d70ad5 865 @SuppressWarnings("deprecation")\r
66cc653d
D
866 @Test(expected = Exception.class)\r
867 public void getResourcesExceptionTest() throws Exception {\r
5a196189 868 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
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
66cc653d 879\r
5a196189
M
880 Date start = new Date();\r
881 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 882 Date finish = (Date) start.clone();\r
5a196189 883 finish.setMinutes(start.getMinutes() + 30);\r
66cc653d 884\r
5a196189
M
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
66cc653d 891\r
5a196189
M
892 uc.setDataHandler(null);\r
893 List<Resource> resList = uc.getResources();\r
66cc653d
D
894\r
895 assertEquals(3, resList.size());\r
5a196189 896 }\r
1ec0e01f 897}\r