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