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