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