Updated Tests
authorMichael <Michael@Michael-LT.fritz.box>
Sat, 9 Jan 2016 17:05:16 +0000 (18:05 +0100)
committerMichael <Michael@Michael-LT.fritz.box>
Sat, 9 Jan 2016 17:05:16 +0000 (18:05 +0100)
src/main/java/ch/bfh/ti/srs/controller/SessionController.java
src/main/java/ch/bfh/ti/srs/controller/UserController.java
src/test/java/ch/bfh/ti/srs/controller/SessionControllerTest.java
src/test/java/ch/bfh/ti/srs/controller/UserControllerTest.java

index 9e5e4b9..91eb7e0 100644 (file)
@@ -43,12 +43,12 @@ public class SessionController {
         *             no <code>DataHandler</code> set\r
         */\r
        public Set<Controller> logIn(String userName, String password) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
                if (currentUser != null)\r
                        throw new Exception("A user is already logged in");\r
                User tempUser = dh.findUser(userName);\r
-               if (tempUser != null || tempUser.checkPassword(password)){\r
+               if (tempUser == null || !tempUser.checkPassword(password))\r
+                       throw new Exception("Username or password wrong");\r
+               else{\r
                        currentUser = tempUser;\r
                        controllers.clear();\r
                        \r
@@ -58,14 +58,11 @@ public class SessionController {
                                                controllers.add(new UserController(dh, this));\r
                                        case ResourceManager:\r
                                                controllers.add(new ResourceManagerController(dh, this));\r
-                                       case Admin:\r
-                                               //Add AdminController to controllers\r
+//                                     case Admin:\r
+//                                             //Add AdminController to controllers\r
                                }\r
                        }\r
                }\r
-               else{\r
-                       throw new Exception("Username or password wrong");\r
-               }\r
                return controllers;\r
        }\r
 \r
@@ -154,4 +151,13 @@ public class SessionController {
                return currentUser;\r
        }\r
 \r
+       public void registUser(String userName, String password, String email, String name, String lastname) throws Exception {\r
+               if (dh == null)\r
+                       throw new Exception("No DataHandler set");\r
+               User newUser = new User(userName, password);\r
+               newUser.setMail(email);\r
+               newUser.setName(name);\r
+               newUser.setLastname(lastname);\r
+               dh.addUser(newUser);\r
+       }\r
 }\r
