Usage of Date fixed
authorMichael <Michael@Michael-LT.fritz.box>
Sat, 28 Nov 2015 10:25:16 +0000 (11:25 +0100)
committerMichael <Michael@Michael-LT.fritz.box>
Sat, 28 Nov 2015 10:25:16 +0000 (11:25 +0100)
src/test/java/ch/bfh/ti/srs/controller/UserControllerTest.java

index 427bc2d..c8cf6a9 100644 (file)
@@ -166,7 +166,7 @@ public class UserControllerTest {
        @Test(expected=Exception.class)\r
        public void getLoggedNameExceptionTest() throws Exception{\r
                UserController uc = new UserController();\r
-               String currentName = uc.getLoggedName();\r
+               uc.getLoggedName();\r
        }\r
        \r
        @Test\r
@@ -282,10 +282,8 @@ public class UserControllerTest {
                uc.logIn("TestUser1", "pass1");\r
                \r
                UUID groupId = UUID.randomUUID();\r
-               Date start = new Date();\r
-               start.setTime((System.currentTimeMillis() % 1000));\r
-               Date finish = (Date)start.clone();\r
-               finish.setMinutes(start.getMinutes() + 30);\r
+               Date start = new Date(2015,11,28,11,00,00);\r
+               Date finish = new Date(2015,11,28,11,30,00);\r
                DateRange dateRange = new DateRangeImpl(start, finish);\r
                \r
                Resource resource1 = new Resource("Room101", "Class room");\r
@@ -386,8 +384,7 @@ public class UserControllerTest {
                uc.getReservationsInDateRange(null);\r
        }\r
        \r
-       @Ignore("disabled until implementation is finished")\r
-       //@Test\r
+       @Test\r
        public void makeReservationTest() throws Exception{\r
                DataHandler dh = new DataHandlerForTests();\r
                UserController uc = new UserController();\r
@@ -396,11 +393,6 @@ public class UserControllerTest {
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
                \r
-               Date start = new Date();\r
-               start.setTime((System.currentTimeMillis() % 1000));\r
-               Date finish = (Date)start.clone();\r
-               finish.setMinutes(start.getMinutes() + 30);\r
-               \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                Resource resource2 = new Resource("Room101", "Class room");\r
                Resource resource3 = new Resource("Room101", "Class room");\r
@@ -409,19 +401,15 @@ public class UserControllerTest {
                dh.addResource(resource3);\r
                \r
                List<DateRange> dtList = new ArrayList<DateRange>();\r
-               // Woechentlich, 10 Wochen lang\r
                for(int i = 1;i<10;i++){\r
-                       start.setDate(start.getDate() + (i*7));\r
-                       finish.setDate(finish.getDate() + (i*7));\r
-                       dtList.add(new DateRangeImpl(start, finish));\r
+                       dtList.add(new DateRangeImpl(new Date(2015,12,2+i,11,00,00), new Date(2015,12,2+i,11,00,00)));\r
                }\r
                \r
                assertEquals(null, uc.makeReservation(uc.getLoggedUser(), resource1, dtList, "remark"));\r
                assertEquals(null, uc.makeReservation(null, resource2, dtList, "remark"));\r
        }\r
        \r
-       @Ignore("disabled until implementation is finished")\r
-       //@Test\r
+       @Test\r
        public void makeInvalidReservationTest() throws Exception{\r
                DataHandler dh = new DataHandlerForTests();\r
                UserController uc = new UserController();\r
@@ -430,11 +418,6 @@ public class UserControllerTest {
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
                \r
-               Date start = new Date();\r
-               start.setTime((System.currentTimeMillis() % 1000));\r
-               Date finish = (Date)start.clone();\r
-               finish.setMinutes(start.getMinutes() + 30);\r
-               \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                Resource resource2 = new Resource("Room101", "Class room");\r
                Resource resource3 = new Resource("Room101", "Class room");\r
@@ -443,27 +426,23 @@ public class UserControllerTest {
                dh.addResource(resource3);\r
                \r
                List<DateRange> dtList = new ArrayList<DateRange>();\r
-               // Woechentlich, 10 Wochen lang\r
                for(int i = 1;i<10;i++){\r
-                       start.setDate(start.getDate() + (i*7));\r
-                       finish.setDate(finish.getDate() + (i*7));\r
-                       dtList.add(new DateRangeImpl(start, finish));\r
+                       dtList.add(new DateRangeImpl(new Date(2015,12,2+i,11,00,00), new Date(2015,12,2+i,12,00,00)));\r
                }\r
                \r
-               dtList.remove(0);\r
-               dtList.remove(1);\r
-               dtList.remove(2);\r
-               dtList.remove(3);\r
-               \r
-               Set<Reservation> resList = uc.makeReservation(uc.getLoggedUser(), resource1, dtList, "remark");\r
-               Iterator iter = resList.iterator();\r
-               while (iter.hasNext()) {\r
-                       Reservation res = (Reservation)iter.next();\r
-                   System.out.println(res.getDateRange().getStart() + "\t" + res.getDateRange().getFinish());\r
-               }\r
+               List<DateRange> conflictingList = new ArrayList<DateRange>();\r
+               // Conflicts\r
+               conflictingList.add(new DateRangeImpl(new Date(2015,12,4,11,00,00),new Date(2015,12,4,12,00,00)));\r
+               conflictingList.add(new DateRangeImpl(new Date(2015,12,4,11,15,00),new Date(2015,12,4,11,45,00)));\r
+               conflictingList.add(new DateRangeImpl(new Date(2015,12,4,10,00,00),new Date(2015,12,4,17,00,00)));\r
+               conflictingList.add(new DateRangeImpl(new Date(2015,12,4,11,30,00),new Date(2015,12,4,12,30,00)));\r
                \r
-//             assertEquals(null, uc.makeReservation(uc.getLoggedUser(), resource1, dtList, "remark"));                \r
-//             assertEquals(9, uc.makeReservation(uc.getLoggedUser(), resource1, dtList, null).size());\r
+               // OK\r
+               conflictingList.add(new DateRangeImpl(new Date(2015,12,4,10,30,00),new Date(2015,12,4,10,59,59)));\r
+               conflictingList.add(new DateRangeImpl(new Date(2015,12,4,12,00,01),new Date(2015,12,4,12,45,00)));\r
+\r
+               assertEquals(null, uc.makeReservation(uc.getLoggedUser(), resource1, dtList, "remark"));                \r
+               assertEquals(4, uc.makeReservation(uc.getLoggedUser(), resource1, conflictingList, null).size());\r
        }\r
 \r
        @Test(expected=IllegalArgumentException.class)\r
@@ -475,11 +454,6 @@ public class UserControllerTest {
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
                \r
-               Date start = new Date();\r
-               start.setTime((System.currentTimeMillis() % 1000));\r
-               Date finish = (Date)start.clone();\r
-               finish.setMinutes(start.getMinutes() + 30);\r
-               \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                Resource resource2 = new Resource("Room101", "Class room");\r
                Resource resource3 = new Resource("Room101", "Class room");\r
@@ -488,11 +462,8 @@ public class UserControllerTest {
                dh.addResource(resource3);\r
                \r
                List<DateRange> dtList = new ArrayList<DateRange>();\r
-               // Woechentlich, 10 Wochen lang\r
                for(int i = 1;i<10;i++){\r
-                       start.setDate(start.getDate() + (i*7));\r
-                       finish.setDate(finish.getDate() + (i*7));\r
-                       dtList.add(new DateRangeImpl(start, finish));\r
+                       dtList.add(new DateRangeImpl(new Date(2015,12,2+i,11,00,00), new Date(2015,12,2+i,12,00,00)));\r
                }\r
                \r
                uc.logOut();\r
@@ -508,11 +479,6 @@ public class UserControllerTest {
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
                \r
-               Date start = new Date();\r
-               start.setTime((System.currentTimeMillis() % 1000));\r
-               Date finish = (Date)start.clone();\r
-               finish.setMinutes(start.getMinutes() + 30);\r
-               \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                Resource resource2 = new Resource("Room101", "Class room");\r
                Resource resource3 = new Resource("Room101", "Class room");\r
@@ -521,11 +487,8 @@ public class UserControllerTest {
                dh.addResource(resource3);\r
                \r
                List<DateRange> dtList = new ArrayList<DateRange>();\r
-               // Woechentlich, 10 Wochen lang\r
                for(int i = 1;i<10;i++){\r
-                       start.setDate(start.getDate() + (i*7));\r
-                       finish.setDate(finish.getDate() + (i*7));\r
-                       dtList.add(new DateRangeImpl(start, finish));\r
+                       dtList.add(new DateRangeImpl(new Date(2015,12,2+i,11,00,00), new Date(2015,12,2+i,12,00,00)));\r
                }\r
                \r
                assertEquals(null, uc.makeReservation(null, null, dtList, "remark"));\r
@@ -540,11 +503,6 @@ public class UserControllerTest {
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
                \r
-               Date start = new Date();\r
-               start.setTime((System.currentTimeMillis() % 1000));\r
-               Date finish = (Date)start.clone();\r
-               finish.setMinutes(start.getMinutes() + 30);\r
-               \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                Resource resource2 = new Resource("Room101", "Class room");\r
                Resource resource3 = new Resource("Room101", "Class room");\r
@@ -553,11 +511,8 @@ public class UserControllerTest {
                dh.addResource(resource3);\r
                \r
                List<DateRange> dtList = new ArrayList<DateRange>();\r
-               // Woechentlich, 10 Wochen lang\r
                for(int i = 1;i<10;i++){\r
-                       start.setDate(start.getDate() + (i*7));\r
-                       finish.setDate(finish.getDate() + (i*7));\r
-                       dtList.add(new DateRangeImpl(start, finish));\r
+                       dtList.add(new DateRangeImpl(new Date(2015,12,2+i,11,00,00), new Date(2015,12,2+i,12,00,00)));\r
                }\r
                \r
                assertEquals(null, uc.makeReservation(null, resource1, null, "remark"));\r
@@ -572,11 +527,6 @@ public class UserControllerTest {
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.logIn("TestUser1", "pass1");\r
                \r
-               Date start = new Date();\r
-               start.setTime((System.currentTimeMillis() % 1000));\r
-               Date finish = (Date)start.clone();\r
-               finish.setMinutes(start.getMinutes() + 30);\r
-               \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                Resource resource2 = new Resource("Room101", "Class room");\r
                Resource resource3 = new Resource("Room101", "Class room");\r
@@ -599,11 +549,7 @@ public class UserControllerTest {
                uc.logIn("TestUser1", "pass1");\r
                \r
                UUID groupId = UUID.randomUUID();\r
-               Date start = new Date();\r
-               start.setTime((System.currentTimeMillis() % 1000));\r
-               Date finish = (Date)start.clone();\r
-               finish.setMinutes(start.getMinutes() + 30);\r
-               DateRange dateRange = new DateRangeImpl(start, finish);\r
+               DateRange dateRange = new DateRangeImpl(new Date(2015,12,7,14,00,00), new Date(2015,12,7,15,00,00));\r
                \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
@@ -615,9 +561,7 @@ public class UserControllerTest {
                dh.addReservation(reservation1);\r
                \r
                Reservation reservationClone = uc.getReservation(reservation1.getId());\r
-               start.setDate(start.getDate() + 1);\r
-               finish.setDate(finish.getDate() + 1);\r
-               DateRange newDateRange = new DateRangeImpl(start, finish);\r
+               DateRange newDateRange = new DateRangeImpl(new Date(2015,12,7,20,00,00), new Date(2015,12,8,02,00,00));\r
                reservationClone.setDateRange(newDateRange);\r
                uc.changeReservation(reservationClone);\r
                \r