Added isModified method to Resource, Reservation.
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / dataschema / ReservationTest.java
index a48b593..bfd3093 100644 (file)
@@ -8,7 +8,9 @@
 package ch.bfh.ti.srs.dataschema;\r
 \r
 import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
 import static org.junit.Assert.assertNotEquals;\r
+import static org.junit.Assert.assertTrue;\r
 \r
 import java.util.UUID;\r
 \r
@@ -40,8 +42,9 @@ public class ReservationTest {
                Resource testResource = new Resource("N321", "class room");\r
                DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
                                DateFactory.createDate(2015, 11, 13));\r
-               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr, "TestReservation");\r
-               \r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
+                               "TestReservation");\r
+\r
                assertNotEquals(null, testReservation.getId());\r
                assertNotEquals(null, testReservation.getGroupId());\r
                assertEquals(testUser, testReservation.getUser());\r
@@ -49,14 +52,31 @@ public class ReservationTest {
                assertEquals(testDr, testReservation.getDateRange());\r
                assertEquals("TestReservation", testReservation.getRemark());\r
        }\r
-       \r
+\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void createReservationInvalidUserTest() throws Exception {\r
+               Resource testResource = new Resource("N321", "class room");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
+                               DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), null, testResource, testDr, "TestReservation");\r
+       }\r
+\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void createReservationInvalidResourceTest() throws Exception {\r
+               User testUser = new User("TestUser", "pass");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
+                               DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, null, testDr, "TestReservation");\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),\r
                                DateFactory.createDate(2015, 11, 13));\r
-               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr, "TestReservation");\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
+                               "TestReservation");\r
 \r
                testReservation.setRemark("otherTestReservation");\r
                assertEquals("otherTestReservation", testReservation.getRemark());\r
@@ -68,7 +88,8 @@ public class ReservationTest {
                Resource testResource = new Resource("N321", "class room");\r
                DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
                                DateFactory.createDate(2015, 11, 13));\r
-               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr, "TestReservation");\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
+                               "TestReservation");\r
 \r
                User otherTestUser = new User("otherTestUser", "pass");\r
                testReservation.setUser(otherTestUser);\r
@@ -81,11 +102,12 @@ public class ReservationTest {
                Resource testResource = new Resource("N321", "class room");\r
                DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
                                DateFactory.createDate(2015, 11, 13));\r
-               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr, "TestReservation");\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
+                               "TestReservation");\r
 \r
-               Resource OtherTestResource = new Resource("N421", "lecture hall");\r
-               testReservation.setResource(OtherTestResource);\r
-               assertEquals(OtherTestResource, testReservation.getResource());\r
+               Resource otherTestResource = new Resource("N421", "lecture hall");\r
+               testReservation.setResource(otherTestResource);\r
+               assertEquals(otherTestResource, testReservation.getResource());\r
        }\r
 \r
        @Test\r
@@ -94,11 +116,52 @@ public class ReservationTest {
                Resource testResource = new Resource("N321", "class room");\r
                DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
                                DateFactory.createDate(2015, 11, 13));\r
-               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr, "TestReservation");\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
+                               "TestReservation");\r
 \r
                DateRange otherTestDr = factory.createDateRange(DateFactory.createDate(2015, 12, 9),\r
                                DateFactory.createDate(2015, 12, 13));\r
                testReservation.setDateRange(otherTestDr);\r
                assertEquals(otherTestDr, testReservation.getDateRange());\r
        }\r
+\r
+       @Test\r
+       public void isModifiedTest() 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),\r
+                               DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
+                               "TestReservation");\r
+               Reservation clonedTestReservation = testReservation.clone();\r
+               \r
+               assertTrue(testReservation.isModified(null));\r
+               assertFalse(testReservation.isModified(testReservation));\r
+               assertFalse(testReservation.isModified(clonedTestReservation));\r
+               \r
+               User otherTestUser = new User("otherTestUser", "pass");\r
+               clonedTestReservation.setUser(otherTestUser);\r
+               assertTrue(testReservation.isModified(clonedTestReservation));\r
+               \r
+               clonedTestReservation.setUser(testUser);\r
+               assertFalse(testReservation.isModified(clonedTestReservation));\r
+\r
+               Resource otherTestResource = new Resource("N421", "lecture hall");\r
+               clonedTestReservation.setResource(otherTestResource);\r
+               assertTrue(testReservation.isModified(clonedTestReservation));\r
+               \r
+               clonedTestReservation.setResource(testResource);\r
+               assertFalse(testReservation.isModified(clonedTestReservation));\r
+               \r
+               DateRange otherTestDr = factory.createDateRange(DateFactory.createDate(2015, 12, 9),\r
+                               DateFactory.createDate(2015, 12, 13));\r
+               clonedTestReservation.setDateRange(otherTestDr);\r
+               assertTrue(testReservation.isModified(clonedTestReservation));\r
+               \r
+               clonedTestReservation.setDateRange(testDr);\r
+               assertFalse(testReservation.isModified(clonedTestReservation));\r
+               \r
+               clonedTestReservation.setRemark("some other remark");\r
+               assertTrue(testReservation.isModified(clonedTestReservation));\r
+       }\r
 }\r