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