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