Updated Tests
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / controller / UserControllerTest.java
index 46831ed..d113635 100644 (file)
@@ -15,6 +15,7 @@ import java.util.ArrayList;
 import java.util.Date;\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.Test;\r
@@ -34,52 +35,57 @@ public class UserControllerTest {
        @Test\r
        public void addUserTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               SessionController sc = new SessionController();\r
-               UserController uc = new UserController(dh,sc);\r
+               SessionController sc = new SessionController(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
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
+               sc.registUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
        }\r
 \r
        @Test(expected = Exception.class)\r
        public void addUserExceptionTest() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               SessionController sc = new SessionController();\r
-               UserController uc = new UserController(dh,sc);\r
-               uc.setDataHandler(null);\r
+               SessionController sc = new SessionController(null);\r
 \r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+\r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\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(dh);\r
-               uc.setDataHandler(null);\r
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = new UserController(null,sc);\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(expected = Exception.class)\r
        public void getUserExpectionTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController(dh);\r
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+                               \r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
+               \r
                uc.setDataHandler(null);\r
                uc.getUser(null);\r
        }\r
@@ -88,12 +94,17 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\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
@@ -108,9 +119,9 @@ public class UserControllerTest {
 \r
                User testUser2 = uc.getUser("TestUser2");\r
 \r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
-               Reservation reservation2 = new Reservation(groupId, uc.getLoggedUser(), resource2, dateRange,\r
+               Reservation reservation2 = new Reservation(groupId, sc.getLoggedUser(), resource2, dateRange,\r
                                "Test reservation2");\r
                Reservation reservation3 = new Reservation(groupId, testUser2, resource3, dateRange, "Test reservation3");\r
                dh.addReservation(reservation1);\r
@@ -123,7 +134,7 @@ public class UserControllerTest {
                Map<Reservation, Boolean> reservationGroupMap = uc.getReservationGroup(groupId);\r
 \r
                assertEquals(reservationDateRangeMap, reservationGroupMap);\r
-\r
+               \r
                assertTrue(loggedUserReservation.containsKey(reservation1));\r
                assertTrue(loggedUserReservation.containsKey(reservation2));\r
                assertFalse(loggedUserReservation.containsKey(reservation3));\r
@@ -144,7 +155,9 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void getReservationGroupException1Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController(dh);\r
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = new UserController(dh,sc);\r
+               \r
                uc.setDataHandler(null);\r
                uc.getReservationGroup(null);\r
        }\r
@@ -152,15 +165,18 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = new UserController(dh,sc);\r
+               \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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = new UserController(dh,sc);\r
+               \r
                uc.setDataHandler(null);\r
                uc.getUserReservations(null);\r
        }\r
@@ -168,37 +184,45 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = new UserController(dh,sc);\r
+               \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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = new UserController(dh,sc);\r
+               \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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = new UserController(dh,sc);\r
+               \r
                uc.getReservation(null);\r
        }\r
 \r
        @Test(expected = Exception.class)\r
        public void getReservationsInDateRangeException1Test() throws Exception {\r
-               UserController uc = new UserController(null);\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = new UserController(dh,sc);\r
+               \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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = new UserController(dh,sc);\r
+               \r
                uc.getReservationsInDateRange(null);\r
        }\r
 \r
@@ -206,11 +230,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                Resource resource2 = new Resource("Room101", "Class room");\r
@@ -224,7 +253,7 @@ public class UserControllerTest {
                        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(sc.getLoggedUser(), resource1, dtList, "remark"));\r
                assertEquals(null, uc.makeReservation(null, resource2, dtList, "remark"));\r
        }\r
 \r