index 65d8820..6166e91 100644 (file)
@@ -52,7 +52,7 @@ public class UserController extends Controller{
         */\r
        public Map<Reservation, Boolean> getUserReservations(User user) throws Exception {\r
                if (user == null) {\r
-                       if (sc.getLoggedUser().getUserName() == null)\r
+                       if (sc.getLoggedUser() == null)\r
                                throw new Exception("user must be defined, if no user is logged in");\r
                        else\r
                                user = sc.getLoggedUser();\r
@@ -74,12 +74,14 @@ public class UserController extends Controller{
         *             not authorized\r
         */\r
        public boolean changeReservation(Reservation reservation) throws Exception {\r
-               if (sc.getLoggedUser().getUserName() == null)\r
+               if (sc.getLoggedUser() == null)\r
                        throw new Exception("No user is logged in");\r
                if (reservation == null)\r
                        throw new IllegalArgumentException("Reservation must be defined");\r
-               if (!reservation.getUser().equals(super.sc.getLoggedUser().getUserName()))\r
+               if (!reservation.getUser().getUserName().equals(super.sc.getLoggedUser().getUserName())){\r
                        throw new Exception("You are not authorized to make this change");\r
+               }\r
+                       \r
                return super.changeReservation_Super(reservation);\r
        }\r
 \r
@@ -97,7 +99,7 @@ public class UserController extends Controller{
         *             is logged in or logged <code>User</code> is not authorized\r
         */\r
        public boolean deleteReservation(Reservation reservation) throws Exception {\r
-               if (sc.getLoggedUser().getUserName() == null)\r
+               if (sc.getLoggedUser() == null)\r
                        throw new Exception("No user is logged in");\r
                if (reservation == null)\r
                        throw new IllegalArgumentException("Reservation must be defined");\r
@@ -110,7 +112,11 @@ public class UserController extends Controller{
         * {@inheritDoc}\r
         */\r
        public Set<Reservation> makeReservation(User user, Resource resource, List<DateRange> dateRangeList, String remark) throws Exception {\r
-               if (user == null) user = sc.getLoggedUser();\r
+               if (user == null){\r
+                       if (sc.getLoggedUser() == null)\r
+                               throw new IllegalArgumentException("User must be defined if no user is logged in");\r
+                       user = sc.getLoggedUser();\r
+               }\r
                if (!user.equals(sc.getLoggedUser())) throw new Exception("You are not authorized to make this reservation");\r
                return super.makeReservation(user, resource, dateRangeList, remark);\r
        }\r
index dcca926..682a5ab 100644 (file)
@@ -27,16 +27,12 @@ public class SessionControllerTest {
        public void logInTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
                SessionController sc = new SessionController(dh);\r
-               UserController uc = new UserController(dh,sc);\r
+               SessionController sc2 = new SessionController(); //dummy, just to trigger this constructor..\r
 \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
-               User user3 = uc.getUser("TestUser3");\r
-               user3.addRole(Role.User);\r
-               user3.addRole(Role.ResourceManager);\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
                Set<Controller> controllers = sc.logIn("TestUser3", "pass3");\r
                assertFalse(controllers.isEmpty());\r
@@ -46,10 +42,9 @@ public class SessionControllerTest {
        public void logInException1Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
                SessionController sc = new SessionController(dh);\r
-               UserController uc = new UserController(dh,sc);\r
 \r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
 \r
                sc.logIn("TestUser1", "pass1");\r
                sc.logIn("TestUser2", "pass2");\r
@@ -59,10 +54,9 @@ public class SessionControllerTest {
        public void logInInvalidCredetialsTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
                SessionController sc = new SessionController(dh);\r
-               UserController uc = new UserController(dh,sc);\r
 \r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
 \r
                sc.logIn("TestUser3", "pass3");\r
        }\r
@@ -72,13 +66,12 @@ public class SessionControllerTest {
        public void getLoggedUserNameTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
                SessionController sc = new SessionController(dh);\r
-               UserController uc = new UserController(dh,sc);\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
                sc.logIn("TestUser1", "pass1");\r
                assertEquals("TestUser1", sc.getLoggedUserName());\r
@@ -98,12 +91,11 @@ public class SessionControllerTest {
        public void getLoggedUserMailTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
                SessionController sc = new SessionController(dh);\r
-               UserController uc = new UserController(dh,sc);\r
 \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
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser2", "pass2", "hanfli@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
                sc.logIn("TestUser2", "pass2");\r
                assertEquals("hanfli@bfh.ch", sc.getLoggedMail());\r
@@ -123,13 +115,12 @@ public class SessionControllerTest {
        public void getLoggedNameTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
                SessionController sc = new SessionController(dh);\r
-               UserController uc = new UserController(dh,sc);\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
+               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", "Hanfli", null);\r
+               sc.registUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
 \r
                sc.logIn("TestUser3", "pass3");\r
                assertEquals("Hanfli", sc.getLoggedName());\r
@@ -149,13 +140,12 @@ public class SessionControllerTest {
        public void getLoggedLastnameTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
                SessionController sc = new SessionController(dh);\r
-               UserController uc = new UserController(dh,sc);\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
                sc.logIn("TestUser4", "pass4");\r
                assertEquals("User", sc.getLoggedLastname());\r
@@ -174,9 +164,8 @@ public class SessionControllerTest {
        public void getLoggedUserTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
                SessionController sc = new SessionController(dh);\r
-               UserController uc = new UserController(dh,sc);\r
 \r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
                assertEquals(null, sc.getLoggedUser());\r
                sc.logIn("TestUser1", "pass1");\r
                assertEquals("TestUser1", sc.getLoggedUser().getUserName());\r
@@ -187,13 +176,12 @@ public class SessionControllerTest {
        public void logOutTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
                SessionController sc = new SessionController(dh);\r
-               UserController uc = new UserController(dh,sc);\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
                sc.logIn("TestUser1", "pass1");\r
                assertEquals("TestUser1", sc.getLoggedUserName());\r
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