Updated Tests
[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
1f7b5004 44 }\r
66cc653d
D
45\r
46 @Test(expected = Exception.class)\r
47 public void addUserExceptionTest() throws Exception {\r
c1191616 48 SessionController sc = new SessionController(null);\r
66cc653d 49\r
c1191616 50 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
1f7b5004 51 }\r
30d10517 52 \r
5a196189 53 @Test\r
66cc653d 54 public void getUserTest() throws Exception {\r
5a196189 55 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
56 SessionController sc = new SessionController(dh);\r
57 UserController uc = null;\r
58\r
59 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
60 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
61 for (Controller controller : controllers) {\r
62 if(controller.getClass().equals(UserController.class))\r
63 uc = (UserController)controller;\r
64 }\r
5a196189
M
65 assertEquals("grosm9@bfh.ch", uc.getUser("TestUser1").getMail());\r
66 }\r
66cc653d
D
67\r
68 @Test(expected = Exception.class)\r
69 public void getUserExceptionTest() throws Exception {\r
5a196189 70 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
71 SessionController sc = new SessionController(dh);\r
72 UserController uc = new UserController(null,sc);\r
66cc653d 73\r
5a196189
M
74 assertEquals("grosm9@bfh.ch", uc.getUser("TestUser1").getMail());\r
75 }\r
30d10517 76 \r
66cc653d
D
77 @Test(expected = Exception.class)\r
78 public void getUserExpectionTest() throws Exception {\r
da277fcf 79 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
80 SessionController sc = new SessionController(dh);\r
81 UserController uc = null;\r
82 \r
83 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
84 for (Controller controller : controllers) {\r
85 if(controller.getClass().equals(UserController.class))\r
86 uc = (UserController)controller;\r
87 }\r
88 \r
da277fcf 89 uc.setDataHandler(null);\r
5a196189
M
90 uc.getUser(null);\r
91 }\r
30d10517 92 \r
47d70ad5 93 @SuppressWarnings("deprecation")\r
5a196189 94 @Test\r
66cc653d 95 public void getReservationTests() throws Exception {\r
5a196189 96 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
97 SessionController sc = new SessionController(dh);\r
98 UserController uc = null;\r
99 \r
100 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
101 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
102 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
103 for (Controller controller : controllers) {\r
104 if(controller.getClass().equals(UserController.class))\r
105 uc = (UserController)controller;\r
106 }\r
107 \r
5a196189 108 UUID groupId = UUID.randomUUID();\r
66cc653d
D
109 Date start = new Date(2015, 11, 28, 11, 00, 00);\r
110 Date finish = new Date(2015, 11, 28, 11, 30, 00);\r
5a196189 111 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 112\r
5a196189
M
113 Resource resource1 = new Resource("Room101", "Class room");\r
114 Resource resource2 = new Resource("Room101", "Class room");\r
115 Resource resource3 = new Resource("Room101", "Class room");\r
116 dh.addResource(resource1);\r
117 dh.addResource(resource2);\r
118 dh.addResource(resource3);\r
66cc653d 119\r
5a196189 120 User testUser2 = uc.getUser("TestUser2");\r
66cc653d 121\r
c1191616 122 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 123 "Test reservation1");\r
c1191616 124 Reservation reservation2 = new Reservation(groupId, sc.getLoggedUser(), resource2, dateRange,\r
66cc653d 125 "Test reservation2");\r
5a196189
M
126 Reservation reservation3 = new Reservation(groupId, testUser2, resource3, dateRange, "Test reservation3");\r
127 dh.addReservation(reservation1);\r
128 dh.addReservation(reservation2);\r
129 dh.addReservation(reservation3);\r
66cc653d 130\r
5a196189
M
131 Map<Reservation, Boolean> loggedUserReservation = uc.getUserReservations(null);\r
132 Map<Reservation, Boolean> reservationMap = uc.getUserReservations(testUser2);\r
133 Map<Reservation, Boolean> reservationDateRangeMap = uc.getReservationsInDateRange(dateRange);\r
134 Map<Reservation, Boolean> reservationGroupMap = uc.getReservationGroup(groupId);\r
66cc653d 135\r
5a196189 136 assertEquals(reservationDateRangeMap, reservationGroupMap);\r
c1191616 137 \r
5a196189
M
138 assertTrue(loggedUserReservation.containsKey(reservation1));\r
139 assertTrue(loggedUserReservation.containsKey(reservation2));\r
140 assertFalse(loggedUserReservation.containsKey(reservation3));\r
141 assertTrue(reservationMap.containsKey(reservation3));\r
66cc653d 142\r
5a196189 143 for (Map.Entry<Reservation, Boolean> entry : reservationDateRangeMap.entrySet()) {\r
66cc653d 144 if (entry.getKey().getUser().getUserName().equals("TestUser1")) {\r
5a196189
M
145 assertTrue(entry.getValue());\r
146 assertEquals(entry.getKey().getId(), uc.getReservation(entry.getKey().getId()).getId());\r
66cc653d 147 } else {\r
5a196189
M
148 assertFalse(entry.getValue());\r
149 assertEquals(entry.getKey().getId(), uc.getReservation(entry.getKey().getId()).getId());\r
150 }\r
151 }\r
152 assertEquals(null, uc.getReservation(UUID.randomUUID()));\r
153 }\r
66cc653d
D
154\r
155 @Test(expected = Exception.class)\r
156 public void getReservationGroupException1Test() throws Exception {\r
da277fcf 157 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
158 SessionController sc = new SessionController(dh);\r
159 UserController uc = new UserController(dh,sc);\r
160 \r
da277fcf 161 uc.setDataHandler(null);\r
5a196189
M
162 uc.getReservationGroup(null);\r
163 }\r
66cc653d
D
164\r
165 @Test(expected = IllegalArgumentException.class)\r
166 public void getReservationGroupException2Test() throws Exception {\r
5a196189 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
5a196189
M
171 uc.getReservationGroup(null);\r
172 }\r
66cc653d
D
173\r
174 @Test(expected = Exception.class)\r
175 public void getUserReservationException1Test() throws Exception {\r
da277fcf 176 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
177 SessionController sc = new SessionController(dh);\r
178 UserController uc = new UserController(dh,sc);\r
179 \r
da277fcf 180 uc.setDataHandler(null);\r
5a196189
M
181 uc.getUserReservations(null);\r
182 }\r
66cc653d
D
183\r
184 @Test(expected = Exception.class)\r
185 public void getUserReservationException2Test() throws Exception {\r
5a196189 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
5a196189
M
190 uc.getUserReservations(null);\r
191 }\r
66cc653d
D
192\r
193 @Test(expected = Exception.class)\r
194 public void getReservationException1Test() throws Exception {\r
da277fcf 195 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
196 SessionController sc = new SessionController(dh);\r
197 UserController uc = new UserController(dh,sc);\r
198 \r
5a196189
M
199 uc.getReservation(null);\r
200 }\r
66cc653d
D
201\r
202 @Test(expected = Exception.class)\r
203 public void getReservationException2Test() throws Exception {\r
5a196189 204 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
205 SessionController sc = new SessionController(dh);\r
206 UserController uc = new UserController(dh,sc);\r
207 \r
5a196189
M
208 uc.getReservation(null);\r
209 }\r
66cc653d
D
210\r
211 @Test(expected = Exception.class)\r
212 public void getReservationsInDateRangeException1Test() throws Exception {\r
c1191616
M
213 DataHandler dh = new DataHandlerForTests();\r
214 SessionController sc = new SessionController(dh);\r
215 UserController uc = new UserController(dh,sc);\r
216 \r
5a196189
M
217 uc.getReservationsInDateRange(null);\r
218 }\r
66cc653d
D
219\r
220 @Test(expected = Exception.class)\r
221 public void getReservationsInDateRangeException2Test() throws Exception {\r
5a196189 222 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
223 SessionController sc = new SessionController(dh);\r
224 UserController uc = new UserController(dh,sc);\r
225 \r
5a196189
M
226 uc.getReservationsInDateRange(null);\r
227 }\r
66cc653d 228\r
47d70ad5 229 @SuppressWarnings("deprecation")\r
b18afc77 230 @Test\r
66cc653d 231 public void makeReservationTest() throws Exception {\r
5a196189 232 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
233 SessionController sc = new SessionController(dh);\r
234 UserController uc = null;\r
235 \r
236 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
237 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
238 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
239 for (Controller controller : controllers) {\r
240 if(controller.getClass().equals(UserController.class))\r
241 uc = (UserController)controller;\r
242 }\r
66cc653d 243\r
5a196189
M
244 Resource resource1 = new Resource("Room101", "Class room");\r
245 Resource resource2 = new Resource("Room101", "Class room");\r
246 Resource resource3 = new Resource("Room101", "Class room");\r
247 dh.addResource(resource1);\r
248 dh.addResource(resource2);\r
249 dh.addResource(resource3);\r
66cc653d 250\r
5a196189 251 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
252 for (int i = 1; i < 10; i++) {\r
253 dtList.add(new DateRangeImpl(new Date(2015, 12, 2 + i, 11, 00, 00), new Date(2015, 12, 2 + i, 11, 00, 00)));\r
5a196189 254 }\r
66cc653d 255\r
c1191616 256 assertEquals(null, uc.makeReservation(sc.getLoggedUser(), resource1, dtList, "remark"));\r
5a196189
M
257 assertEquals(null, uc.makeReservation(null, resource2, dtList, "remark"));\r
258 }\r
66cc653d 259\r
47d70ad5 260 @SuppressWarnings("deprecation")\r
b18afc77 261 @Test\r
66cc653d 262 public void makeInvalidReservationTest() throws Exception {\r
5a196189 263 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
264 SessionController sc = new SessionController(dh);\r
265 UserController uc = null;\r
266 \r
267 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
268 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
269 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
270 for (Controller controller : controllers) {\r
271 if(controller.getClass().equals(UserController.class))\r
272 uc = (UserController)controller;\r
273 }\r
66cc653d 274\r
5a196189
M
275 Resource resource1 = new Resource("Room101", "Class room");\r
276 Resource resource2 = new Resource("Room101", "Class room");\r
277 Resource resource3 = new Resource("Room101", "Class room");\r
278 dh.addResource(resource1);\r
279 dh.addResource(resource2);\r
280 dh.addResource(resource3);\r
66cc653d 281\r
5a196189 282 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
283 for (int i = 1; i < 10; i++) {\r
284 dtList.add(new DateRangeImpl(new Date(2015, 12, 2 + i, 11, 00, 00), new Date(2015, 12, 2 + i, 12, 00, 00)));\r
5a196189 285 }\r
66cc653d 286\r
b18afc77
M
287 List<DateRange> conflictingList = new ArrayList<DateRange>();\r
288 // Conflicts\r
66cc653d
D
289 conflictingList.add(new DateRangeImpl(new Date(2015, 12, 4, 11, 00, 00), new Date(2015, 12, 4, 12, 00, 00)));\r
290 conflictingList.add(new DateRangeImpl(new Date(2015, 12, 4, 11, 15, 00), new Date(2015, 12, 4, 11, 45, 00)));\r
291 conflictingList.add(new DateRangeImpl(new Date(2015, 12, 4, 10, 00, 00), new Date(2015, 12, 4, 17, 00, 00)));\r
292 conflictingList.add(new DateRangeImpl(new Date(2015, 12, 4, 11, 30, 00), new Date(2015, 12, 4, 12, 30, 00)));\r
293\r
b18afc77 294 // OK\r
66cc653d
D
295 conflictingList.add(new DateRangeImpl(new Date(2015, 12, 4, 10, 30, 00), new Date(2015, 12, 4, 10, 59, 59)));\r
296 conflictingList.add(new DateRangeImpl(new Date(2015, 12, 4, 12, 00, 01), new Date(2015, 12, 4, 12, 45, 00)));\r
b18afc77 297\r
c1191616
M
298 assertEquals(null, uc.makeReservation(sc.getLoggedUser(), resource1, dtList, "remark"));\r
299 assertEquals(4, uc.makeReservation(sc.getLoggedUser(), resource1, conflictingList, null).size());\r
5a196189
M
300 }\r
301\r
47d70ad5 302 @SuppressWarnings("deprecation")\r
66cc653d
D
303 @Test(expected = IllegalArgumentException.class)\r
304 public void makeReservationException1Test() throws Exception {\r
5a196189 305 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
306 SessionController sc = new SessionController(dh);\r
307 UserController uc = null;\r
308 \r
309 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
310 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
311 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
312 for (Controller controller : controllers) {\r
313 if(controller.getClass().equals(UserController.class))\r
314 uc = (UserController)controller;\r
315 }\r
66cc653d 316\r
5a196189
M
317 Resource resource1 = new Resource("Room101", "Class room");\r
318 Resource resource2 = new Resource("Room101", "Class room");\r
319 Resource resource3 = new Resource("Room101", "Class room");\r
320 dh.addResource(resource1);\r
321 dh.addResource(resource2);\r
322 dh.addResource(resource3);\r
66cc653d 323\r
5a196189 324 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
325 for (int i = 1; i < 10; i++) {\r
326 dtList.add(new DateRangeImpl(new Date(2015, 12, 2 + i, 11, 00, 00), new Date(2015, 12, 2 + i, 12, 00, 00)));\r
5a196189 327 }\r
66cc653d 328\r
c1191616 329 sc.logOut();\r
5a196189
M
330 assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
331 }\r
332\r
47d70ad5 333 @SuppressWarnings("deprecation")\r
66cc653d
D
334 @Test(expected = IllegalArgumentException.class)\r
335 public void makeReservationException2Test() throws Exception {\r
5a196189 336 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
337 SessionController sc = new SessionController(dh);\r
338 UserController uc = null;\r
339 \r
340 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
341 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
342 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
343 for (Controller controller : controllers) {\r
344 if(controller.getClass().equals(UserController.class))\r
345 uc = (UserController)controller;\r
346 }\r
66cc653d 347\r
5a196189
M
348 Resource resource1 = new Resource("Room101", "Class room");\r
349 Resource resource2 = new Resource("Room101", "Class room");\r
350 Resource resource3 = new Resource("Room101", "Class room");\r
351 dh.addResource(resource1);\r
352 dh.addResource(resource2);\r
353 dh.addResource(resource3);\r
66cc653d 354\r
5a196189 355 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
356 for (int i = 1; i < 10; i++) {\r
357 dtList.add(new DateRangeImpl(new Date(2015, 12, 2 + i, 11, 00, 00), new Date(2015, 12, 2 + i, 12, 00, 00)));\r
5a196189 358 }\r
66cc653d 359\r
5a196189
M
360 assertEquals(null, uc.makeReservation(null, null, dtList, "remark"));\r
361 }\r
362\r
47d70ad5 363 @SuppressWarnings("deprecation")\r
c1191616 364 @Test(expected = Exception.class)\r
66cc653d 365 public void makeReservationException3Test() throws Exception {\r
5a196189 366 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
367 SessionController sc = new SessionController(dh);\r
368 UserController uc = null;\r
369 \r
370 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
371 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
372 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
373 for (Controller controller : controllers) {\r
374 if(controller.getClass().equals(UserController.class))\r
375 uc = (UserController)controller;\r
376 }\r
66cc653d 377\r
5a196189
M
378 Resource resource1 = new Resource("Room101", "Class room");\r
379 Resource resource2 = new Resource("Room101", "Class room");\r
380 Resource resource3 = new Resource("Room101", "Class room");\r
381 dh.addResource(resource1);\r
382 dh.addResource(resource2);\r
383 dh.addResource(resource3);\r
66cc653d 384\r
5a196189 385 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d
D
386 for (int i = 1; i < 10; i++) {\r
387 dtList.add(new DateRangeImpl(new Date(2015, 12, 2 + i, 11, 00, 00), new Date(2015, 12, 2 + i, 12, 00, 00)));\r
5a196189 388 }\r
66cc653d 389\r
c1191616 390 assertEquals(null, uc.makeReservation(uc.getUser("TestUser2"), resource1, null, "remark"));\r
5a196189
M
391 }\r
392\r
66cc653d
D
393 @Test(expected = IllegalArgumentException.class)\r
394 public void makeReservationException4Test() throws Exception {\r
5a196189 395 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
396 SessionController sc = new SessionController(dh);\r
397 UserController uc = null;\r
398 \r
399 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
400 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
401 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
402 for (Controller controller : controllers) {\r
403 if(controller.getClass().equals(UserController.class))\r
404 uc = (UserController)controller;\r
405 }\r
66cc653d 406\r
5a196189
M
407 Resource resource1 = new Resource("Room101", "Class room");\r
408 Resource resource2 = new Resource("Room101", "Class room");\r
409 Resource resource3 = new Resource("Room101", "Class room");\r
410 dh.addResource(resource1);\r
411 dh.addResource(resource2);\r
412 dh.addResource(resource3);\r
66cc653d 413\r
5a196189 414 List<DateRange> dtList = new ArrayList<DateRange>();\r
66cc653d 415\r
5a196189
M
416 assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
417 }\r
66cc653d 418\r
47d70ad5 419 @SuppressWarnings("deprecation")\r
5a196189 420 @Test\r
66cc653d 421 public void changeReservationTest() throws Exception {\r
5a196189 422 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
423 SessionController sc = new SessionController(dh);\r
424 UserController uc = null;\r
425 \r
426 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
427 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
428 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
429 for (Controller controller : controllers) {\r
430 if(controller.getClass().equals(UserController.class))\r
431 uc = (UserController)controller;\r
432 }\r
66cc653d 433\r
5a196189 434 UUID groupId = UUID.randomUUID();\r
66cc653d
D
435 DateRange dateRange = new DateRangeImpl(new Date(2015, 12, 7, 14, 00, 00), new Date(2015, 12, 7, 15, 00, 00));\r
436\r
5a196189
M
437 Resource resource1 = new Resource("Room101", "Class room");\r
438 dh.addResource(resource1);\r
66cc653d 439\r
c1191616 440 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 441 "Test reservation1");\r
5a196189 442 dh.addReservation(reservation1);\r
66cc653d 443\r
5a196189 444 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
66cc653d
D
445 DateRange newDateRange = new DateRangeImpl(new Date(2015, 12, 7, 20, 00, 00),\r
446 new Date(2015, 12, 8, 02, 00, 00));\r
5a196189
M
447 reservationClone.setDateRange(newDateRange);\r
448 uc.changeReservation(reservationClone);\r
66cc653d 449\r
5a196189
M
450 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
451 }\r
66cc653d 452\r
47d70ad5 453 @SuppressWarnings("deprecation")\r
66cc653d
D
454 @Test(expected = Exception.class)\r
455 public void changeReservationException1Test() throws Exception {\r
5a196189 456 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
457 SessionController sc = new SessionController(dh);\r
458 UserController uc = null;\r
459 \r
460 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
461 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
462 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
463 for (Controller controller : controllers) {\r
464 if(controller.getClass().equals(UserController.class))\r
465 uc = (UserController)controller;\r
466 }\r
66cc653d 467\r
5a196189
M
468 UUID groupId = UUID.randomUUID();\r
469 Date start = new Date();\r
470 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 471 Date finish = (Date) start.clone();\r
5a196189
M
472 finish.setMinutes(start.getMinutes() + 30);\r
473 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 474\r
5a196189
M
475 Resource resource1 = new Resource("Room101", "Class room");\r
476 dh.addResource(resource1);\r
66cc653d 477\r
c1191616 478 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 479 "Test reservation1");\r
5a196189 480 dh.addReservation(reservation1);\r
66cc653d 481\r
5a196189
M
482 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
483 start.setDate(start.getDate() + 1);\r
484 finish.setDate(finish.getDate() + 1);\r
485 DateRange newDateRange = new DateRangeImpl(start, finish);\r
486 reservationClone.setDateRange(newDateRange);\r
66cc653d 487\r
5a196189
M
488 uc.setDataHandler(null);\r
489 uc.changeReservation(reservationClone);\r
66cc653d 490\r
5a196189
M
491 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
492 }\r
66cc653d 493\r
47d70ad5 494 @SuppressWarnings("deprecation")\r
66cc653d
D
495 @Test(expected = Exception.class)\r
496 public void changeReservationException2Test() throws Exception {\r
5a196189 497 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
498 SessionController sc = new SessionController(dh);\r
499 UserController uc = null;\r
500 \r
501 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
502 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
503 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
504 for (Controller controller : controllers) {\r
505 if(controller.getClass().equals(UserController.class))\r
506 uc = (UserController)controller;\r
507 }\r
66cc653d 508\r
5a196189
M
509 UUID groupId = UUID.randomUUID();\r
510 Date start = new Date();\r
511 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 512 Date finish = (Date) start.clone();\r
5a196189
M
513 finish.setMinutes(start.getMinutes() + 30);\r
514 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 515\r
5a196189
M
516 Resource resource1 = new Resource("Room101", "Class room");\r
517 dh.addResource(resource1);\r
66cc653d 518\r
c1191616 519 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 520 "Test reservation1");\r
5a196189 521 dh.addReservation(reservation1);\r
66cc653d 522\r
5a196189
M
523 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
524 start.setDate(start.getDate() + 1);\r
525 finish.setDate(finish.getDate() + 1);\r
526 DateRange newDateRange = new DateRangeImpl(start, finish);\r
527 reservationClone.setDateRange(newDateRange);\r
66cc653d 528\r
c1191616 529 sc.logOut();\r
5a196189 530 uc.changeReservation(reservationClone);\r
66cc653d 531\r
5a196189
M
532 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
533 }\r
66cc653d 534\r
47d70ad5 535 @SuppressWarnings("deprecation")\r
66cc653d
D
536 @Test(expected = IllegalArgumentException.class)\r
537 public void changeReservationException3Test() throws Exception {\r
5a196189 538 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
539 SessionController sc = new SessionController(dh);\r
540 UserController uc = null;\r
541 \r
542 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
543 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
544 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
545 for (Controller controller : controllers) {\r
546 if(controller.getClass().equals(UserController.class))\r
547 uc = (UserController)controller;\r
548 }\r
66cc653d 549\r
5a196189
M
550 UUID groupId = UUID.randomUUID();\r
551 Date start = new Date();\r
552 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 553 Date finish = (Date) start.clone();\r
5a196189
M
554 finish.setMinutes(start.getMinutes() + 30);\r
555 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 556\r
5a196189
M
557 Resource resource1 = new Resource("Room101", "Class room");\r
558 dh.addResource(resource1);\r
66cc653d 559\r
c1191616 560 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 561 "Test reservation1");\r
5a196189 562 dh.addReservation(reservation1);\r
66cc653d 563\r
5a196189
M
564 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
565 start.setDate(start.getDate() + 1);\r
566 finish.setDate(finish.getDate() + 1);\r
567 DateRange newDateRange = new DateRangeImpl(start, finish);\r
568 reservationClone.setDateRange(newDateRange);\r
66cc653d 569\r
5a196189 570 uc.changeReservation(null);\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 = Exception.class)\r
577 public void changeReservationException4Test() 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
c1191616
M
610 sc.logOut();\r
611 sc.logIn("TestUser2", "pass2");\r
5a196189 612 uc.changeReservation(reservationClone);\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
5a196189 618 @Test\r
66cc653d 619 public void deleteReservationTest() 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 646 uc.deleteReservation(reservation1);\r
66cc653d 647\r
5a196189
M
648 assertEquals(null, uc.getReservation(reservation1.getId()));\r
649 }\r
66cc653d 650\r
47d70ad5 651 @SuppressWarnings("deprecation")\r
66cc653d
D
652 @Test(expected = Exception.class)\r
653 public void deleteReservationException1Test() throws Exception {\r
5a196189 654 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
655 SessionController sc = new SessionController(dh);\r
656 UserController uc = null;\r
657 \r
658 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
659 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
660 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
661 for (Controller controller : controllers) {\r
662 if(controller.getClass().equals(UserController.class))\r
663 uc = (UserController)controller;\r
664 }\r
66cc653d 665\r
5a196189
M
666 UUID groupId = UUID.randomUUID();\r
667 Date start = new Date();\r
668 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 669 Date finish = (Date) start.clone();\r
5a196189
M
670 finish.setMinutes(start.getMinutes() + 30);\r
671 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 672\r
5a196189
M
673 Resource resource1 = new Resource("Room101", "Class room");\r
674 dh.addResource(resource1);\r
66cc653d 675\r
c1191616 676 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 677 "Test reservation1");\r
5a196189 678 dh.addReservation(reservation1);\r
66cc653d 679\r
5a196189
M
680 uc.setDataHandler(null);\r
681 uc.deleteReservation(reservation1);\r
66cc653d 682\r
5a196189
M
683 assertEquals(null, uc.getReservation(reservation1.getId()));\r
684 }\r
66cc653d 685\r
47d70ad5 686 @SuppressWarnings("deprecation")\r
66cc653d
D
687 @Test(expected = Exception.class)\r
688 public void deleteReservationException2Test() throws Exception {\r
5a196189 689 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
690 SessionController sc = new SessionController(dh);\r
691 UserController uc = null;\r
692 \r
693 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
694 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
695 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
696 for (Controller controller : controllers) {\r
697 if(controller.getClass().equals(UserController.class))\r
698 uc = (UserController)controller;\r
699 }\r
66cc653d 700\r
5a196189
M
701 UUID groupId = UUID.randomUUID();\r
702 Date start = new Date();\r
703 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 704 Date finish = (Date) start.clone();\r
5a196189
M
705 finish.setMinutes(start.getMinutes() + 30);\r
706 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 707\r
5a196189
M
708 Resource resource1 = new Resource("Room101", "Class room");\r
709 dh.addResource(resource1);\r
66cc653d 710\r
c1191616 711 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 712 "Test reservation1");\r
5a196189 713 dh.addReservation(reservation1);\r
66cc653d 714\r
c1191616 715 sc.logOut();\r
5a196189 716 uc.deleteReservation(reservation1);\r
66cc653d 717\r
5a196189
M
718 assertEquals(null, uc.getReservation(reservation1.getId()));\r
719 }\r
66cc653d 720\r
47d70ad5 721 @SuppressWarnings("deprecation")\r
66cc653d
D
722 @Test(expected = IllegalArgumentException.class)\r
723 public void deleteReservationException3Test() throws Exception {\r
5a196189 724 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
725 SessionController sc = new SessionController(dh);\r
726 UserController uc = null;\r
727 \r
728 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
729 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
730 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
731 for (Controller controller : controllers) {\r
732 if(controller.getClass().equals(UserController.class))\r
733 uc = (UserController)controller;\r
734 }\r
66cc653d 735\r
5a196189
M
736 UUID groupId = UUID.randomUUID();\r
737 Date start = new Date();\r
738 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 739 Date finish = (Date) start.clone();\r
5a196189
M
740 finish.setMinutes(start.getMinutes() + 30);\r
741 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 742\r
5a196189
M
743 Resource resource1 = new Resource("Room101", "Class room");\r
744 dh.addResource(resource1);\r
66cc653d 745\r
c1191616 746 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 747 "Test reservation1");\r
5a196189 748 dh.addReservation(reservation1);\r
66cc653d 749\r
5a196189 750 uc.deleteReservation(null);\r
66cc653d 751\r
5a196189
M
752 assertEquals(null, uc.getReservation(reservation1.getId()));\r
753 }\r
66cc653d 754\r
47d70ad5 755 @SuppressWarnings("deprecation")\r
66cc653d
D
756 @Test(expected = Exception.class)\r
757 public void deleteReservationException4Test() throws Exception {\r
5a196189 758 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
759 SessionController sc = new SessionController(dh);\r
760 UserController uc = null;\r
761 \r
762 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
763 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
764 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
765 for (Controller controller : controllers) {\r
766 if(controller.getClass().equals(UserController.class))\r
767 uc = (UserController)controller;\r
768 }\r
66cc653d 769\r
5a196189
M
770 UUID groupId = UUID.randomUUID();\r
771 Date start = new Date();\r
772 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 773 Date finish = (Date) start.clone();\r
5a196189
M
774 finish.setMinutes(start.getMinutes() + 30);\r
775 DateRange dateRange = new DateRangeImpl(start, finish);\r
66cc653d 776\r
5a196189
M
777 Resource resource1 = new Resource("Room101", "Class room");\r
778 dh.addResource(resource1);\r
66cc653d 779\r
c1191616 780 Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
66cc653d 781 "Test reservation1");\r
5a196189 782 dh.addReservation(reservation1);\r
66cc653d 783\r
c1191616
M
784 sc.logOut();\r
785 sc.logIn("TestUser2", "pass2");\r
5a196189 786 uc.deleteReservation(reservation1);\r
66cc653d 787\r
5a196189
M
788 assertEquals(null, uc.getReservation(reservation1.getId()));\r
789 }\r
66cc653d 790\r
47d70ad5 791 @SuppressWarnings("deprecation")\r
5a196189 792 @Test\r
66cc653d 793 public void getResourcesTest() throws Exception {\r
5a196189 794 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
795 SessionController sc = new SessionController(dh);\r
796 UserController uc = null;\r
797 \r
798 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
799 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
800 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
801 for (Controller controller : controllers) {\r
802 if(controller.getClass().equals(UserController.class))\r
803 uc = (UserController)controller;\r
804 }\r
66cc653d 805\r
5a196189
M
806 Date start = new Date();\r
807 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 808 Date finish = (Date) start.clone();\r
5a196189 809 finish.setMinutes(start.getMinutes() + 30);\r
66cc653d 810\r
5a196189
M
811 Resource resource1 = new Resource("Room101", "Class room");\r
812 Resource resource2 = new Resource("Room101", "Class room");\r
813 Resource resource3 = new Resource("Room101", "Class room");\r
814 dh.addResource(resource1);\r
815 dh.addResource(resource2);\r
816 dh.addResource(resource3);\r
66cc653d 817\r
5a196189 818 List<Resource> resList = uc.getResources();\r
66cc653d
D
819\r
820 assertEquals(3, resList.size());\r
5a196189 821 }\r
66cc653d 822\r
47d70ad5 823 @SuppressWarnings("deprecation")\r
66cc653d
D
824 @Test(expected = Exception.class)\r
825 public void getResourcesExceptionTest() throws Exception {\r
5a196189 826 DataHandler dh = new DataHandlerForTests();\r
c1191616
M
827 SessionController sc = new SessionController(dh);\r
828 UserController uc = null;\r
829 \r
830 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
831 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
832 Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
833 for (Controller controller : controllers) {\r
834 if(controller.getClass().equals(UserController.class))\r
835 uc = (UserController)controller;\r
836 }\r
66cc653d 837\r
5a196189
M
838 Date start = new Date();\r
839 start.setTime((System.currentTimeMillis() % 1000));\r
66cc653d 840 Date finish = (Date) start.clone();\r
5a196189 841 finish.setMinutes(start.getMinutes() + 30);\r
66cc653d 842\r
5a196189
M
843 Resource resource1 = new Resource("Room101", "Class room");\r
844 Resource resource2 = new Resource("Room101", "Class room");\r
845 Resource resource3 = new Resource("Room101", "Class room");\r
846 dh.addResource(resource1);\r
847 dh.addResource(resource2);\r
848 dh.addResource(resource3);\r
66cc653d 849\r
5a196189
M
850 uc.setDataHandler(null);\r
851 List<Resource> resList = uc.getResources();\r
66cc653d
D
852\r
853 assertEquals(3, resList.size());\r
5a196189 854 }\r
1ec0e01f 855}\r