added id, groupid
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / dataschema / ReservationTest.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.dataschema;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotEquals;
12
13 import java.util.UUID;
14
15 import org.junit.Before;
16 import org.junit.Test;
17
18 import ch.bfh.ti.daterange.DateFactory;
19 import ch.bfh.ti.daterange.DateRange;
20 import ch.bfh.ti.daterange.DateRangeFactory;
21 import ch.bfh.ti.srs.dataschema.Reservation;
22 import ch.bfh.ti.srs.dataschema.Resource;
23 import ch.bfh.ti.srs.dataschema.User;
24
25 public class ReservationTest {
26
27 private DateRangeFactory factory;
28
29 @Before
30 public void setUp() throws Exception {
31 String className = System.getProperty("daterangefactory.name",
32 "ch.bfh.ti.daterange.impl.pojo.DateRangeFactory");
33 Class<?> clazz = Class.forName(className);
34 factory = (DateRangeFactory) clazz.newInstance();
35 }
36
37 @Test
38 public void createReservationTest() throws Exception {
39 User testUser = new User("TestUser", "pass");
40 Resource testResource = new Resource("N321", "class room");
41 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),
42 DateFactory.createDate(2015, 11, 13));
43 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr, "TestReservation");
44
45 assertNotEquals(null, testReservation.getId());
46 assertNotEquals(null, testReservation.getGroupId());
47 assertEquals(testUser, testReservation.getUser());
48 assertEquals(testResource, testReservation.getResource());
49 assertEquals(testDr, testReservation.getDateRange());
50 assertEquals("TestReservation", testReservation.getRemark());
51 }
52
53 @Test
54 public void setAndGetNameTest() throws Exception {
55 User testUser = new User("TestUser", "pass");
56 Resource testResource = new Resource("N321", "class room");
57 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),
58 DateFactory.createDate(2015, 11, 13));
59 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr, "TestReservation");
60
61 testReservation.setRemark("otherTestReservation");
62 assertEquals("otherTestReservation", testReservation.getRemark());
63 }
64
65 @Test
66 public void setAndGetUserTest() throws Exception {
67 User testUser = new User("TestUser", "pass");
68 Resource testResource = new Resource("N321", "class room");
69 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),
70 DateFactory.createDate(2015, 11, 13));
71 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr, "TestReservation");
72
73 User otherTestUser = new User("otherTestUser", "pass");
74 testReservation.setUser(otherTestUser);
75 assertEquals(otherTestUser, testReservation.getUser());
76 }
77
78 @Test
79 public void setAndGetResourceTest() throws Exception {
80 User testUser = new User("TestUser", "pass");
81 Resource testResource = new Resource("N321", "class room");
82 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),
83 DateFactory.createDate(2015, 11, 13));
84 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr, "TestReservation");
85
86 Resource OtherTestResource = new Resource("N421", "lecture hall");
87 testReservation.setResource(OtherTestResource);
88 assertEquals(OtherTestResource, testReservation.getResource());
89 }
90
91 @Test
92 public void setAndGetDateRangeTest() throws Exception {
93 User testUser = new User("TestUser", "pass");
94 Resource testResource = new Resource("N321", "class room");
95 DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),
96 DateFactory.createDate(2015, 11, 13));
97 Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr, "TestReservation");
98
99 DateRange otherTestDr = factory.createDateRange(DateFactory.createDate(2015, 12, 9),
100 DateFactory.createDate(2015, 12, 13));
101 testReservation.setDateRange(otherTestDr);
102 assertEquals(otherTestDr, testReservation.getDateRange());
103 }
104 }