UserControllerTest updated
authorMichael <Michael@Michael-LT.fritz.box>
Fri, 27 Nov 2015 11:41:39 +0000 (12:41 +0100)
committerMichael <Michael@Michael-LT.fritz.box>
Fri, 27 Nov 2015 11:41:39 +0000 (12:41 +0100)
src/main/java/ch/bfh/ti/srs/controller/UserController.java
src/test/java/ch/bfh/ti/srs/controller/UserControllerTest.java

index 7073c7e..49dbbd1 100644 (file)
@@ -182,7 +182,7 @@ public class UserController {
                // and easier code maintenance\r
                Map<Reservation, Boolean> returnSet = new HashMap<Reservation, Boolean>();\r
                for (Reservation reservation : dh.overlaps(dateRange)) {\r
-                       returnSet.put(reservation, reservation.getUser().equals(currentUser));\r
+                       returnSet.put(reservation, reservation.getUser().getUserName().equals(currentUser.getUserName()));\r
                }\r
                return returnSet;\r
        }\r
@@ -220,7 +220,7 @@ public class UserController {
                // and easier code maintenance\r
                Map<Reservation, Boolean> returnSet = new HashMap<Reservation, Boolean>();\r
                for (Reservation reservation : dh.userReservations(user)) {\r
-                       returnSet.put(reservation, reservation.getUser().equals(currentUser));\r
+                       returnSet.put(reservation, reservation.getUser().getUserName().equals(currentUser.getUserName()));\r
                }\r
                return returnSet;\r
        }\r
@@ -242,7 +242,7 @@ public class UserController {
                // and easier code maintenance\r
                Map<Reservation, Boolean> returnSet = new HashMap<Reservation, Boolean>();\r
                for (Reservation reservation : dh.findGroupReservations(groupId)) {\r
-                       returnSet.put(reservation, reservation.getUser().equals(currentUser));\r
+                       returnSet.put(reservation, reservation.getUser().getUserName().equals(currentUser.getUserName()));\r
                }\r
                return returnSet;\r
        }\r
