warnings fixed
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / controller / UserControllerTest.java
index 016ae1b..a63687e 100644 (file)
@@ -11,11 +11,26 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;\r
 import static org.junit.Assert.assertTrue;\r
 \r
+import java.util.ArrayList;\r
+import java.util.Date;\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+import java.util.UUID;\r
+\r
+import org.junit.Ignore;\r
 import org.junit.Test;\r
 \r
+import ch.bfh.ti.daterange.DateRange;\r
+import ch.bfh.ti.daterange.impl.pojo.DateRangeImpl;\r
 import ch.bfh.ti.srs.controller.UserController;\r
 import ch.bfh.ti.srs.datahandler.DataHandler;\r
 import ch.bfh.ti.srs.datahandler.DataHandlerForTests;\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
 /**\r
  * @author Michael Grossen\r
@@ -23,188 +38,914 @@ import ch.bfh.ti.srs.datahandler.DataHandlerForTests;
 public class UserControllerTest {\r
 \r
        @Test\r
-       public void addUserTest() throws Exception{\r
+       public void addUserTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               \r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
                uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
        }\r
-       \r
-       @Test(expected=Exception.class)\r
-       public void addUserExceptionTest() throws Exception{\r
+\r
+       @Test(expected = Exception.class)\r
+       public void addUserExceptionTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               \r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
+\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
        }\r
 \r
        @Test\r
-       public void logInTest() throws Exception{\r
+       public void logInTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               \r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
                uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
-               \r
+\r
                uc.logIn("TestUser3", "pass3");\r
        }\r
-       \r
-       @Test(expected=Exception.class)\r
-       public void logInException1Test() throws Exception{\r
+\r
+       @Test(expected = Exception.class)\r
+       public void logInException1Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
                uc.logIn("TestUser3", "pass3");\r
        }\r
 \r
-       @Test(expected=Exception.class)\r
-       public void logInException2Test() throws Exception{\r
+       @Test(expected = Exception.class)\r
+       public void logInException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               \r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-               \r
+\r
                uc.logIn("TestUser1", "pass1");\r
                uc.logIn("TestUser2", "pass2");\r
        }\r
-       \r
+\r
        @Test\r
-       public void logInInvalidCredetialsTest() throws Exception{\r
+       public void logInInvalidCredetialsTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               \r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-               \r
+\r
                assertFalse(uc.logIn("TestUser3", "pass3"));\r
                assertFalse(uc.logIn("TestUser1", "pass2"));\r
                assertTrue(uc.logIn("TestUser1", "pass1"));\r
        }\r
-       \r
+\r
+       @SuppressWarnings("deprecation")\r
        @Test\r
-       public void getLoggedUserNameTest() throws Exception{\r
+       public void getLoggedUserNameTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               \r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
                uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
-               \r
+\r
                uc.logIn("TestUser1", "pass1");\r
                assertEquals("TestUser1", uc.getLoggedUserName());\r
        }\r
-       \r
 \r
-       @Test(expected=Exception.class)\r
-       public void getLoggedUserNameExceptionTest() throws Exception{\r
-               UserController uc = new UserController();\r
-               String currentUserName = uc.getLoggedUserName();\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void getLoggedUserNameExceptionTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
+               uc.getLoggedUserName();\r
        }\r
-       \r
+\r
+       @SuppressWarnings("deprecation")\r
        @Test\r
-       public void getLoggedUserMailTest() throws Exception{\r
+       public void getLoggedUserMailTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               \r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "hanfli@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
                uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
-               \r
+\r
                uc.logIn("TestUser2", "pass2");\r
                assertEquals("hanfli@bfh.ch", uc.getLoggedMail());\r
        }\r
-       \r
-       @Test(expected=Exception.class)\r
-       public void getLoggedMailExceptionTest() throws Exception{\r
-               UserController uc = new UserController();\r
-               String currentMail = uc.getLoggedMail();\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void getLoggedMailExceptionTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
+               uc.getLoggedMail();\r
        }\r
-       \r
+\r
+       @SuppressWarnings("deprecation")\r
        @Test\r
-       public void getLoggedNameTest() throws Exception{\r
+       public void getLoggedNameTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               \r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Hanfli", null);\r
                uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
-               \r
+\r
                uc.logIn("TestUser3", "pass3");\r
                assertEquals("Hanfli", uc.getLoggedName());\r
        }\r
-       \r
-       @Test(expected=Exception.class)\r
-       public void getLoggedNameExceptionTest() throws Exception{\r
-               UserController uc = new UserController();\r
-               String currentName = uc.getLoggedName();\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void getLoggedNameExceptionTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
+               uc.getLoggedName();\r
        }\r
-       \r
+\r
+       @SuppressWarnings("deprecation")\r
        @Test\r
-       public void getLoggedLastnameTest() throws Exception{\r
+       public void getLoggedLastnameTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               \r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
                uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
-               \r
+\r
                uc.logIn("TestUser4", "pass4");\r
                assertEquals("User", uc.getLoggedLastname());\r
        }\r
-       \r
-       @Test(expected=Exception.class)\r
-       public void getLoggedLastnameExceptionTest() throws Exception{\r
-               UserController uc = new UserController();\r
-               String currentLastName = uc.getLoggedLastname();\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void getLoggedLastnameExceptionTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
+               uc.getLoggedLastname();\r
+       }\r
+\r
+       @Test\r
+       public void getLoggedUserTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               assertEquals(null, uc.getLoggedUser());\r
+               uc.logIn("TestUser1", "pass1");\r
+               assertEquals("TestUser1", uc.getLoggedUser().getUserName());\r
+       }\r
+\r
+       // @Test(expected=Exception.class)\r
+       // public void getLoggedUserExceptionTest() throws Exception{\r
+       // DataHandler dh = new DataHandlerForTests();\r
+       // UserController uc = new UserController(dh);\r
+       //\r
+       // uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+       // uc.logIn("TestUser1", "pass1");\r
+       // assertEquals("TestUser1", uc.getLoggedUser().getUserName());\r
+       // }\r
+\r
+       @Test\r
+       public void getUserTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.logIn("TestUser1", "pass1");\r
+               assertEquals("grosm9@bfh.ch", uc.getUser("TestUser1").getMail());\r
        }\r
-       \r
+\r
+       @Test(expected = Exception.class)\r
+       public void getUserExceptionTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
+\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.logIn("TestUser1", "pass1");\r
+               assertEquals("grosm9@bfh.ch", uc.getUser("TestUser1").getMail());\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
        @Test\r
-       public void logOutTest() throws Exception{\r
+       public void logOutTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               \r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+\r
+               //uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
                uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
                uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
-               \r
+\r
                uc.logIn("TestUser1", "pass1");\r
                assertEquals("TestUser1", uc.getLoggedUserName());\r
                uc.logOut();\r
        }\r
-       \r
-       @Test(expected=Exception.class)\r
-       public void logOutException1Test() throws Exception{\r
+\r
+       @Test(expected = Exception.class)\r
+       public void logOutException1Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
+\r
+               uc.logOut();\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void logOutException2Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+\r
+               //uc.setDataHandler(dh);\r
+               uc.logOut();\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void getUserExpectionTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
+               uc.getUser(null);\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test\r
+       public void getReservationTests() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.logIn("TestUser1", "pass1");\r
+\r
+               UUID groupId = UUID.randomUUID();\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
+               Resource resource2 = new Resource("Room101", "Class room");\r
+               Resource resource3 = new Resource("Room101", "Class room");\r
+               dh.addResource(resource1);\r
+               dh.addResource(resource2);\r
+               dh.addResource(resource3);\r
+\r
+               User testUser2 = uc.getUser("TestUser2");\r
+\r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+                               "Test reservation1");\r
+               Reservation reservation2 = new Reservation(groupId, uc.getLoggedUser(), resource2, dateRange,\r
+                               "Test reservation2");\r
+               Reservation reservation3 = new Reservation(groupId, testUser2, resource3, dateRange, "Test reservation3");\r
+               dh.addReservation(reservation1);\r
+               dh.addReservation(reservation2);\r
+               dh.addReservation(reservation3);\r
+\r
+               Map<Reservation, Boolean> loggedUserReservation = uc.getUserReservations(null);\r
+               Map<Reservation, Boolean> reservationMap = uc.getUserReservations(testUser2);\r
+               Map<Reservation, Boolean> reservationDateRangeMap = uc.getReservationsInDateRange(dateRange);\r
+               Map<Reservation, Boolean> reservationGroupMap = uc.getReservationGroup(groupId);\r
+\r
+               assertEquals(reservationDateRangeMap, reservationGroupMap);\r
+\r
+               assertTrue(loggedUserReservation.containsKey(reservation1));\r
+               assertTrue(loggedUserReservation.containsKey(reservation2));\r
+               assertFalse(loggedUserReservation.containsKey(reservation3));\r
+               assertTrue(reservationMap.containsKey(reservation3));\r
+\r
+               for (Map.Entry<Reservation, Boolean> entry : reservationDateRangeMap.entrySet()) {\r
+                       if (entry.getKey().getUser().getUserName().equals("TestUser1")) {\r
+                               assertTrue(entry.getValue());\r
+                               assertEquals(entry.getKey().getId(), uc.getReservation(entry.getKey().getId()).getId());\r
+                       } else {\r
+                               assertFalse(entry.getValue());\r
+                               assertEquals(entry.getKey().getId(), uc.getReservation(entry.getKey().getId()).getId());\r
+                       }\r
+               }\r
+               assertEquals(null, uc.getReservation(UUID.randomUUID()));\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void getReservationGroupException1Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
+               uc.getReservationGroup(null);\r
+       }\r
+\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void getReservationGroupException2Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.getReservationGroup(null);\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void getUserReservationException1Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.setDataHandler(null);\r
+               uc.getUserReservations(null);\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void getUserReservationException2Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.getUserReservations(null);\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void getReservationException1Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               uc.getReservation(null);\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void getReservationException2Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.getReservation(null);\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void getReservationsInDateRangeException1Test() throws Exception {\r
+               UserController uc = new UserController(null);\r
+               uc.getReservationsInDateRange(null);\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void getReservationsInDateRangeException2Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.getReservationsInDateRange(null);\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test\r
+       public void makeReservationTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.logIn("TestUser1", "pass1");\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
+               dh.addResource(resource1);\r
+               dh.addResource(resource2);\r
+               dh.addResource(resource3);\r
+\r
+               List<DateRange> dtList = new ArrayList<DateRange>();\r
+               for (int i = 1; i < 10; i++) {\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
+       @SuppressWarnings("deprecation")\r
+       @Test\r
+       public void makeInvalidReservationTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.logIn("TestUser1", "pass1");\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
+               dh.addResource(resource1);\r
+               dh.addResource(resource2);\r
+               dh.addResource(resource3);\r
+\r
+               List<DateRange> dtList = new ArrayList<DateRange>();\r
+               for (int i = 1; i < 10; i++) {\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
+               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
+               // 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
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void makeReservationException1Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.logIn("TestUser1", "pass1");\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
+               dh.addResource(resource1);\r
+               dh.addResource(resource2);\r
+               dh.addResource(resource3);\r
+\r
+               List<DateRange> dtList = new ArrayList<DateRange>();\r
+               for (int i = 1; i < 10; i++) {\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
+               assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void makeReservationException2Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.logIn("TestUser1", "pass1");\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
+               dh.addResource(resource1);\r
+               dh.addResource(resource2);\r
+               dh.addResource(resource3);\r
+\r
+               List<DateRange> dtList = new ArrayList<DateRange>();\r
+               for (int i = 1; i < 10; i++) {\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
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void makeReservationException3Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.logIn("TestUser1", "pass1");\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
+               dh.addResource(resource1);\r
+               dh.addResource(resource2);\r
+               dh.addResource(resource3);\r
+\r
+               List<DateRange> dtList = new ArrayList<DateRange>();\r
+               for (int i = 1; i < 10; i++) {\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
+       }\r
+\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void makeReservationException4Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.logIn("TestUser1", "pass1");\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
+               dh.addResource(resource1);\r
+               dh.addResource(resource2);\r
+               dh.addResource(resource3);\r
+\r
+               List<DateRange> dtList = new ArrayList<DateRange>();\r
+\r
+               assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test\r
+       public void changeReservationTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               uc.logIn("TestUser1", "pass1");\r
+\r
+               UUID groupId = UUID.randomUUID();\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
+\r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+                               "Test reservation1");\r
+               dh.addReservation(reservation1);\r
+\r
+               Reservation reservationClone = uc.getReservation(reservation1.getId());\r
+               DateRange newDateRange = new DateRangeImpl(new Date(2015, 12, 7, 20, 00, 00),\r
+                               new Date(2015, 12, 8, 02, 00, 00));\r
+               reservationClone.setDateRange(newDateRange);\r
+               uc.changeReservation(reservationClone);\r
+\r
+               assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void changeReservationException1Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               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
+\r
+               Resource resource1 = new Resource("Room101", "Class room");\r
+               dh.addResource(resource1);\r
+\r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+                               "Test reservation1");\r
+               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
+               reservationClone.setDateRange(newDateRange);\r
+\r
+               uc.setDataHandler(null);\r
+               uc.changeReservation(reservationClone);\r
+\r
+               assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void changeReservationException2Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               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
+\r
+               Resource resource1 = new Resource("Room101", "Class room");\r
+               dh.addResource(resource1);\r
+\r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+                               "Test reservation1");\r
+               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
+               reservationClone.setDateRange(newDateRange);\r
+\r
+               uc.logOut();\r
+               uc.changeReservation(reservationClone);\r
+\r
+               assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void changeReservationException3Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               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
+\r
+               Resource resource1 = new Resource("Room101", "Class room");\r
+               dh.addResource(resource1);\r
+\r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+                               "Test reservation1");\r
+               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
+               reservationClone.setDateRange(newDateRange);\r
+\r
+               uc.changeReservation(null);\r
+\r
+               assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void changeReservationException4Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               \r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               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
+\r
+               Resource resource1 = new Resource("Room101", "Class room");\r
+               dh.addResource(resource1);\r
+\r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+                               "Test reservation1");\r
+               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
+               reservationClone.setDateRange(newDateRange);\r
+\r
                uc.logOut();\r
+               uc.logIn("TestUser2", "pass2");\r
+               uc.changeReservation(reservationClone);\r
+\r
+               assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
        }\r
-       \r
-       @Test(expected=Exception.class)\r
-       public void logOutException2Test() throws Exception{\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test\r
+       public void deleteReservationTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               \r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               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
+\r
+               Resource resource1 = new Resource("Room101", "Class room");\r
+               dh.addResource(resource1);\r
+\r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+                               "Test reservation1");\r
+               dh.addReservation(reservation1);\r
+\r
+               uc.deleteReservation(reservation1);\r
+\r
+               assertEquals(null, uc.getReservation(reservation1.getId()));\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void deleteReservationException1Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               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
+\r
+               Resource resource1 = new Resource("Room101", "Class room");\r
+               dh.addResource(resource1);\r
+\r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+                               "Test reservation1");\r
+               dh.addReservation(reservation1);\r
+\r
+               uc.setDataHandler(null);\r
+               uc.deleteReservation(reservation1);\r
+\r
+               assertEquals(null, uc.getReservation(reservation1.getId()));\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void deleteReservationException2Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               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
+\r
+               Resource resource1 = new Resource("Room101", "Class room");\r
+               dh.addResource(resource1);\r
+\r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+                               "Test reservation1");\r
+               dh.addReservation(reservation1);\r
+\r
                uc.logOut();\r
+               uc.deleteReservation(reservation1);\r
+\r
+               assertEquals(null, uc.getReservation(reservation1.getId()));\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void deleteReservationException3Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               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
+\r
+               Resource resource1 = new Resource("Room101", "Class room");\r
+               dh.addResource(resource1);\r
+\r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+                               "Test reservation1");\r
+               dh.addReservation(reservation1);\r
+\r
+               uc.deleteReservation(null);\r
+\r
+               assertEquals(null, uc.getReservation(reservation1.getId()));\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void deleteReservationException4Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               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
+\r
+               Resource resource1 = new Resource("Room101", "Class room");\r
+               dh.addResource(resource1);\r
+\r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+                               "Test reservation1");\r
+               dh.addReservation(reservation1);\r
+\r
+               uc.logOut();\r
+               uc.logIn("TestUser2", "pass2");\r
+               uc.deleteReservation(reservation1);\r
+\r
+               assertEquals(null, uc.getReservation(reservation1.getId()));\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test\r
+       public void getResourcesTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               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
+               dh.addResource(resource1);\r
+               dh.addResource(resource2);\r
+               dh.addResource(resource3);\r
+\r
+               List<Resource> resList = uc.getResources();\r
+\r
+               assertEquals(3, resList.size());\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void getResourcesExceptionTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController(dh);\r
+               //uc.setDataHandler(dh);\r
+               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               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
+               dh.addResource(resource1);\r
+               dh.addResource(resource2);\r
+               dh.addResource(resource3);\r
+\r
+               uc.setDataHandler(null);\r
+               List<Resource> resList = uc.getResources();\r
+\r
+               assertEquals(3, resList.size());\r
        }\r
 }\r