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