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