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