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