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