UserControllerTest 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
169 String currentName = uc.getLoggedName();\r
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
285 Date start = new Date();\r
286 start.setTime((System.currentTimeMillis() % 1000));\r
287 Date finish = (Date)start.clone();\r
288 finish.setMinutes(start.getMinutes() + 30);\r
289 DateRange dateRange = new DateRangeImpl(start, finish);\r
290 \r
291 Resource resource1 = new Resource("Room101", "Class room");\r
292 Resource resource2 = new Resource("Room101", "Class room");\r
293 Resource resource3 = new Resource("Room101", "Class room");\r
294 dh.addResource(resource1);\r
295 dh.addResource(resource2);\r
296 dh.addResource(resource3);\r
297 \r
298 User loggedUser = uc.getLoggedUser();\r
299 User testUser2 = uc.getUser("TestUser2");\r
300 \r
301 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
302 Reservation reservation2 = new Reservation(groupId, uc.getLoggedUser(), resource2, dateRange, "Test reservation2");\r
303 Reservation reservation3 = new Reservation(groupId, testUser2, resource3, dateRange, "Test reservation3");\r
304 dh.addReservation(reservation1);\r
305 dh.addReservation(reservation2);\r
306 dh.addReservation(reservation3);\r
307 \r
308 Map<Reservation, Boolean> loggedUserReservation = uc.getUserReservations(null);\r
309 Map<Reservation, Boolean> reservationMap = uc.getUserReservations(testUser2);\r
310 Map<Reservation, Boolean> reservationDateRangeMap = uc.getReservationsInDateRange(dateRange);\r
311 Map<Reservation, Boolean> reservationGroupMap = uc.getReservationGroup(groupId);\r
312 \r
313 assertEquals(reservationDateRangeMap, reservationGroupMap);\r
314 \r
315 assertTrue(loggedUserReservation.containsKey(reservation1));\r
316 assertTrue(loggedUserReservation.containsKey(reservation2));\r
317 assertFalse(loggedUserReservation.containsKey(reservation3));\r
318 assertTrue(reservationMap.containsKey(reservation3));\r
319 \r
320 for (Map.Entry<Reservation, Boolean> entry : reservationDateRangeMap.entrySet()) {\r
321 if(entry.getKey().getUser().getUserName().equals("TestUser1")){\r
322 assertTrue(entry.getValue());\r
323 assertEquals(entry.getKey().getId(), uc.getReservation(entry.getKey().getId()).getId());\r
324 }\r
325 else{\r
326 assertFalse(entry.getValue());\r
327 assertEquals(entry.getKey().getId(), uc.getReservation(entry.getKey().getId()).getId());\r
328 }\r
329 }\r
330 assertEquals(null, uc.getReservation(UUID.randomUUID()));\r
331 }\r
332 \r
333 @Test(expected=Exception.class)\r
334 public void getReservationGroupException1Test() throws Exception{\r
335 UserController uc = new UserController();\r
336 uc.getReservationGroup(null);\r
337 }\r
338 \r
339 @Test(expected=IllegalArgumentException.class)\r
340 public void getReservationGroupException2Test() throws Exception{\r
341 DataHandler dh = new DataHandlerForTests();\r
342 UserController uc = new UserController();\r
343 uc.setDataHandler(dh);\r
344 uc.getReservationGroup(null);\r
345 }\r
346 \r
347 @Test(expected=Exception.class)\r
348 public void getUserReservationException1Test() throws Exception{\r
349 UserController uc = new UserController();\r
350 uc.getUserReservations(null);\r
351 }\r
352 \r
353 @Test(expected=Exception.class)\r
354 public void getUserReservationException2Test() throws Exception{\r
355 DataHandler dh = new DataHandlerForTests();\r
356 UserController uc = new UserController();\r
357 uc.setDataHandler(dh);\r
358 uc.getUserReservations(null);\r
359 }\r
360 \r
361 @Test(expected=Exception.class)\r
362 public void getReservationException1Test() throws Exception{\r
363 UserController uc = new UserController();\r
364 uc.getReservation(null);\r
365 }\r
366 \r
367 @Test(expected=Exception.class)\r
368 public void getReservationException2Test() throws Exception{\r
369 DataHandler dh = new DataHandlerForTests();\r
370 UserController uc = new UserController();\r
371 uc.setDataHandler(dh);\r
372 uc.getReservation(null);\r
373 }\r
374 \r
375 @Test(expected=Exception.class)\r
376 public void getReservationsInDateRangeException1Test() throws Exception{\r
377 UserController uc = new UserController();\r
378 uc.getReservationsInDateRange(null);\r
379 }\r
380 \r
381 @Test(expected=Exception.class)\r
382 public void getReservationsInDateRangeException2Test() throws Exception{\r
383 DataHandler dh = new DataHandlerForTests();\r
384 UserController uc = new UserController();\r
385 uc.setDataHandler(dh);\r
386 uc.getReservationsInDateRange(null);\r
387 }\r
388 \r
389 @Ignore("disabled until implementation is finished")\r
390 //@Test\r
391 public void makeReservationTest() throws Exception{\r
392 DataHandler dh = new DataHandlerForTests();\r
393 UserController uc = new UserController();\r
394 uc.setDataHandler(dh);\r
395 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
396 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
397 uc.logIn("TestUser1", "pass1");\r
398 \r
399 Date start = new Date();\r
400 start.setTime((System.currentTimeMillis() % 1000));\r
401 Date finish = (Date)start.clone();\r
402 finish.setMinutes(start.getMinutes() + 30);\r
403 \r
404 Resource resource1 = new Resource("Room101", "Class room");\r
405 Resource resource2 = new Resource("Room101", "Class room");\r
406 Resource resource3 = new Resource("Room101", "Class room");\r
407 dh.addResource(resource1);\r
408 dh.addResource(resource2);\r
409 dh.addResource(resource3);\r
410 \r
411 List<DateRange> dtList = new ArrayList<DateRange>();\r
412 // Woechentlich, 10 Wochen lang\r
413 for(int i = 1;i<10;i++){\r
414 start.setDate(start.getDate() + (i*7));\r
415 finish.setDate(finish.getDate() + (i*7));\r
416 dtList.add(new DateRangeImpl(start, finish));\r
417 }\r
418 \r
419 assertEquals(null, uc.makeReservation(uc.getLoggedUser(), resource1, dtList, "remark"));\r
420 assertEquals(null, uc.makeReservation(null, resource2, dtList, "remark"));\r
421 }\r
422 \r
423 @Ignore("disabled until implementation is finished")\r
424 //@Test\r
425 public void makeInvalidReservationTest() throws Exception{\r
426 DataHandler dh = new DataHandlerForTests();\r
427 UserController uc = new UserController();\r
428 uc.setDataHandler(dh);\r
429 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
430 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
431 uc.logIn("TestUser1", "pass1");\r
432 \r
433 Date start = new Date();\r
434 start.setTime((System.currentTimeMillis() % 1000));\r
435 Date finish = (Date)start.clone();\r
436 finish.setMinutes(start.getMinutes() + 30);\r
437 \r
438 Resource resource1 = new Resource("Room101", "Class room");\r
439 Resource resource2 = new Resource("Room101", "Class room");\r
440 Resource resource3 = new Resource("Room101", "Class room");\r
441 dh.addResource(resource1);\r
442 dh.addResource(resource2);\r
443 dh.addResource(resource3);\r
444 \r
445 List<DateRange> dtList = new ArrayList<DateRange>();\r
446 // Woechentlich, 10 Wochen lang\r
447 for(int i = 1;i<10;i++){\r
448 start.setDate(start.getDate() + (i*7));\r
449 finish.setDate(finish.getDate() + (i*7));\r
450 dtList.add(new DateRangeImpl(start, finish));\r
451 }\r
452 \r
453 dtList.remove(0);\r
454 dtList.remove(1);\r
455 dtList.remove(2);\r
456 dtList.remove(3);\r
457 \r
458 Set<Reservation> resList = uc.makeReservation(uc.getLoggedUser(), resource1, dtList, "remark");\r
459 Iterator iter = resList.iterator();\r
460 while (iter.hasNext()) {\r
461 Reservation res = (Reservation)iter.next();\r
462 System.out.println(res.getDateRange().getStart() + "\t" + res.getDateRange().getFinish());\r
463 }\r
464 \r
465// assertEquals(null, uc.makeReservation(uc.getLoggedUser(), resource1, dtList, "remark")); \r
466// assertEquals(9, uc.makeReservation(uc.getLoggedUser(), resource1, dtList, null).size());\r
467 }\r
468\r
469 @Test(expected=IllegalArgumentException.class)\r
470 public void makeReservationException1Test() throws Exception{\r
471 DataHandler dh = new DataHandlerForTests();\r
472 UserController uc = new UserController();\r
473 uc.setDataHandler(dh);\r
474 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
475 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
476 uc.logIn("TestUser1", "pass1");\r
477 \r
478 Date start = new Date();\r
479 start.setTime((System.currentTimeMillis() % 1000));\r
480 Date finish = (Date)start.clone();\r
481 finish.setMinutes(start.getMinutes() + 30);\r
482 \r
483 Resource resource1 = new Resource("Room101", "Class room");\r
484 Resource resource2 = new Resource("Room101", "Class room");\r
485 Resource resource3 = new Resource("Room101", "Class room");\r
486 dh.addResource(resource1);\r
487 dh.addResource(resource2);\r
488 dh.addResource(resource3);\r
489 \r
490 List<DateRange> dtList = new ArrayList<DateRange>();\r
491 // Woechentlich, 10 Wochen lang\r
492 for(int i = 1;i<10;i++){\r
493 start.setDate(start.getDate() + (i*7));\r
494 finish.setDate(finish.getDate() + (i*7));\r
495 dtList.add(new DateRangeImpl(start, finish));\r
496 }\r
497 \r
498 uc.logOut();\r
499 assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
500 }\r
501\r
502 @Test(expected=IllegalArgumentException.class)\r
503 public void makeReservationException2Test() throws Exception{\r
504 DataHandler dh = new DataHandlerForTests();\r
505 UserController uc = new UserController();\r
506 uc.setDataHandler(dh);\r
507 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
508 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
509 uc.logIn("TestUser1", "pass1");\r
510 \r
511 Date start = new Date();\r
512 start.setTime((System.currentTimeMillis() % 1000));\r
513 Date finish = (Date)start.clone();\r
514 finish.setMinutes(start.getMinutes() + 30);\r
515 \r
516 Resource resource1 = new Resource("Room101", "Class room");\r
517 Resource resource2 = new Resource("Room101", "Class room");\r
518 Resource resource3 = new Resource("Room101", "Class room");\r
519 dh.addResource(resource1);\r
520 dh.addResource(resource2);\r
521 dh.addResource(resource3);\r
522 \r
523 List<DateRange> dtList = new ArrayList<DateRange>();\r
524 // Woechentlich, 10 Wochen lang\r
525 for(int i = 1;i<10;i++){\r
526 start.setDate(start.getDate() + (i*7));\r
527 finish.setDate(finish.getDate() + (i*7));\r
528 dtList.add(new DateRangeImpl(start, finish));\r
529 }\r
530 \r
531 assertEquals(null, uc.makeReservation(null, null, dtList, "remark"));\r
532 }\r
533\r
534 @Test(expected=IllegalArgumentException.class)\r
535 public void makeReservationException3Test() throws Exception{\r
536 DataHandler dh = new DataHandlerForTests();\r
537 UserController uc = new UserController();\r
538 uc.setDataHandler(dh);\r
539 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
540 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
541 uc.logIn("TestUser1", "pass1");\r
542 \r
543 Date start = new Date();\r
544 start.setTime((System.currentTimeMillis() % 1000));\r
545 Date finish = (Date)start.clone();\r
546 finish.setMinutes(start.getMinutes() + 30);\r
547 \r
548 Resource resource1 = new Resource("Room101", "Class room");\r
549 Resource resource2 = new Resource("Room101", "Class room");\r
550 Resource resource3 = new Resource("Room101", "Class room");\r
551 dh.addResource(resource1);\r
552 dh.addResource(resource2);\r
553 dh.addResource(resource3);\r
554 \r
555 List<DateRange> dtList = new ArrayList<DateRange>();\r
556 // Woechentlich, 10 Wochen lang\r
557 for(int i = 1;i<10;i++){\r
558 start.setDate(start.getDate() + (i*7));\r
559 finish.setDate(finish.getDate() + (i*7));\r
560 dtList.add(new DateRangeImpl(start, finish));\r
561 }\r
562 \r
563 assertEquals(null, uc.makeReservation(null, resource1, null, "remark"));\r
564 }\r
565\r
566 @Test(expected=IllegalArgumentException.class)\r
567 public void makeReservationException4Test() throws Exception{\r
568 DataHandler dh = new DataHandlerForTests();\r
569 UserController uc = new UserController();\r
570 uc.setDataHandler(dh);\r
571 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
572 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
573 uc.logIn("TestUser1", "pass1");\r
574 \r
575 Date start = new Date();\r
576 start.setTime((System.currentTimeMillis() % 1000));\r
577 Date finish = (Date)start.clone();\r
578 finish.setMinutes(start.getMinutes() + 30);\r
579 \r
580 Resource resource1 = new Resource("Room101", "Class room");\r
581 Resource resource2 = new Resource("Room101", "Class room");\r
582 Resource resource3 = new Resource("Room101", "Class room");\r
583 dh.addResource(resource1);\r
584 dh.addResource(resource2);\r
585 dh.addResource(resource3);\r
586 \r
587 List<DateRange> dtList = new ArrayList<DateRange>();\r
588 \r
589 assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
590 }\r
591 \r
592 @Test\r
593 public void changeReservationTest() throws Exception{\r
594 DataHandler dh = new DataHandlerForTests();\r
595 UserController uc = new UserController();\r
596 uc.setDataHandler(dh);\r
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
600 \r
601 UUID groupId = UUID.randomUUID();\r
602 Date start = new Date();\r
603 start.setTime((System.currentTimeMillis() % 1000));\r
604 Date finish = (Date)start.clone();\r
605 finish.setMinutes(start.getMinutes() + 30);\r
606 DateRange dateRange = new DateRangeImpl(start, finish);\r
607 \r
608 Resource resource1 = new Resource("Room101", "Class room");\r
609 dh.addResource(resource1);\r
610 \r
611 User loggedUser = uc.getLoggedUser();\r
612 User testUser2 = uc.getUser("TestUser2");\r
613 \r
614 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
615 dh.addReservation(reservation1);\r
616 \r
617 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
618 start.setDate(start.getDate() + 1);\r
619 finish.setDate(finish.getDate() + 1);\r
620 DateRange newDateRange = new DateRangeImpl(start, finish);\r
621 reservationClone.setDateRange(newDateRange);\r
622 uc.changeReservation(reservationClone);\r
623 \r
624 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
625 }\r
626 \r
627 @Test(expected=Exception.class)\r
628 public void changeReservationException1Test() throws Exception{\r
629 DataHandler dh = new DataHandlerForTests();\r
630 UserController uc = new UserController();\r
631 uc.setDataHandler(dh);\r
632 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
633 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
634 uc.logIn("TestUser1", "pass1");\r
635 \r
636 UUID groupId = UUID.randomUUID();\r
637 Date start = new Date();\r
638 start.setTime((System.currentTimeMillis() % 1000));\r
639 Date finish = (Date)start.clone();\r
640 finish.setMinutes(start.getMinutes() + 30);\r
641 DateRange dateRange = new DateRangeImpl(start, finish);\r
642 \r
643 Resource resource1 = new Resource("Room101", "Class room");\r
644 dh.addResource(resource1);\r
645 \r
646 User loggedUser = uc.getLoggedUser();\r
647 User testUser2 = uc.getUser("TestUser2");\r
648 \r
649 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
650 dh.addReservation(reservation1);\r
651 \r
652 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
653 start.setDate(start.getDate() + 1);\r
654 finish.setDate(finish.getDate() + 1);\r
655 DateRange newDateRange = new DateRangeImpl(start, finish);\r
656 reservationClone.setDateRange(newDateRange);\r
657 \r
658 uc.setDataHandler(null);\r
659 uc.changeReservation(reservationClone);\r
660 \r
661 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
662 }\r
663 \r
664 @Test(expected=Exception.class)\r
665 public void changeReservationException2Test() throws Exception{\r
666 DataHandler dh = new DataHandlerForTests();\r
667 UserController uc = new UserController();\r
668 uc.setDataHandler(dh);\r
669 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
670 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
671 uc.logIn("TestUser1", "pass1");\r
672 \r
673 UUID groupId = UUID.randomUUID();\r
674 Date start = new Date();\r
675 start.setTime((System.currentTimeMillis() % 1000));\r
676 Date finish = (Date)start.clone();\r
677 finish.setMinutes(start.getMinutes() + 30);\r
678 DateRange dateRange = new DateRangeImpl(start, finish);\r
679 \r
680 Resource resource1 = new Resource("Room101", "Class room");\r
681 dh.addResource(resource1);\r
682 \r
683 User loggedUser = uc.getLoggedUser();\r
684 User testUser2 = uc.getUser("TestUser2");\r
685 \r
686 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
687 dh.addReservation(reservation1);\r
688 \r
689 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
690 start.setDate(start.getDate() + 1);\r
691 finish.setDate(finish.getDate() + 1);\r
692 DateRange newDateRange = new DateRangeImpl(start, finish);\r
693 reservationClone.setDateRange(newDateRange);\r
694 \r
695 uc.logOut();\r
696 uc.changeReservation(reservationClone);\r
697 \r
698 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
699 }\r
700 \r
701 @Test(expected=IllegalArgumentException.class)\r
702 public void changeReservationException3Test() throws Exception{\r
703 DataHandler dh = new DataHandlerForTests();\r
704 UserController uc = new UserController();\r
705 uc.setDataHandler(dh);\r
706 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
707 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
708 uc.logIn("TestUser1", "pass1");\r
709 \r
710 UUID groupId = UUID.randomUUID();\r
711 Date start = new Date();\r
712 start.setTime((System.currentTimeMillis() % 1000));\r
713 Date finish = (Date)start.clone();\r
714 finish.setMinutes(start.getMinutes() + 30);\r
715 DateRange dateRange = new DateRangeImpl(start, finish);\r
716 \r
717 Resource resource1 = new Resource("Room101", "Class room");\r
718 dh.addResource(resource1);\r
719 \r
720 User loggedUser = uc.getLoggedUser();\r
721 User testUser2 = uc.getUser("TestUser2");\r
722 \r
723 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
724 dh.addReservation(reservation1);\r
725 \r
726 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
727 start.setDate(start.getDate() + 1);\r
728 finish.setDate(finish.getDate() + 1);\r
729 DateRange newDateRange = new DateRangeImpl(start, finish);\r
730 reservationClone.setDateRange(newDateRange);\r
731 \r
732 uc.changeReservation(null);\r
733 \r
734 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
735 }\r
736 \r
737 @Test(expected=Exception.class)\r
738 public void changeReservationException4Test() throws Exception{\r
739 DataHandler dh = new DataHandlerForTests();\r
740 UserController uc = new UserController();\r
741 uc.setDataHandler(dh);\r
742 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
743 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
744 uc.logIn("TestUser1", "pass1");\r
745 \r
746 UUID groupId = UUID.randomUUID();\r
747 Date start = new Date();\r
748 start.setTime((System.currentTimeMillis() % 1000));\r
749 Date finish = (Date)start.clone();\r
750 finish.setMinutes(start.getMinutes() + 30);\r
751 DateRange dateRange = new DateRangeImpl(start, finish);\r
752 \r
753 Resource resource1 = new Resource("Room101", "Class room");\r
754 dh.addResource(resource1);\r
755 \r
756 User loggedUser = uc.getLoggedUser();\r
757 User testUser2 = uc.getUser("TestUser2");\r
758 \r
759 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
760 dh.addReservation(reservation1);\r
761 \r
762 Reservation reservationClone = uc.getReservation(reservation1.getId());\r
763 start.setDate(start.getDate() + 1);\r
764 finish.setDate(finish.getDate() + 1);\r
765 DateRange newDateRange = new DateRangeImpl(start, finish);\r
766 reservationClone.setDateRange(newDateRange);\r
767 \r
768 uc.logOut();\r
769 uc.logIn("TestUser2", "pass2");\r
770 uc.changeReservation(reservationClone);\r
771 \r
772 assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
773 }\r
774 \r
775 @Test\r
776 public void deleteReservationTest() throws Exception{\r
777 DataHandler dh = new DataHandlerForTests();\r
778 UserController uc = new UserController();\r
779 uc.setDataHandler(dh);\r
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
783 \r
784 UUID groupId = UUID.randomUUID();\r
785 Date start = new Date();\r
786 start.setTime((System.currentTimeMillis() % 1000));\r
787 Date finish = (Date)start.clone();\r
788 finish.setMinutes(start.getMinutes() + 30);\r
789 DateRange dateRange = new DateRangeImpl(start, finish);\r
790 \r
791 Resource resource1 = new Resource("Room101", "Class room");\r
792 dh.addResource(resource1);\r
793 \r
794 User loggedUser = uc.getLoggedUser();\r
795 User testUser2 = uc.getUser("TestUser2");\r
796 \r
797 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
798 dh.addReservation(reservation1);\r
799 \r
800 uc.deleteReservation(reservation1);\r
801 \r
802 assertEquals(null, uc.getReservation(reservation1.getId()));\r
803 }\r
804 \r
805 @Test(expected=Exception.class)\r
806 public void deleteReservationException1Test() throws Exception{\r
807 DataHandler dh = new DataHandlerForTests();\r
808 UserController uc = new UserController();\r
809 uc.setDataHandler(dh);\r
810 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
811 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
812 uc.logIn("TestUser1", "pass1");\r
813 \r
814 UUID groupId = UUID.randomUUID();\r
815 Date start = new Date();\r
816 start.setTime((System.currentTimeMillis() % 1000));\r
817 Date finish = (Date)start.clone();\r
818 finish.setMinutes(start.getMinutes() + 30);\r
819 DateRange dateRange = new DateRangeImpl(start, finish);\r
820 \r
821 Resource resource1 = new Resource("Room101", "Class room");\r
822 dh.addResource(resource1);\r
823 \r
824 User loggedUser = uc.getLoggedUser();\r
825 User testUser2 = uc.getUser("TestUser2");\r
826 \r
827 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
828 dh.addReservation(reservation1);\r
829 \r
830 uc.setDataHandler(null);\r
831 uc.deleteReservation(reservation1);\r
832 \r
833 assertEquals(null, uc.getReservation(reservation1.getId()));\r
834 }\r
835 \r
836 @Test(expected=Exception.class)\r
837 public void deleteReservationException2Test() throws Exception{\r
838 DataHandler dh = new DataHandlerForTests();\r
839 UserController uc = new UserController();\r
840 uc.setDataHandler(dh);\r
841 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
842 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
843 uc.logIn("TestUser1", "pass1");\r
844 \r
845 UUID groupId = UUID.randomUUID();\r
846 Date start = new Date();\r
847 start.setTime((System.currentTimeMillis() % 1000));\r
848 Date finish = (Date)start.clone();\r
849 finish.setMinutes(start.getMinutes() + 30);\r
850 DateRange dateRange = new DateRangeImpl(start, finish);\r
851 \r
852 Resource resource1 = new Resource("Room101", "Class room");\r
853 dh.addResource(resource1);\r
854 \r
855 User loggedUser = uc.getLoggedUser();\r
856 User testUser2 = uc.getUser("TestUser2");\r
857 \r
858 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
859 dh.addReservation(reservation1);\r
860 \r
861 uc.logOut();\r
862 uc.deleteReservation(reservation1);\r
863 \r
864 assertEquals(null, uc.getReservation(reservation1.getId()));\r
865 }\r
866 \r
867 @Test(expected=IllegalArgumentException.class)\r
868 public void deleteReservationException3Test() throws Exception{\r
869 DataHandler dh = new DataHandlerForTests();\r
870 UserController uc = new UserController();\r
871 uc.setDataHandler(dh);\r
872 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
873 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
874 uc.logIn("TestUser1", "pass1");\r
875 \r
876 UUID groupId = UUID.randomUUID();\r
877 Date start = new Date();\r
878 start.setTime((System.currentTimeMillis() % 1000));\r
879 Date finish = (Date)start.clone();\r
880 finish.setMinutes(start.getMinutes() + 30);\r
881 DateRange dateRange = new DateRangeImpl(start, finish);\r
882 \r
883 Resource resource1 = new Resource("Room101", "Class room");\r
884 dh.addResource(resource1);\r
885 \r
886 User loggedUser = uc.getLoggedUser();\r
887 User testUser2 = uc.getUser("TestUser2");\r
888 \r
889 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
890 dh.addReservation(reservation1);\r
891 \r
892 uc.deleteReservation(null);\r
893 \r
894 assertEquals(null, uc.getReservation(reservation1.getId()));\r
895 }\r
896 \r
897 @Test(expected=Exception.class)\r
898 public void deleteReservationException4Test() throws Exception{\r
899 DataHandler dh = new DataHandlerForTests();\r
900 UserController uc = new UserController();\r
901 uc.setDataHandler(dh);\r
902 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
903 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
904 uc.logIn("TestUser1", "pass1");\r
905 \r
906 UUID groupId = UUID.randomUUID();\r
907 Date start = new Date();\r
908 start.setTime((System.currentTimeMillis() % 1000));\r
909 Date finish = (Date)start.clone();\r
910 finish.setMinutes(start.getMinutes() + 30);\r
911 DateRange dateRange = new DateRangeImpl(start, finish);\r
912 \r
913 Resource resource1 = new Resource("Room101", "Class room");\r
914 dh.addResource(resource1);\r
915 \r
916 User loggedUser = uc.getLoggedUser();\r
917 User testUser2 = uc.getUser("TestUser2");\r
918 \r
919 Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
920 dh.addReservation(reservation1);\r
921 \r
922 uc.logOut();\r
923 uc.logIn("TestUser2", "pass2");\r
924 uc.deleteReservation(reservation1);\r
925 \r
926 assertEquals(null, uc.getReservation(reservation1.getId()));\r
927 }\r
928 \r
929 @Test\r
930 public void getResourcesTest() throws Exception{\r
931 DataHandler dh = new DataHandlerForTests();\r
932 UserController uc = new UserController();\r
933 uc.setDataHandler(dh);\r
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
937 \r
938 Date start = new Date();\r
939 start.setTime((System.currentTimeMillis() % 1000));\r
940 Date finish = (Date)start.clone();\r
941 finish.setMinutes(start.getMinutes() + 30);\r
942 \r
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
949 \r
950 List<Resource> resList = uc.getResources();\r
951 \r
952 assertEquals(3,resList.size());\r
953 }\r
954 \r
955 @Test(expected=Exception.class)\r
956 public void getResourcesExceptionTest() throws Exception{\r
957 DataHandler dh = new DataHandlerForTests();\r
958 UserController uc = new UserController();\r
959 uc.setDataHandler(dh);\r
960 uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
961 uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
962 uc.logIn("TestUser1", "pass1");\r
963 \r
964 Date start = new Date();\r
965 start.setTime((System.currentTimeMillis() % 1000));\r
966 Date finish = (Date)start.clone();\r
967 finish.setMinutes(start.getMinutes() + 30);\r
968 \r
969 Resource resource1 = new Resource("Room101", "Class room");\r
970 Resource resource2 = new Resource("Room101", "Class room");\r
971 Resource resource3 = new Resource("Room101", "Class room");\r
972 dh.addResource(resource1);\r
973 dh.addResource(resource2);\r
974 dh.addResource(resource3);\r
975 \r
976 uc.setDataHandler(null);\r
977 List<Resource> resList = uc.getResources();\r
978 \r
979 assertEquals(3,resList.size());\r
980 }\r
1ec0e01f 981}\r