Add Resource, Reservation, ResourceTest, ReservationTest classes
authorMoritz Trittibach <tritm3@bfh.ch>
Mon, 9 Nov 2015 10:44:01 +0000 (11:44 +0100)
committerMoritz Trittibach <tritm3@bfh.ch>
Mon, 9 Nov 2015 10:44:01 +0000 (11:44 +0100)
src/main/java/ch/bfh/ti/srs/dataschema/Reservation.java [new file with mode: 0644]
src/main/java/ch/bfh/ti/srs/dataschema/Resource.java [new file with mode: 0644]
src/main/java/ch/bfh/ti/srs/extern/date-range.jar [new file with mode: 0644]
src/test/java/ch/bfh/ti/srs/core/ReservationTest.java [new file with mode: 0644]
src/test/java/ch/bfh/ti/srs/core/ResourceTest.java [new file with mode: 0644]

diff --git a/src/main/java/ch/bfh/ti/srs/dataschema/Reservation.java b/src/main/java/ch/bfh/ti/srs/dataschema/Reservation.java
new file mode 100644 (file)
index 0000000..2aa7c0d
--- /dev/null
@@ -0,0 +1,57 @@
+/*\r
+ * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
+ *\r
+ * Project Smart Reservation System.\r
+ *\r
+ * Distributable under GPL license. See terms of license at gnu.org.\r
+ */\r
+package ch.bfh.ti.srs.dataschema;\r
+\r
+import ch.bfh.ti.daterange.DateRange;\r
+\r
+public class Reservation {\r
+\r
+       private String name;\r
+       private User user;\r
+       private Resource resource;\r
+       private DateRange dateRange;\r
+\r
+       public Reservation(String name, User user, Resource resource, DateRange DateRange) {\r
+               this.name = name;\r
+               this.user = user;\r
+               this.resource = resource;\r
+               this.dateRange = DateRange;\r
+       }\r
+\r
+       public String getName() {\r
+               return name;\r
+       }\r
+\r
+       public User getUser() {\r
+               return user;\r
+       }\r
+\r
+       public Resource getResource() {\r
+               return resource;\r
+       }\r
+\r
+       public DateRange getDateRange() {\r
+               return dateRange;\r
+       }\r
+\r
+       public void setName(String name) {\r
+               this.name = name;\r
+       }\r
+\r
+       public void setUser(User user) {\r
+               this.user = user;\r
+       }\r
+\r
+       public void setResource(Resource resource) {\r
+               this.resource = resource;\r
+       }\r
+\r
+       public void setDateRange(DateRange dateRange) {\r
+               this.dateRange = dateRange;\r
+       }\r
+}\r
diff --git a/src/main/java/ch/bfh/ti/srs/dataschema/Resource.java b/src/main/java/ch/bfh/ti/srs/dataschema/Resource.java
new file mode 100644 (file)
index 0000000..e9913eb
--- /dev/null
@@ -0,0 +1,46 @@
+/*\r
+ * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
+ *\r
+ * Project Smart Reservation System.\r
+ *\r
+ * Distributable under GPL license. See terms of license at gnu.org.\r
+ */\r
+package ch.bfh.ti.srs.dataschema;\r
+\r
+public class Resource {\r
+\r
+       private String name;\r
+       private String type;\r
+\r
+       /**\r
+        * Normal constructor for new resources created in the UserController\r
+        * \r
+        * @param name\r
+        * @param type\r
+        * @throws Exception\r
+        */\r
+\r
+       public Resource(String name, String type) throws Exception{\r
+               if (name == null)\r
+                       throw new IllegalArgumentException("Name must not be null");\r
+\r
+               this.name = name;\r
+               this.type = type;\r
+       }\r
+\r
+       public String getName() {\r
+               return name;\r
+       }\r
+\r
+       public String getType() {\r
+               return type;\r
+       }\r
+\r
+       public void setName(String name) {\r
+               this.name = name;\r
+       }\r
+\r
+       public void setType(String type) {\r
+               this.type = type;\r
+       }\r
+}\r
diff --git a/src/main/java/ch/bfh/ti/srs/extern/date-range.jar b/src/main/java/ch/bfh/ti/srs/extern/date-range.jar
new file mode 100644 (file)
index 0000000..9c7b51b
Binary files /dev/null and b/src/main/java/ch/bfh/ti/srs/extern/date-range.jar differ
diff --git a/src/test/java/ch/bfh/ti/srs/core/ReservationTest.java b/src/test/java/ch/bfh/ti/srs/core/ReservationTest.java
new file mode 100644 (file)
index 0000000..cf4779e
--- /dev/null
@@ -0,0 +1,93 @@
+/*\r
+ * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
+ *\r
+ * Project Smart Reservation System.\r
+ *\r
+ * Distributable under GPL license. See terms of license at gnu.org.\r
+ */\r
+package ch.bfh.ti.srs.core;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+import ch.bfh.ti.daterange.DateFactory;\r
+import ch.bfh.ti.daterange.DateRange;\r
+import ch.bfh.ti.daterange.DateRangeFactory;\r
+import ch.bfh.ti.srs.dataschema.Reservation;\r
+import ch.bfh.ti.srs.dataschema.Resource;\r
+import ch.bfh.ti.srs.dataschema.User;\r
+\r
+public class ReservationTest {\r
+\r
+       private DateRangeFactory factory;\r
+       \r
+       @Before\r
+       public void setUp() throws Exception {\r
+               String className = System.getProperty("daterangefactory.name",\r
+                               "ch.bfh.ti.daterange.impl.pojo.DateRangeFactory");\r
+               Class<?> clazz = Class.forName(className);\r
+               factory = (DateRangeFactory) clazz.newInstance();\r
+       }\r
+       \r
+       @Test\r
+       public void createReservationTest() throws Exception {\r
+               User testUser = new User("TestUser", "pass");\r
+               Resource testResource = new Resource("N321", "class room");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9), DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation("TestReservation", testUser, testResource, testDr);\r
+               \r
+               assertEquals("TestReservation", testReservation.getName());\r
+               assertEquals(testUser, testReservation.getUser());\r
+               assertEquals(testResource, testReservation.getResource());\r
+               assertEquals(testDr, testReservation.getDateRange());\r
+       }       \r
+       \r
+       @Test\r
+       public void setAndGetNameTest() throws Exception {\r
+               User testUser = new User("TestUser", "pass");\r
+               Resource testResource = new Resource("N321", "class room");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9), DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation("TestReservation", testUser, testResource, testDr);\r
+               \r
+               testReservation.setName("otherTestReservation");\r
+               assertEquals("otherTestReservation", testReservation.getName());\r
+       }\r
+       \r
+       @Test\r
+       public void setAndGetUserTest() throws Exception {\r
+               User testUser = new User("TestUser", "pass");\r
+               Resource testResource = new Resource("N321", "class room");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9), DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation("TestReservation", testUser, testResource, testDr);\r
+               \r
+               User otherTestUser = new User("otherTestUser", "pass");\r
+               testReservation.setUser(otherTestUser);\r
+               assertEquals(otherTestUser, testReservation.getUser());\r
+       }\r
+       \r
+       @Test\r
+       public void setAndGetResourceTest() throws Exception {\r
+               User testUser = new User("TestUser", "pass");\r
+               Resource testResource = new Resource("N321", "class room");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9), DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation("TestReservation", testUser, testResource, testDr);\r
+               \r
+               Resource OtherTestResource = new Resource("N421", "lecture hall");\r
+               testReservation.setResource(OtherTestResource);\r
+               assertEquals(OtherTestResource, testReservation.getResource());\r
+       }\r
+       \r
+       @Test\r
+       public void setAndGetDateRangeTest() throws Exception {\r
+               User testUser = new User("TestUser", "pass");\r
+               Resource testResource = new Resource("N321", "class room");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9), DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation("TestReservation", testUser, testResource, testDr);\r
+               \r
+               DateRange otherTestDr = factory.createDateRange(DateFactory.createDate(2015, 12, 9), DateFactory.createDate(2015, 12, 13));\r
+               testReservation.setDateRange(otherTestDr);\r
+               assertEquals(otherTestDr, testReservation.getDateRange());\r
+       }\r
+}\r
diff --git a/src/test/java/ch/bfh/ti/srs/core/ResourceTest.java b/src/test/java/ch/bfh/ti/srs/core/ResourceTest.java
new file mode 100644 (file)
index 0000000..2d33503
--- /dev/null
@@ -0,0 +1,47 @@
+/*\r
+ * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
+ *\r
+ * Project Smart Reservation System.\r
+ *\r
+ * Distributable under GPL license. See terms of license at gnu.org.\r
+ */\r
+package ch.bfh.ti.srs.core;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import org.junit.Test;\r
+\r
+import ch.bfh.ti.srs.dataschema.Resource;\r
+\r
+public class ResourceTest {\r
+\r
+       @Test\r
+       public void createResurceTest() throws Exception {\r
+               Resource testResource = new Resource("N321", "class room");\r
+               assertEquals("N321", testResource.getName());\r
+               assertEquals("class room", testResource.getType());\r
+       }\r
+\r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void createUserInvalidNameTest() throws Exception{\r
+               Resource testResource = new Resource(null, "class room");\r
+       }\r
+       \r
+       @Test\r
+       public void setAndGetNameTest() throws Exception {\r
+               Resource testRessource = new Resource("N321", "class room");\r
+               testRessource.setName("N421");\r
+               assertEquals("N421", testRessource.getName());\r
+               testRessource.setName(null);\r
+               assertEquals(null, testRessource.getName());\r
+       }\r
+\r
+       @Test\r
+       public void setAndGetTypeTest() throws Exception {\r
+               Resource testRessource = new Resource("N321", "class room");\r
+               testRessource.setType("lecture hall");\r
+               assertEquals("lecture hall", testRessource.getType());\r
+               testRessource.setType(null);\r
+               assertEquals(null, testRessource.getType());\r
+       }\r
+}\r