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