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