@@ -232,11 +261,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                Resource resource2 = new Resource("Room101", "Class room");\r
@@ -261,19 +295,24 @@ public class UserControllerTest {
                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
+               assertEquals(null, uc.makeReservation(sc.getLoggedUser(), resource1, dtList, "remark"));\r
+               assertEquals(4, uc.makeReservation(sc.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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                Resource resource2 = new Resource("Room101", "Class room");\r
@@ -287,7 +326,7 @@ public class UserControllerTest {
                        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
+               sc.logOut();\r
                assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
        }\r
 \r
@@ -295,11 +334,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                Resource resource2 = new Resource("Room101", "Class room");\r
@@ -317,14 +361,19 @@ public class UserControllerTest {
        }\r
 \r
        @SuppressWarnings("deprecation")\r
-       @Test(expected = IllegalArgumentException.class)\r
+       @Test(expected = Exception.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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                Resource resource2 = new Resource("Room101", "Class room");\r
@@ -338,17 +387,22 @@ public class UserControllerTest {
                        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
+               assertEquals(null, uc.makeReservation(uc.getUser("TestUser2"), 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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                Resource resource1 = new Resource("Room101", "Class room");\r
                Resource resource2 = new Resource("Room101", "Class room");\r
@@ -366,11 +420,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\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
@@ -378,7 +437,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -395,11 +454,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                UUID groupId = UUID.randomUUID();\r
                Date start = new Date();\r
@@ -411,7 +475,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -431,11 +495,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                UUID groupId = UUID.randomUUID();\r
                Date start = new Date();\r
@@ -447,7 +516,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -457,7 +526,7 @@ public class UserControllerTest {
                DateRange newDateRange = new DateRangeImpl(start, finish);\r
                reservationClone.setDateRange(newDateRange);\r
 \r
-               uc.logOut();\r
+               sc.logOut();\r
                uc.changeReservation(reservationClone);\r
 \r
                assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
@@ -467,11 +536,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                UUID groupId = UUID.randomUUID();\r
                Date start = new Date();\r
@@ -483,7 +557,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -502,11 +576,16 @@ public class UserControllerTest {
        @Test(expected = Exception.class)\r
        public void changeReservationException4Test() 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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                UUID groupId = UUID.randomUUID();\r
                Date start = new Date();\r
@@ -518,7 +597,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -528,8 +607,8 @@ public class UserControllerTest {
                DateRange newDateRange = new DateRangeImpl(start, finish);\r
                reservationClone.setDateRange(newDateRange);\r
 \r
-               uc.logOut();\r
-               uc.logIn("TestUser2", "pass2");\r
+               sc.logOut();\r
+               sc.logIn("TestUser2", "pass2");\r
                uc.changeReservation(reservationClone);\r
 \r
                assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
@@ -539,11 +618,16 @@ public class UserControllerTest {
        @Test\r
        public void deleteReservationTest() 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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                UUID groupId = UUID.randomUUID();\r
                Date start = new Date();\r
@@ -555,7 +639,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -568,11 +652,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                UUID groupId = UUID.randomUUID();\r
                Date start = new Date();\r
@@ -584,7 +673,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -598,11 +687,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                UUID groupId = UUID.randomUUID();\r
                Date start = new Date();\r
@@ -614,11 +708,11 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
-               uc.logOut();\r
+               sc.logOut();\r
                uc.deleteReservation(reservation1);\r
 \r
                assertEquals(null, uc.getReservation(reservation1.getId()));\r
@@ -628,11 +722,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                UUID groupId = UUID.randomUUID();\r
                Date start = new Date();\r
@@ -644,7 +743,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -657,11 +756,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                UUID groupId = UUID.randomUUID();\r
                Date start = new Date();\r
@@ -673,12 +777,12 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
-               uc.logOut();\r
-               uc.logIn("TestUser2", "pass2");\r
+               sc.logOut();\r
+               sc.logIn("TestUser2", "pass2");\r
                uc.deleteReservation(reservation1);\r
 \r
                assertEquals(null, uc.getReservation(reservation1.getId()));\r
@@ -688,11 +792,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                Date start = new Date();\r
                start.setTime((System.currentTimeMillis() % 1000));\r
@@ -715,11 +824,16 @@ public class UserControllerTest {
        @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
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
+               \r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               Set<Controller> controllers = sc.logIn("TestUser1", "pass1");\r
+               for (Controller controller : controllers) {\r
+                       if(controller.getClass().equals(UserController.class))\r
+                               uc = (UserController)controller;\r
+               }\r
 \r
                Date start = new Date();\r
                start.setTime((System.currentTimeMillis() % 1000));\r