@@ -250,7 +250,7 @@ public class UserController {
        /**\r
         * Makes a reservation in the current set DataHandler\r
         * \r
-        * @param user                                                  user owning the reservation\r
+        * @param user                                                  user owning the reservation, if null currentUser is set\r
         * @param resource                                              resource to reserve\r
         * @param dateRangeList                                 <code>List</code> of DateRanges defining when the resource is occupied\r
         * @param remark                                                public remark for the reservation\r
@@ -260,7 +260,10 @@ public class UserController {
         */\r
        public Set<Reservation> makeReservation(User user, Resource resource, List<DateRange> dateRangeList, String remark) throws Exception\r
        {\r
-               if(user == null) user = currentUser;\r
+               if(user == null){\r
+                       if(currentUser == null) throw new IllegalArgumentException("User must be defined if no user is logged in");\r
+                       user = currentUser;\r
+               }\r
                if(resource == null) throw new IllegalArgumentException("Resource must be definded");\r
                if(dateRangeList == null) throw new IllegalArgumentException("dateRangeList can not be null");\r
                if(dateRangeList.isEmpty()) throw new IllegalArgumentException("dateRangeList empty");\r
index 016ae1b..427bc2d 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
@@ -176,6 +191,49 @@ public class UserControllerTest {
        }\r
        \r
        @Test\r
+       public void getLoggedUserTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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();\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();\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
+       @Test(expected=Exception.class)\r
+       public void getUserExceptionTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+       @Test\r
        public void logOutTest() throws Exception{\r
                DataHandler dh = new DataHandlerForTests();\r
                UserController uc = new UserController();\r
@@ -207,4 +265,717 @@ public class UserControllerTest {
                uc.setDataHandler(dh);\r
                uc.logOut();\r
        }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void getUserExpectionTest() throws Exception{\r
+               UserController uc = new UserController();\r
+               uc.getUser(null);\r
+       }\r
+       \r
+       @Test\r
+       public void getReservationTests() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+               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 loggedUser = uc.getLoggedUser();\r
+               User testUser2 = uc.getUser("TestUser2");\r
+               \r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
+               Reservation reservation2 = new Reservation(groupId, uc.getLoggedUser(), resource2, dateRange, "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
+                       }\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
+               UserController uc = new UserController();\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();\r
+               uc.setDataHandler(dh);\r
+               uc.getReservationGroup(null);\r
+       }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void getUserReservationException1Test() throws Exception{\r
+               UserController uc = new UserController();\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();\r
+               uc.setDataHandler(dh);\r
+               uc.getUserReservations(null);\r
+       }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void getReservationException1Test() throws Exception{\r
+               UserController uc = new UserController();\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();\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();\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();\r
+               uc.setDataHandler(dh);\r
+               uc.getReservationsInDateRange(null);\r
+       }\r
+       \r
+       @Ignore("disabled until implementation is finished")\r
+       //@Test\r
+       public void makeReservationTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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<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
+               }\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
+       public void makeInvalidReservationTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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<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
+               }\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
+               \r
+//             assertEquals(null, uc.makeReservation(uc.getLoggedUser(), resource1, dtList, "remark"));                \r
+//             assertEquals(9, uc.makeReservation(uc.getLoggedUser(), resource1, dtList, null).size());\r
+       }\r
+\r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void makeReservationException1Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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<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
+               }\r
+               \r
+               uc.logOut();\r
+               assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
+       }\r
+\r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void makeReservationException2Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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<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
+               }\r
+               \r
+               assertEquals(null, uc.makeReservation(null, null, dtList, "remark"));\r
+       }\r
+\r
+       @Test(expected=IllegalArgumentException.class)\r
+       public void makeReservationException3Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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<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
+               }\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();\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<DateRange> dtList = new ArrayList<DateRange>();\r
+               \r
+               assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
+       }\r
+       \r
+       @Test\r
+       public void changeReservationTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+               User loggedUser = uc.getLoggedUser();\r
+               User testUser2 = uc.getUser("TestUser2");\r
+               \r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "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
+               uc.changeReservation(reservationClone);\r
+               \r
+               assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
+       }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void changeReservationException1Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+               User loggedUser = uc.getLoggedUser();\r
+               User testUser2 = uc.getUser("TestUser2");\r
+               \r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "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
+       @Test(expected=Exception.class)\r
+       public void changeReservationException2Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+               User loggedUser = uc.getLoggedUser();\r
+               User testUser2 = uc.getUser("TestUser2");\r
+               \r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "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
+       @Test(expected=IllegalArgumentException.class)\r
+       public void changeReservationException3Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+               User loggedUser = uc.getLoggedUser();\r
+               User testUser2 = uc.getUser("TestUser2");\r
+               \r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "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
+       @Test(expected=Exception.class)\r
+       public void changeReservationException4Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+               User loggedUser = uc.getLoggedUser();\r
+               User testUser2 = uc.getUser("TestUser2");\r
+               \r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "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\r
+       public void deleteReservationTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+               User loggedUser = uc.getLoggedUser();\r
+               User testUser2 = uc.getUser("TestUser2");\r
+               \r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
+               dh.addReservation(reservation1);\r
+               \r
+               uc.deleteReservation(reservation1);\r
+               \r
+               assertEquals(null, uc.getReservation(reservation1.getId()));\r
+       }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void deleteReservationException1Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+               User loggedUser = uc.getLoggedUser();\r
+               User testUser2 = uc.getUser("TestUser2");\r
+               \r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "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
+       @Test(expected=Exception.class)\r
+       public void deleteReservationException2Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+               User loggedUser = uc.getLoggedUser();\r
+               User testUser2 = uc.getUser("TestUser2");\r
+               \r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "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
+       @Test(expected=IllegalArgumentException.class)\r
+       public void deleteReservationException3Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+               User loggedUser = uc.getLoggedUser();\r
+               User testUser2 = uc.getUser("TestUser2");\r
+               \r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "Test reservation1");\r
+               dh.addReservation(reservation1);\r
+               \r
+               uc.deleteReservation(null);\r
+               \r
+               assertEquals(null, uc.getReservation(reservation1.getId()));\r
+       }\r
+       \r
+       @Test(expected=Exception.class)\r
+       public void deleteReservationException4Test() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+               User loggedUser = uc.getLoggedUser();\r
+               User testUser2 = uc.getUser("TestUser2");\r
+               \r
+               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange, "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
+       @Test\r
+       public void getResourcesTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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
+       @Test(expected=Exception.class)\r
+       public void getResourcesExceptionTest() throws Exception{\r
+               DataHandler dh = new DataHandlerForTests();\r
+               UserController uc = new UserController();\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