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