Merge remote-tracking branch 'origin/development' master del4
authorDominik <muggd1@bfh.ch>
Sun, 10 Jan 2016 13:53:17 +0000 (14:53 +0100)
committerDominik <muggd1@bfh.ch>
Sun, 10 Jan 2016 13:53:17 +0000 (14:53 +0100)
Conflicts:
.gitignore
pom.xml
src/site/apt/sprint_backlog.apt

32 files changed:
.classpath
.settings/org.eclipse.core.resources.prefs [new file with mode: 0644]
.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
pom.xml
src/main/java/ch/bfh/ti/srs/controller/Controller.java [copied from src/main/java/ch/bfh/ti/srs/controller/UserController.java with 58% similarity]
src/main/java/ch/bfh/ti/srs/controller/ResourceManagerController.java [new file with mode: 0644]
src/main/java/ch/bfh/ti/srs/controller/SessionController.java [new file with mode: 0644]
src/main/java/ch/bfh/ti/srs/controller/UserController.java
src/main/java/ch/bfh/ti/srs/datahandler/DataHandler.java
src/main/java/ch/bfh/ti/srs/datahandler/DataHandlerForTests.java
src/main/java/ch/bfh/ti/srs/dataschema/Modifiable.java [new file with mode: 0644]
src/main/java/ch/bfh/ti/srs/dataschema/Reservation.java
src/main/java/ch/bfh/ti/srs/dataschema/Resource.java
src/main/java/ch/bfh/ti/srs/dataschema/Role.java [copied from src/main/java/ch/bfh/ti/srs/dataschema/package-info.java with 76% similarity]
src/main/java/ch/bfh/ti/srs/dataschema/User.java
src/main/java/ch/bfh/ti/srs/noTest/DataHandlerForExcel.java
src/site/apt/package_design.apt [new file with mode: 0644]
src/site/apt/package_diagram.apt
src/site/apt/sprint_backlog.apt
src/site/resources/images/AI_Graph.png [new file with mode: 0644]
src/site/resources/images/SSD.png
src/site/resources/images/context_diagram.png
src/site/resources/images/packageDiagram.png
src/site/resources/images/seq_userlogin_diagram.png
src/site/site.xml
src/test/java/ch/bfh/ti/srs/controller/ResourceManagerControllerTest.java [new file with mode: 0644]
src/test/java/ch/bfh/ti/srs/controller/SessionControllerTest.java [new file with mode: 0644]
src/test/java/ch/bfh/ti/srs/controller/UserControllerTest.java
src/test/java/ch/bfh/ti/srs/datahandler/DataHandlerForTestsTest.java
src/test/java/ch/bfh/ti/srs/dataschema/ReservationTest.java
src/test/java/ch/bfh/ti/srs/dataschema/ResourceTest.java
src/test/java/ch/bfh/ti/srs/dataschema/UserTest.java

index 61f3bb9..8433ca6 100644 (file)
@@ -1,26 +1,36 @@
-<?xml version="1.0" encoding="UTF-8"?>\r
-<classpath>\r
-       <classpathentry kind="src" output="target/classes" path="src/main/java">\r
-               <attributes>\r
-                       <attribute name="optional" value="true"/>\r
-                       <attribute name="maven.pomderived" value="true"/>\r
-               </attributes>\r
-       </classpathentry>\r
-       <classpathentry kind="src" output="target/test-classes" path="src/test/java">\r
-               <attributes>\r
-                       <attribute name="optional" value="true"/>\r
-                       <attribute name="maven.pomderived" value="true"/>\r
-               </attributes>\r
-       </classpathentry>\r
-       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">\r
-               <attributes>\r
-                       <attribute name="maven.pomderived" value="true"/>\r
-               </attributes>\r
-       </classpathentry>\r
-       <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">\r
-               <attributes>\r
-                       <attribute name="maven.pomderived" value="true"/>\r
-               </attributes>\r
-       </classpathentry>\r
-       <classpathentry kind="output" path="target/classes"/>\r
-</classpath>\r
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" output="target/classes" path="src/main/java">
+               <attributes>
+                       <attribute name="optional" value="true"/>
+                       <attribute name="maven.pomderived" value="true"/>
+               </attributes>
+       </classpathentry>
+       <classpathentry kind="src" output="target/test-classes" path="src/test/java">
+               <attributes>
+                       <attribute name="optional" value="true"/>
+                       <attribute name="maven.pomderived" value="true"/>
+               </attributes>
+       </classpathentry>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+               <attributes>
+                       <attribute name="maven.pomderived" value="true"/>
+               </attributes>
+       </classpathentry>
+       <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+               <attributes>
+                       <attribute name="maven.pomderived" value="true"/>
+               </attributes>
+       </classpathentry>
+       <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
+               <attributes>
+                       <attribute name="maven.pomderived" value="true"/>
+               </attributes>
+       </classpathentry>
+       <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
+               <attributes>
+                       <attribute name="maven.pomderived" value="true"/>
+               </attributes>
+       </classpathentry>
+       <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644 (file)
index 0000000..4c28b1a
--- /dev/null
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1\r
+encoding//src/main/java=UTF-8\r
+encoding//src/test/java=UTF-8\r
+encoding/<project>=UTF-8\r
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..d59e09c
--- /dev/null
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8\r
+org.eclipse.jdt.core.compiler.compliance=1.8\r
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning\r
+org.eclipse.jdt.core.compiler.source=1.8\r
diff --git a/pom.xml b/pom.xml
index 5c091ef..d07cddd 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
        <modelVersion>4.0.0</modelVersion>\r
        <groupId>srs-purple</groupId>\r
        <artifactId>srs-purple-main</artifactId>\r
-       <version>1.1</version>\r
+       <version>1.4</version>\r
        <name>Smart Reservation System</name>\r
        <description>Some description ...</description>\r
        <organization>\r
@@ -23,65 +23,33 @@ import ch.bfh.ti.srs.dataschema.Resource;
 import ch.bfh.ti.srs.dataschema.User;\r
 \r
 /**\r
- * @author Michael Grossen\r
+ * @author Michael\r
  */\r
-public class UserController {\r
-       private User currentUser;\r
-       private DataHandler dh;\r
-\r
-       public UserController() {\r
-       }\r
+public abstract class Controller {\r
+       protected DataHandler dh;\r
+       protected SessionController sc;\r
 \r
        /**\r
         * Sets the <code>DataHandler</code> implementation for this Controller,\r
         * must be set before using all other methods!\r
         * @param dh\r
         *            DataHandler implementation (i.e. DataHandlerForExcel)\r
+        * @param sc\r
+        *            SessionController which is responsable for the login\r
         */\r
-       public void setDataHandler(DataHandler dh) {\r
+       public Controller(DataHandler dh, SessionController sc) {\r
                this.dh = dh;\r
+               this.sc = sc;\r
        }\r
 \r
        /**\r
-        * Tries to log in a <code>User</code> with the given credentials\r
-        * @param userName\r
-        *            user name\r
-        * @param password\r
-        *            the stored password for the given user name\r
-        * @return <code>True</code> if the user could log in successfully,\r
-        *         <code>False</code> either the username or the password was not\r
-        *         correct.\r
-        * @throws Exception\r
-        *             no <code>DataHandler</code> set\r
-        * @throws AlreadyBoundException\r
-        *             a <code>User</code> is already logged in\r
-        */\r
-       public boolean 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 AlreadyBoundException("A user is already logged in");\r
-               User tempUser = dh.findUser(userName);\r
-               if (tempUser == null || !tempUser.checkPassword(password))\r
-                       return false;\r
-               else {\r
-                       currentUser = tempUser;\r
-                       return true;\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Logs out the current logged user\r
-        * @throws Exception\r
-        *             either no <code>DataHandler</code> is set or no user is\r
-        *             logged in\r
+        * Sets the <code>DataHandler</code> implementation for this Controller,\r
+        * must be set before using all other methods!\r
+        * @param dh\r
+        *            DataHandler implementation (i.e. DataHandlerForExcel)\r
         */\r
-       public void logOut() throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               currentUser = null;\r
+       public void setDataHandler(DataHandler dh) {\r
+               this.dh = dh;\r
        }\r
 \r
        /**\r
@@ -110,84 +78,19 @@ public class UserController {
        }\r
 \r
        /**\r
-        * Gets the user name of the current user\r
-        * @deprecated use <code>getLoggedUser().getUserName()</code>\r
-        * @return user name\r
+        * Returns all stored resources of the set DataHandler\r
+        * @return <code>List</code> of resources\r
         * @throws Exception\r
         *             no <code>DataHandler</code> is set\r
         */\r
-       @Deprecated\r
-       public String getLoggedUserName() throws Exception {\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               return currentUser.getUserName();\r
-       }\r
-\r
-       /**\r
-        * Gets the mail address of the current user\r
-        * @deprecated use <code>getLoggedUser().getMail()</code>\r
-        * @return Mail address\r
-        * @throws Exception\r
-        *             no user is logged in\r
-        */\r
-       @Deprecated\r
-       public String getLoggedMail() throws Exception {\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               return currentUser.getMail();\r
-       }\r
-\r
-       /**\r
-        * Gets the first name of the current user\r
-        * @deprecated use <code>getLoggedUser().getName()</code>\r
-        * @return First name\r
-        * @throws Exception\r
-        *             no user is logged in\r
-        */\r
-       @Deprecated\r
-       public String getLoggedName() throws Exception {\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               return currentUser.getName();\r
-       }\r
-\r
-       /**\r
-        * Gets the last name of the current user\r
-        * @deprecated use <code>getLoggedUser().getLastName()</code>\r
-        * @return Last name\r
-        * @throws Exception\r
-        *             no user is logged in\r
-        */\r
-       @Deprecated\r
-       public String getLoggedLastname() throws Exception {\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               return currentUser.getLastname();\r
-       }\r
-\r
-       /**\r
-        * Gets the current logged <code>User</code>\r
-        * @return current <code>User</code>, or <code>null</code> if no\r
-        *         <code>User</code> is logged in\r
-        */\r
-       public User getLoggedUser() {\r
-               if (currentUser == null)\r
-                       return null;\r
-               return currentUser;\r
-       }\r
-\r
-       /**\r
-        * Searches the set DataHandler for a specific <code>User</code>\r
-        * @param userName\r
-        *            <code>User</code>\r
-        * @return clone of <code>User</code>\r
-        * @throws Exception\r
-        *             No <code>DataHandler</code> is set\r
-        */\r
-       public User getUser(String userName) throws Exception {\r
+       public List<Resource> getResources() throws Exception {\r
                if (dh == null)\r
                        throw new Exception("No DataHandler set");\r
-               return dh.findUser(userName).clone();\r
+               List<Resource> resourceList = new ArrayList<Resource>();\r
+               for (Resource resource : dh.getAllResources()) {\r
+                       resourceList.add(resource.clone());\r
+               }\r
+               return resourceList;\r
        }\r
 \r
        /**\r
@@ -201,42 +104,24 @@ public class UserController {
         *             <code>DataHandler</code> is set\r
         */\r
        public Map<Reservation, Boolean> getReservationsInDateRange(DateRange dateRange) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
+               // Not needed at the moment since this check is already done in\r
+               // UserController\r
+               // if (dh == null)\r
+               // throw new Exception("No DataHandler set");\r
                if (dateRange == null)\r
                        throw new Exception("dateRange must be defined");\r
 \r
                // Could be swapped out to private method for better performance (just\r
-               // check currentUser once)\r
+               // check sc.getLoggedUser() once)\r
                // and easier code maintenance\r
                Map<Reservation, Boolean> returnSet = new HashMap<Reservation, Boolean>();\r
                for (Reservation reservation : dh.overlaps(dateRange)) {\r
-                       returnSet.put(reservation, reservation.getUser().getUserName().equals(currentUser.getUserName()));\r
+                       returnSet.put(reservation, reservation.getUser().getUserName().equals(sc.getLoggedUser().getUserName()));\r
                }\r
                return returnSet;\r
        }\r
 \r
        /**\r
-        * Returns the reservation or null if no reservation was found\r
-        * @param id\r
-        *            reservation identifier\r
-        * @return <code>Reservation</code> copy of reservation with given id,\r
-        *         <code>null</code> no reservation with this id found\r
-        * @throws Exception\r
-        *             No DataHandler set or id null\r
-        */\r
-       public Reservation getReservation(UUID id) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (id == null)\r
-                       throw new Exception("uuid must be defined");\r
-               if (dh.findReservation(id) == null)\r
-                       return null;\r
-               else\r
-                       return dh.findReservation(id).clone();\r
-       }\r
-\r
-       /**\r
         * Returns the reservations of the given user\r
         * @param user\r
         *            Owner, if <code>null</code> returns the reservations of the\r
@@ -246,27 +131,48 @@ public class UserController {
         *             either no <code>DataHandler</code> is set or no user is\r
         *             logged in while user param = null\r
         */\r
-       public Map<Reservation, Boolean> getUserReservations(User user) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (user == null) {\r
-                       if (currentUser == null)\r
-                               throw new Exception("user must be defined, if no user is logged in");\r
-                       else\r
-                               user = currentUser;\r
-               }\r
+       public Map<Reservation, Boolean> getUserReservations_Super(User user) throws Exception {\r
+               // Not needed at the moment since this check is already done in\r
+               // UserController\r
+               // if (dh == null)\r
+               // throw new Exception("No DataHandler set");\r
+               // if (user == null) {\r
+               // throw new Exception("user must be defined");\r
+               // }\r
 \r
                // Could be swapped out to private method for better performance (just\r
-               // check currentUser once)\r
+               // check sc.getLoggedUser() once)\r
                // and easier code maintenance\r
                Map<Reservation, Boolean> returnSet = new HashMap<Reservation, Boolean>();\r
                for (Reservation reservation : dh.userReservations(user)) {\r
-                       returnSet.put(reservation, reservation.getUser().getUserName().equals(currentUser.getUserName()));\r
+                       returnSet.put(reservation, reservation.getUser().getUserName().equals(sc.getLoggedUser().getUserName()));\r
                }\r
                return returnSet;\r
        }\r
 \r
        /**\r
+        * Returns the reservation or null if no reservation was found\r
+        * @param id\r
+        *            reservation identifier\r
+        * @return <code>Reservation</code> copy of reservation with given id,\r
+        *         <code>null</code> no reservation with this id found\r
+        * @throws Exception\r
+        *             No DataHandler set or id null\r
+        */\r
+       public Reservation getReservation(UUID id) throws Exception {\r
+               // Not needed at the moment since this check is already done in\r
+               // UserController\r
+               // if (dh == null)\r
+               // throw new Exception("No DataHandler set");\r
+               if (id == null)\r
+                       throw new Exception("uuid must be defined");\r
+               if (dh.findReservation(id) == null)\r
+                       return null;\r
+               else\r
+                       return dh.findReservation(id).clone();\r
+       }\r
+\r
+       /**\r
         * Returns <code>Map</code> of reservation group (recurring reservations)\r
         * @param groupId\r
         *            group identifier\r
@@ -283,11 +189,11 @@ public class UserController {
                        throw new IllegalArgumentException("groupId has to be defined");\r
 \r
                // Could be swapped out to private method for better performance (just\r
-               // check currentUser once)\r
+               // check sc.getLoggedUser() once)\r
                // and easier code maintenance\r
                Map<Reservation, Boolean> returnSet = new HashMap<Reservation, Boolean>();\r
                for (Reservation reservation : dh.findGroupReservations(groupId)) {\r
-                       returnSet.put(reservation, reservation.getUser().getUserName().equals(currentUser.getUserName()));\r
+                       returnSet.put(reservation, reservation.getUser().getUserName().equals(sc.getLoggedUser().getUserName()));\r
                }\r
                return returnSet;\r
        }\r
@@ -295,7 +201,7 @@ public class UserController {
        /**\r
         * Makes a reservation in the current set DataHandler\r
         * @param user\r
-        *            user owning the reservation, if null currentUser is set\r
+        *            user owning the reservation, if null sc.getLoggedUser() is set\r
         * @param resource\r
         *            resource to reserve\r
         * @param dateRangeList\r
@@ -313,11 +219,14 @@ public class UserController {
         */\r
        public Set<Reservation> makeReservation(User user, Resource resource, List<DateRange> dateRangeList, String remark)\r
                        throws Exception {\r
-               if (user == null) {\r
-                       if (currentUser == null)\r
-                               throw new IllegalArgumentException("User must be defined if no user is logged in");\r
-                       user = currentUser;\r
-               }\r
+               // Not needed at the moment since this check is already done in\r
+               // UserController\r
+               // if (user == null) {\r
+               // if (sc.getLoggedUser() == null)\r
+               // throw new IllegalArgumentException("User must be defined if no user\r
+               // is logged in");\r
+               // user = sc.getLoggedUser();\r
+               // }\r
                if (resource == null)\r
                        throw new IllegalArgumentException("Resource must be definded");\r
                if (dateRangeList == null)\r
@@ -352,15 +261,13 @@ public class UserController {
         *             if no <code>DataHandler</code> is set or the logged user is\r
         *             not authorized\r
         */\r
-       public boolean changeReservation(Reservation reservation) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (currentUser == 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(currentUser))\r
-                       throw new Exception("You are not authorized to make this change");\r
+       public boolean changeReservation_Super(Reservation reservation) throws Exception {\r
+               // Not needed at the moment since this check is already done in\r
+               // UserController\r
+               // if (dh == null)\r
+               // throw new Exception("No DataHandler set");\r
+               // if (reservation == null)\r
+               // throw new IllegalArgumentException("Reservation must be defined");\r
                return dh.editReservation(reservation);\r
        }\r
 \r
@@ -377,31 +284,13 @@ public class UserController {
         *             if no <code>DataHandler</code> is set, no <code>User</code>\r
         *             is logged in or logged <code>User</code> is not authorized\r
         */\r
-       public boolean deleteReservation(Reservation reservation) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (currentUser == 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(currentUser))\r
-                       throw new Exception("You are not authorized to make this change");\r
+       public boolean deleteReservation_Super(Reservation reservation) throws Exception {\r
+               // Not needed at the moment since this check is already done in\r
+               // UserController\r
+               // if (dh == null)\r
+               // throw new Exception("No DataHandler set");\r
+               // if (reservation == null)\r
+               // throw new IllegalArgumentException("Reservation must be defined");\r
                return dh.deleteReservation(reservation);\r
        }\r
-\r
-       /**\r
-        * Returns all stored resources of the set DataHandler\r
-        * @return <code>List</code> of resources\r
-        * @throws Exception\r
-        *             no <code>DataHandler</code> is set\r
-        */\r
-       public List<Resource> getResources() throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               List<Resource> resourceList = new ArrayList<Resource>();\r
-               for (Resource resource : dh.getAllResources()) {\r
-                       resourceList.add(resource.clone());\r
-               }\r
-               return resourceList;\r
-       }\r
 }\r
diff --git a/src/main/java/ch/bfh/ti/srs/controller/ResourceManagerController.java b/src/main/java/ch/bfh/ti/srs/controller/ResourceManagerController.java
new file mode 100644 (file)
index 0000000..0d6099d
--- /dev/null
@@ -0,0 +1,81 @@
+/*\r
+ * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
+ *\r
+ * Project Smart Reservation System.\r
+ *\r
+ * Distributable under GPL license. See terms of license at gnu.org.\r
+ */\r
+package ch.bfh.ti.srs.controller;\r
+\r
+import ch.bfh.ti.srs.datahandler.DataHandler;\r
+import ch.bfh.ti.srs.dataschema.Resource;\r
+\r
+public class ResourceManagerController extends Controller {\r
+\r
+       public ResourceManagerController(DataHandler dh, SessionController sc) {\r
+               super(dh, sc);\r
+       }\r
+\r
+       /**\r
+        * Creates new resource in the set <code>DataHandler</code>\r
+        * @param name\r
+        *            name of resource\r
+        * @param type\r
+        *            type of resource\r
+        * @return <code>True</code> Changes saved <code>False</code> Changes could\r
+        *         not be saved\r
+        * @throws IllegalArgumentException\r
+        *             if name is null\r
+        * @throws Exception\r
+        *             if no <code>DataHandler</code> is set\r
+        */\r
+       public boolean addResource(String name, String type) throws Exception {\r
+               if (dh == null)\r
+                       throw new Exception("No DataHandler set");\r
+               if (name == null)\r
+                       throw new IllegalArgumentException("Resource must be defined");\r
+\r
+               Resource resource = new Resource(name, type);\r
+               return dh.addResource(resource);\r
+       }\r
+\r
+       /**\r
+        * Replaces the given resource in the set <code>DataHandler</code> referring\r
+        * to the resource id\r
+        * @param resource\r
+        *            Copy of the resource to edit\r
+        * @return <code>True</code> Changes saved <code>False</code> Changes could\r
+        *         not be saved\r
+        * @throws IllegalArgumentException\r
+        *             if resource is null\r
+        * @throws Exception\r
+        *             if no <code>DataHandler</code> is set\r
+        */\r
+       public boolean changeResource(Resource resource) throws Exception {\r
+               if (dh == null)\r
+                       throw new Exception("No DataHandler set");\r
+               if (resource == null)\r
+                       throw new IllegalArgumentException("Resource must be defined");\r
+               return dh.editResource(resource);\r
+       }\r
+\r
+       /**\r
+        * Deletes the given resource in the set <code>DataHandler</code> referring\r
+        * to the resource id\r
+        * @param resource\r
+        *            Copy of the resource to edit\r
+        * @return <code>True</code> Changes saved <code>False</code> Changes could\r
+        *         not be saved\r
+        * @throws IllegalArgumentException\r
+        *             if resource is null\r
+        * @throws Exception\r
+        *             if no <code>DataHandler</code> is set\r
+        */\r
+       public boolean deleteResource(Resource resource) throws Exception {\r
+               if (dh == null)\r
+                       throw new Exception("No DataHandler set");\r
+               if (resource == null)\r
+                       throw new IllegalArgumentException("Resource must be defined");\r
+               return dh.deleteResource(resource);\r
+       }\r
+}\r
diff --git a/src/main/java/ch/bfh/ti/srs/controller/SessionController.java b/src/main/java/ch/bfh/ti/srs/controller/SessionController.java
new file mode 100644 (file)
index 0000000..21d8a70
--- /dev/null
@@ -0,0 +1,164 @@
+/*\r
+ * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
+ *\r
+ * Project Smart Reservation System.\r
+ *\r
+ * Distributable under GPL license. See terms of license at gnu.org.\r
+ */\r
+package ch.bfh.ti.srs.controller;\r
+\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import ch.bfh.ti.srs.datahandler.DataHandler;\r
+import ch.bfh.ti.srs.datahandler.DataHandlerForTests;\r
+import ch.bfh.ti.srs.dataschema.Role;\r
+import ch.bfh.ti.srs.dataschema.User;\r
+\r
+public class SessionController {\r
+       private Set<Controller> controllers;\r
+       private DataHandler dh;\r
+       private User currentUser;\r
+\r
+       public SessionController(DataHandler dh) {\r
+               this.dh = dh;\r
+               controllers = new HashSet<Controller>();\r
+       }\r
+\r
+       public SessionController() {\r
+               this.dh = new DataHandlerForTests();\r
+               controllers = new HashSet<Controller>();\r
+       }\r
+\r
+       /**\r
+        * Tries to log in a <code>User</code> with the given credentials\r
+        * @param userName\r
+        *            user name\r
+        * @param password\r
+        *            the stored password for the given user name\r
+        * @return <code>True</code> if the user could log in successfully,\r
+        *         <code>False</code> either the username or the password was not\r
+        *         correct.\r
+        * @throws Exception\r
+        *             no <code>DataHandler</code> set\r
+        */\r
+       public Set<Controller> logIn(String userName, String password) throws Exception {\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
+                       throw new Exception("Username or password wrong");\r
+               else {\r
+                       currentUser = tempUser;\r
+                       controllers.clear();\r
+\r
+                       for (Role role : currentUser.getRoles()) {\r
+                               switch (role) {\r
+                               case User:\r
+                                       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
+                               }\r
+                       }\r
+               }\r
+               return controllers;\r
+       }\r
+\r
+       /**\r
+        * Logs out the current logged user\r
+        * @throws Exception\r
+        *             either no <code>DataHandler</code> is set or no user is\r
+        *             logged in\r
+        */\r
+       public void logOut() throws Exception {\r
+               if (dh == null)\r
+                       throw new Exception("No DataHandler set");\r
+               if (currentUser == null)\r
+                       throw new Exception("No user is logged in");\r
+               currentUser = null;\r
+               for (Controller controller : controllers) {\r
+                       controller = null;\r
+               }\r
+               controllers.clear();\r
+       }\r
+\r
+       /**\r
+        * Gets the user name of the current user\r
+        * @deprecated use <code>getLoggedUser().getUserName()</code>\r
+        * @return user name\r
+        * @throws Exception\r
+        *             no <code>DataHandler</code> is set\r
+        */\r
+       @Deprecated\r
+       public String getLoggedUserName() throws Exception {\r
+               if (currentUser == null)\r
+                       throw new Exception("No user is logged in");\r
+               return currentUser.getUserName();\r
+       }\r
+\r
+       /**\r
+        * Gets the mail address of the current user\r
+        * @deprecated use <code>getLoggedUser().getMail()</code>\r
+        * @return Mail address\r
+        * @throws Exception\r
+        *             no user is logged in\r
+        */\r
+       @Deprecated\r
+       public String getLoggedMail() throws Exception {\r
+               if (currentUser == null)\r
+                       throw new Exception("No user is logged in");\r
+               return currentUser.getMail();\r
+       }\r
+\r
+       /**\r
+        * Gets the first name of the current user\r
+        * @deprecated use <code>getLoggedUser().getName()</code>\r
+        * @return First name\r
+        * @throws Exception\r
+        *             no user is logged in\r
+        */\r
+       @Deprecated\r
+       public String getLoggedName() throws Exception {\r
+               if (currentUser == null)\r
+                       throw new Exception("No user is logged in");\r
+               return currentUser.getName();\r
+       }\r
+\r
+       /**\r
+        * Gets the last name of the current user\r
+        * @deprecated use <code>getLoggedUser().getLastName()</code>\r
+        * @return Last name\r
+        * @throws Exception\r
+        *             no user is logged in\r
+        */\r
+       @Deprecated\r
+       public String getLoggedLastname() throws Exception {\r
+               if (currentUser == null)\r
+                       throw new Exception("No user is logged in");\r
+               return currentUser.getLastname();\r
+       }\r
+\r
+       /**\r
+        * Gets the current logged <code>User</code>\r
+        * @return current <code>User</code>, or <code>null</code> if no\r
+        *         <code>User</code> is logged in\r
+        */\r
+       public User getLoggedUser() {\r
+               if (currentUser == null)\r
+                       return null;\r
+               return currentUser;\r
+       }\r
+\r
+       public void registUser(String userName, String password, String email, String name, String lastname)\r
+                       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 18ce351..64217b1 100644 (file)
@@ -7,14 +7,9 @@
  */\r
 package ch.bfh.ti.srs.controller;\r
 \r
-import java.rmi.AlreadyBoundException;\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
-import java.util.UUID;\r
 \r
 import ch.bfh.ti.daterange.DateRange;\r
 import ch.bfh.ti.srs.datahandler.DataHandler;\r
@@ -25,155 +20,10 @@ import ch.bfh.ti.srs.dataschema.User;
 /**\r
  * @author Michael Grossen\r
  */\r
-public class UserController {\r
-       private User currentUser;\r
-       private DataHandler dh;\r
+public class UserController extends Controller {\r
 \r
-       public UserController() {\r
-       }\r
-\r
-       /**\r
-        * Sets the <code>DataHandler</code> implementation for this Controller,\r
-        * must be set before using all other methods!\r
-        * @param dh\r
-        *            DataHandler implementation (i.e. DataHandlerForExcel)\r
-        */\r
-       public void setDataHandler(DataHandler dh) {\r
-               this.dh = dh;\r
-       }\r
-\r
-       /**\r
-        * Tries to log in a <code>User</code> with the given credentials\r
-        * @param userName\r
-        *            user name\r
-        * @param password\r
-        *            the stored password for the given user name\r
-        * @return <code>True</code> if the user could log in successfully,\r
-        *         <code>False</code> either the username or the password was not\r
-        *         correct.\r
-        * @throws Exception\r
-        *             no <code>DataHandler</code> set\r
-        * @throws AlreadyBoundException\r
-        *             a <code>User</code> is already logged in\r
-        */\r
-       public boolean 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 AlreadyBoundException("A user is already logged in");\r
-               User tempUser = dh.findUser(userName);\r
-               if (tempUser == null || !tempUser.checkPassword(password))\r
-                       return false;\r
-               else {\r
-                       currentUser = tempUser;\r
-                       return true;\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Logs out the current logged user\r
-        * @throws Exception\r
-        *             either no <code>DataHandler</code> is set or no user is\r
-        *             logged in\r
-        */\r
-       public void logOut() throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               currentUser = null;\r
-       }\r
-\r
-       /**\r
-        * Registers a new user to the current DataHandler\r
-        * @param userName\r
-        *            unique user name\r
-        * @param password\r
-        *            plain-text password\r
-        * @param email\r
-        *            e-mail address\r
-        * @param name\r
-        *            name\r
-        * @param lastname\r
-        *            last name\r
-        * @throws Exception\r
-        *             no <code>DataHandler</code> set\r
-        */\r
-       public void addUser(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
-       /**\r
-        * Gets the user name of the current user\r
-        * @deprecated use <code>getLoggedUser().getUserName()</code>\r
-        * @return user name\r
-        * @throws Exception\r
-        *             no <code>DataHandler</code> is set\r
-        */\r
-       @Deprecated\r
-       public String getLoggedUserName() throws Exception {\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               return currentUser.getUserName();\r
-       }\r
-\r
-       /**\r
-        * Gets the mail address of the current user\r
-        * @deprecated use <code>getLoggedUser().getMail()</code>\r
-        * @return Mail address\r
-        * @throws Exception\r
-        *             no user is logged in\r
-        */\r
-       @Deprecated\r
-       public String getLoggedMail() throws Exception {\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               return currentUser.getMail();\r
-       }\r
-\r
-       /**\r
-        * Gets the first name of the current user\r
-        * @deprecated use <code>getLoggedUser().getName()</code>\r
-        * @return First name\r
-        * @throws Exception\r
-        *             no user is logged in\r
-        */\r
-       @Deprecated\r
-       public String getLoggedName() throws Exception {\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               return currentUser.getName();\r
-       }\r
-\r
-       /**\r
-        * Gets the last name of the current user\r
-        * @deprecated use <code>getLoggedUser().getLastName()</code>\r
-        * @return Last name\r
-        * @throws Exception\r
-        *             no user is logged in\r
-        */\r
-       @Deprecated\r
-       public String getLoggedLastname() throws Exception {\r
-               if (currentUser == null)\r
-                       throw new Exception("No user is logged in");\r
-               return currentUser.getLastname();\r
-       }\r
-\r
-       /**\r
-        * Gets the current logged <code>User</code>\r
-        * @return current <code>User</code>, or <code>null</code> if no\r
-        *         <code>User</code> is logged in\r
-        */\r
-       public User getLoggedUser() {\r
-               if (currentUser == null)\r
-                       return null;\r
-               return currentUser;\r
+       public UserController(DataHandler dh, SessionController sc) {\r
+               super(dh, sc);\r
        }\r
 \r
        /**\r
@@ -191,52 +41,6 @@ public class UserController {
        }\r
 \r
        /**\r
-        * Returns all reservations overlapping the given dateRange in a\r
-        * <code>Map</code>\r
-        * @param dateRange\r
-        *            time span\r
-        * @return <code>Key</code> reservation, <code>Value</code> is editable\r
-        * @throws Exception\r
-        *             no <code>User</code> is logged in or no\r
-        *             <code>DataHandler</code> is set\r
-        */\r
-       public Map<Reservation, Boolean> getReservationsInDateRange(DateRange dateRange) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (dateRange == null)\r
-                       throw new Exception("dateRange must be defined");\r
-\r
-               // Could be swapped out to private method for better performance (just\r
-               // check currentUser once)\r
-               // and easier code maintenance\r
-               Map<Reservation, Boolean> returnSet = new HashMap<Reservation, Boolean>();\r
-               for (Reservation reservation : dh.overlaps(dateRange)) {\r
-                       returnSet.put(reservation, reservation.getUser().getUserName().equals(currentUser.getUserName()));\r
-               }\r
-               return returnSet;\r
-       }\r
-\r
-       /**\r
-        * Returns the reservation or null if no reservation was found\r
-        * @param id\r
-        *            reservation identifier\r
-        * @return <code>Reservation</code> copy of reservation with given id,\r
-        *         <code>null</code> no reservation with this id found\r
-        * @throws Exception\r
-        *             No DataHandler set or id null\r
-        */\r
-       public Reservation getReservation(UUID id) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (id == null)\r
-                       throw new Exception("uuid must be defined");\r
-               if (dh.findReservation(id) == null)\r
-                       return null;\r
-               else\r
-                       return dh.findReservation(id).clone();\r
-       }\r
-\r
-       /**\r
         * Returns the reservations of the given user\r
         * @param user\r
         *            Owner, if <code>null</code> returns the reservations of the\r
@@ -247,96 +51,13 @@ public class UserController {
         *             logged in while user param = null\r
         */\r
        public Map<Reservation, Boolean> getUserReservations(User user) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
                if (user == null) {\r
-                       if (currentUser == null)\r
+                       if (sc.getLoggedUser() == null)\r
                                throw new Exception("user must be defined, if no user is logged in");\r
                        else\r
-                               user = currentUser;\r
+                               user = sc.getLoggedUser();\r
                }\r
-\r
-               // Could be swapped out to private method for better performance (just\r
-               // check currentUser once)\r
-               // and easier code maintenance\r
-               Map<Reservation, Boolean> returnSet = new HashMap<Reservation, Boolean>();\r
-               for (Reservation reservation : dh.userReservations(user)) {\r
-                       returnSet.put(reservation, reservation.getUser().getUserName().equals(currentUser.getUserName()));\r
-               }\r
-               return returnSet;\r
-       }\r
-\r
-       /**\r
-        * Returns <code>Map</code> of reservation group (recurring reservations)\r
-        * @param groupId\r
-        *            group identifier\r
-        * @return <code>Key</code> reservation, <code>Value</code> is editable\r
-        * @throws IllegalArgumentException\r
-        *             groupId is null\r
-        * @throws Exception\r
-        *             no <code>DataHandler</code> set\r
-        */\r
-       public Map<Reservation, Boolean> getReservationGroup(UUID groupId) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (groupId == null)\r
-                       throw new IllegalArgumentException("groupId has to be defined");\r
-\r
-               // Could be swapped out to private method for better performance (just\r
-               // check currentUser once)\r
-               // and easier code maintenance\r
-               Map<Reservation, Boolean> returnSet = new HashMap<Reservation, Boolean>();\r
-               for (Reservation reservation : dh.findGroupReservations(groupId)) {\r
-                       returnSet.put(reservation, reservation.getUser().getUserName().equals(currentUser.getUserName()));\r
-               }\r
-               return returnSet;\r
-       }\r
-\r
-       /**\r
-        * Makes a reservation in the current set DataHandler\r
-        * @param user\r
-        *            user owning the reservation, if null currentUser is set\r
-        * @param resource\r
-        *            resource to reserve\r
-        * @param dateRangeList\r
-        *            <code>List</code> of DateRanges defining when the resource is\r
-        *            occupied\r
-        * @param remark\r
-        *            public remark for the reservation\r
-        * @return <code>Set</code> of Reservations that overlap an already stored\r
-        *         reservation (conflict), if not empty no reservation was saved\r
-        * @throws IllegalArgumentException\r
-        *             <code>resource</code> or <code>dateRangeList</code> is null,\r
-        *             or <code>dateRangeList</code> is empty\r
-        * @throws Exception\r
-        *             thrown by <code>DataHandler</code>\r
-        */\r
-       public Set<Reservation> makeReservation(User user, Resource resource, List<DateRange> dateRangeList, String remark)\r
-                       throws Exception {\r
-               if (user == null) {\r
-                       if (currentUser == null)\r
-                               throw new IllegalArgumentException("User must be defined if no user is logged in");\r
-                       user = currentUser;\r
-               }\r
-               if (resource == null)\r
-                       throw new IllegalArgumentException("Resource must be definded");\r
-               if (dateRangeList == null)\r
-                       throw new IllegalArgumentException("dateRangeList can not be null");\r
-               if (dateRangeList.isEmpty())\r
-                       throw new IllegalArgumentException("dateRangeList empty");\r
-\r
-               Set<Reservation> invalidReservations = new HashSet<Reservation>();\r
-               UUID groupId = UUID.randomUUID();\r
-               for (DateRange dateRange : dateRangeList) {\r
-                       Reservation reservation = new Reservation(groupId, user, resource, dateRange, remark);\r
-                       if (!dh.addReservation(reservation))\r
-                               invalidReservations.add(reservation);\r
-               }\r
-               if (invalidReservations.isEmpty()) {\r
-                       dh.saveChanges();\r
-                       return null;\r
-               } else\r
-                       return invalidReservations;\r
+               return super.getUserReservations_Super(user);\r
        }\r
 \r
        /**\r
@@ -353,15 +74,15 @@ public class UserController {
         *             not authorized\r
         */\r
        public boolean changeReservation(Reservation reservation) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (currentUser == 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(currentUser))\r
+               if (!reservation.getUser().getUserName().equals(super.sc.getLoggedUser().getUserName())) {\r
                        throw new Exception("You are not authorized to make this change");\r
-               return dh.editReservation(reservation);\r
+               }\r
+\r
+               return super.changeReservation_Super(reservation);\r
        }\r
 \r
        /**\r
@@ -378,30 +99,27 @@ public class UserController {
         *             is logged in or logged <code>User</code> is not authorized\r
         */\r
        public boolean deleteReservation(Reservation reservation) throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               if (currentUser == 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(currentUser))\r
+               if (!reservation.getUser().equals(sc.getLoggedUser()))\r
                        throw new Exception("You are not authorized to make this change");\r
-               return dh.deleteReservation(reservation);\r
+               return super.deleteReservation_Super(reservation);\r
        }\r
 \r
        /**\r
-        * Returns all stored resources of the set DataHandler\r
-        * @return <code>List</code> of resources\r
-        * @throws Exception\r
-        *             no <code>DataHandler</code> is set\r
+        * {@inheritDoc}\r
         */\r
-       public List<Resource> getResources() throws Exception {\r
-               if (dh == null)\r
-                       throw new Exception("No DataHandler set");\r
-               List<Resource> resourceList = new ArrayList<Resource>();\r
-               for (Resource resource : dh.getAllResources()) {\r
-                       resourceList.add(resource.clone());\r
+       public Set<Reservation> makeReservation(User user, Resource resource, List<DateRange> dateRangeList, String remark)\r
+                       throws Exception {\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
-               return resourceList;\r
+               if (!user.equals(sc.getLoggedUser()))\r
+                       throw new Exception("You are not authorized to make this reservation");\r
+               return super.makeReservation(user, resource, dateRangeList, remark);\r
        }\r
 }\r
index e861f0e..0c964b1 100644 (file)
@@ -43,6 +43,14 @@ public interface DataHandler {
        public boolean addUser(User user) throws Exception;
 
        /**
+        * Edit a User with the same Name.
+        * @param user
+        *            the new User
+        * @return a boolean whether the user was edited or not
+        */
+       public boolean editUser(User user);
+
+       /**
         * Finds the resourceName in the Datacontext and returns the Resource object
         * or null if not found
         * @param resourceName
@@ -132,9 +140,41 @@ public interface DataHandler {
         */
        public void refresh(boolean discardChanges) throws Exception;
 
+       /**
+        * Edit a Reservation with the same ID.
+        * @param reservation
+        *            the new Reservation
+        * @return a boolean whether the reservation was edited or not
+        */
        public boolean editReservation(Reservation reservation);
 
+       /**
+        * deletes a Reservation from the datastorage
+        * @param reservation
+        *            the Reservation to remove
+        * @return a boolean whether the reservation was deleted or not
+        */
        public boolean deleteReservation(Reservation reservation);
 
+       /**
+        * Edit a Resource with the same ID.
+        * @param resource
+        *            the new Resource
+        * @return a boolean whether the resource was edited or not
+        */
+       public boolean editResource(Resource resource);
+
+       /**
+        * deletes a Resource from the datastorage
+        * @param resource
+        *            the Resource to remove
+        * @return a boolean whether the resource was deleted or not
+        */
+       public boolean deleteResource(Resource resource);
+
+       /**
+        * get all the Resources from the datastorage
+        * @return a set of Resources
+        */
        public Set<Resource> getAllResources();
 }
index 18229b5..39d8897 100644 (file)
@@ -196,6 +196,9 @@ public class DataHandlerForTests implements DataHandler {
                        throw new Exception("No implementation on DataHandlerForTests possible");
        }
 
+       /**
+        * {@inheritDoc}
+        */
        @Override
        public boolean editReservation(Reservation reservation) {
                if (reservation == null) {
@@ -209,6 +212,9 @@ public class DataHandlerForTests implements DataHandler {
                return false;
        }
 
+       /**
+        * {@inheritDoc}
+        */
        @Override
        public boolean deleteReservation(Reservation reservation) {
                if (reservation == null) {
@@ -221,10 +227,56 @@ public class DataHandlerForTests implements DataHandler {
                }
        }
 
+       /**
+        * {@inheritDoc}
+        */
        @Override
        public Set<Resource> getAllResources() {
 
                return resourceList;
        }
 
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean editResource(Resource resource) {
+               if (resource == null) {
+                       throw new IllegalArgumentException("Resource object must not be null!");
+               }
+               if (findResource(resource.getName()) != null) {
+                       resourceList.remove(findResource(resource.getName()));
+                       resourceList.add(resource);
+                       return true;
+               }
+               return false;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public boolean deleteResource(Resource resource) {
+               if (resource == null) {
+                       throw new IllegalArgumentException("Resource object must not be null!");
+               } else if (resourceList.contains(resource)) {
+                       resourceList.remove(resource);
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
+       @Override
+       public boolean editUser(User user) {
+               if (user == null) {
+                       throw new IllegalArgumentException("User object must not be null!");
+               }
+               if (findUser(user.getUserName()) != null) {
+                       userList.remove(findUser(user.getUserName()));
+                       userList.add(user);
+                       return true;
+               }
+               return false;
+       }
 }
diff --git a/src/main/java/ch/bfh/ti/srs/dataschema/Modifiable.java b/src/main/java/ch/bfh/ti/srs/dataschema/Modifiable.java
new file mode 100644 (file)
index 0000000..4fe51e4
--- /dev/null
@@ -0,0 +1,25 @@
+/*\r
+ * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
+ *\r
+ * Project Smart Reservation System.\r
+ *\r
+ * Distributable under GPL license. See terms of license at gnu.org.\r
+ */\r
+package ch.bfh.ti.srs.dataschema;\r
+\r
+/**\r
+ * Specifies the interface checking if the Object got modified.\r
+ */\r
+\r
+public interface Modifiable extends Cloneable {\r
+\r
+       /**\r
+        * Checks if any of the updatable variables got changed.\r
+        * @param obj\r
+        *            object to modify\r
+        * @return true if something got changed and false if no change happened.\r
+        */\r
+       public boolean isModified(Object obj);\r
+\r
+       public Object clone() throws CloneNotSupportedException;\r
+}\r
index fd7da2b..ca9f5ec 100644 (file)
@@ -11,7 +11,7 @@ import java.util.UUID;
 \r
 import ch.bfh.ti.daterange.DateRange;\r
 \r
-public class Reservation implements Cloneable {\r
+public class Reservation implements Modifiable {\r
 \r
        private UUID id;\r
        private UUID groupId;\r
@@ -20,20 +20,33 @@ public class Reservation implements Cloneable {
        private DateRange dateRange;\r
        private String remark;\r
 \r
-       public Reservation(UUID groupId, User user, Resource resource, DateRange DateRange, String remark) {\r
-               // // if (groupId == null)\r
-               // // throw new IllegalArgumentException("GroupID must not be null");\r
-               // if (user.getUserName() == null)\r
-               // throw new IllegalArgumentException("User must not be null");\r
-               // if (resource.getId() == null)\r
-               // throw new IllegalArgumentException("Resource must not be null");\r
-               // if (dateRange.isEmpty())\r
-               // throw new IllegalArgumentException("DateRange must not be null");\r
+       /**\r
+        * Normal constructor for new reservation created in the Controller\r
+        * @param groupId\r
+        *            id of reservation group when reocuring reservation, 0 when\r
+        *            single reservation\r
+        * @param user\r
+        *            user who created the reservation\r
+        * @param resource\r
+        *            reserved resource\r
+        * @param dateRange\r
+        *            daterange of the reservation\r
+        * @param remark\r
+        *            remark\r
+        * @throws IllegalArgumentException\r
+        *             the name of the user and resource can't be null\r
+        */\r
+\r
+       public Reservation(UUID groupId, User user, Resource resource, DateRange dateRange, String remark) {\r
+               if (user == null)\r
+                       throw new IllegalArgumentException("User must not be null");\r
+               if (resource == null)\r
+                       throw new IllegalArgumentException("Resource must not be null");\r
 \r
                this.groupId = groupId;\r
                this.user = user;\r
                this.resource = resource;\r
-               this.dateRange = DateRange;\r
+               this.dateRange = dateRange;\r
                this.remark = remark;\r
 \r
                this.id = UUID.randomUUID();\r
@@ -80,6 +93,20 @@ public class Reservation implements Cloneable {
        }\r
 \r
        @Override\r
+       public boolean isModified(Object obj) {\r
+               if (obj == this) {\r
+                       return false;\r
+               }\r
+               if (obj == null) {\r
+                       return true;\r
+               }\r
+               Reservation otherReservation = (Reservation) obj;\r
+               return this.user != otherReservation.getUser() || this.resource != otherReservation.getResource()\r
+                               || this.dateRange.compareTo(otherReservation.getDateRange()) != 0\r
+                               || this.remark != otherReservation.getRemark();\r
+       }\r
+\r
+       @Override\r
        public Reservation clone() throws CloneNotSupportedException {\r
                return (Reservation) super.clone();\r
        }\r
index e5b1ebe..62d047b 100644 (file)
@@ -9,7 +9,7 @@ package ch.bfh.ti.srs.dataschema;
 \r
 import java.util.UUID;\r
 \r
-public class Resource implements Cloneable {\r
+public class Resource implements Modifiable {\r
 \r
        private UUID id;\r
        private String name;\r
@@ -55,6 +55,17 @@ public class Resource implements Cloneable {
                this.type = type;\r
        }\r
 \r
+       public boolean isModified(Object obj) {\r
+               if (obj == this) {\r
+                       return false;\r
+               }\r
+               if (obj == null) {\r
+                       return true;\r
+               }\r
+               Resource otherResource = (Resource) obj;\r
+               return this.name != otherResource.getName() || this.type != otherResource.getType();\r
+       }\r
+\r
        @Override\r
        public Resource clone() throws CloneNotSupportedException {\r
                return (Resource) super.clone();\r
@@ -6,3 +6,7 @@
  * Distributable under GPL license. See terms of license at gnu.org.\r
  */\r
 package ch.bfh.ti.srs.dataschema;\r
+\r
+public enum Role {\r
+       User, ResourceManager, Admin\r
+}\r
index 19bfabb..109febe 100644 (file)
@@ -7,10 +7,11 @@
  */
 package ch.bfh.ti.srs.dataschema;
 
-import ch.bfh.ti.srs.extern.Password;
 import java.util.HashSet;
 import java.util.Set;
 
+import ch.bfh.ti.srs.extern.Password;
+
 public class User implements Cloneable {
 
        private final String userName;
@@ -18,6 +19,7 @@ public class User implements Cloneable {
        private String mail;
        private String name;
        private String lastname;
+       private Set<Role> roles = new HashSet<Role>();
 
        /**
         * Constructor for already existing <code>User</code> in the Datacontext.
@@ -64,6 +66,7 @@ public class User implements Cloneable {
 
                this.userName = userName;
                this.hashedPassword = Password.getSaltedHash(password);
+               this.roles.add(Role.User);
        }
 
        public String getUserName() {
@@ -151,12 +154,21 @@ public class User implements Cloneable {
                return m.matches();
        }
 
-       /*
-        * (non-Javadoc)
-        * @see java.lang.Object#clone()
-        */
        @Override
        public User clone() throws CloneNotSupportedException {
                return (User) super.clone();
        }
+
+       public void addRole(Role role) {
+               roles.add(role);
+       }
+
+       public void removeRole(Role role) {
+               if (roles.contains(role))
+                       roles.remove(role);
+       }
+
+       public Set<Role> getRoles() {
+               return roles;
+       }
 }
index c507ff5..01d308b 100644 (file)
@@ -206,4 +206,22 @@ public class DataHandlerForExcel implements DataHandler {
                // TODO Auto-generated method stub
                return null;
        }
+
+       @Override
+       public boolean editResource(Resource resource) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean deleteResource(Resource resource) {
+               // TODO Auto-generated method stub
+               return false;
+       }
+
+       @Override
+       public boolean editUser(User user) {
+               // TODO Auto-generated method stub
+               return false;
+       }
 }
diff --git a/src/site/apt/package_design.apt b/src/site/apt/package_design.apt
new file mode 100644 (file)
index 0000000..5ead4cd
--- /dev/null
@@ -0,0 +1,20 @@
+               ----------
+               Package Diagram
+               ----------
+               muggd1
+               ----------
+               December 07, 2015
+
+Package Diagram
+
+       This document describes the Package Design of the Smart Reservation
+System (SRS). It shows the A-I Graph with the corresponding stability and abstractness, 
+also the arrows from one to another package.
+We only had 3 packages in this small project, if we would continue we would probably add a GUI-package and
+some other.
+As you can see the package dataschema(left point) is in the zone of pain, because it hasn't that much
+abstractness and the other two packages use this package. But its not in the left corner of zone of pain.
+
+* 1. The A-I Graph
+
+[images/AI_Graph.png]A-I Graph
\ No newline at end of file
index 19dda18..ee6c850 100644 (file)
@@ -8,7 +8,7 @@
 Package Diagram
 
        This document describes the Package Diagram of the Smart Reservation
-System (SRS). It show the classes with the imports of other classes/packages. 
+System (SRS). It show the classes and interface with the imports of other classes/packages. 
 
 * 1. Package Diagram
 
index 6bfbfdc..064a700 100644 (file)
@@ -40,11 +40,11 @@ Sprint Backlog
 |                      |       wiederholungen                  | z.B wöchentliche             |                               |               |               |               |                       |
 |                      |                                                       | reservationen zu machen       |                               |               |               |               |                       |
 *-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
-| 7                    | -     resource manager client | ein client über den der      |low                    |               |               |               |Waiting        |
+| 7                    | -     resource manager client | ein client über den der      |High                   |21             |               |               |done           |
 |                      |                                                       | resource manager seine        |                               |               |               |               |                       |
 |                      |                                                       | Aktionen durchführen kann    |                               |               |               |               |                       |
 *-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
-| 8                    | -     Resourcen Prüfen               | erlaubt es dem resource       |low                    |               |               |               |Waiting        |
+| 8                    | -     Resourcen Prüfen               | erlaubt es dem resource       |High                   |               |               |               |Waiting        |
 |                      |                                                       | manager zu sehen wer zu       |                               |               |               |               |                       |
 |                      |                                                       | welcher Zeit welche           |                               |               |               |               |                       |
 |                      |                                                       | ressource gebucht hat         |                               |               |               |               |                       |
@@ -68,6 +68,8 @@ Sprint Backlog
 |                      |                                                       |                                                       |                               |[h]    |[h]    |[h]    |                       |
 *-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
 
+
+
 * 3. finished tasks
 
 *-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
@@ -146,4 +148,52 @@ Sprint Backlog
 *-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
 | 6.2          |                                                       | Test für 5.1                         |High                   |1              |               |2              |Done           |
 |                      |                                                       |                                                       |                               |               |               |               |                       |
+*-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
+| 7                    | -     resource manager                | ein client über den der      |High                   |21             |               |26             |Done           |       
+|                      |                                                       | resource manager seine        |                               |               |               |               |                       |
+|                      |                                                       | Aktionen durchführen kann    |                               |               |               |               |                       |
+*-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
+| 7.1          |                                                       | SessionController Klasse      |High                   | 2             |               |3              |Done           |       
+|                      |                                                       | implementieren                        |                               |               |               |               |                       |
+|                      |                                                       |                                                       |                               |               |               |               |                       |
+*-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
+| 7.2          |                                                       | Testklasse für                       |High                   | 2             |               |2              |Done           |       
+|                      |                                                       | SessionController                     |                               |               |               |               |                       |
+|                      |                                                       | implementieren                        |                               |               |               |               |                       |
+*-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
+| 7.3          |                                                       | UserController anpassen       |High                   | 2             |               |5              |Done           |       
+|                      |                                                       |                                                       |                               |               |               |               |                       |
+|                      |                                                       |                                                       |                               |               |               |               |                       |
+*-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
+| 7.4          |                                                       | Testklasse für                       |High                   | 2             |               |3              |Done           |       
+|                      |                                                       | UserController anpassen       |                               |               |               |               |                       |
+|                      |                                                       |                                                       |                               |               |               |               |                       |
+*-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
+| 7.5          |                                                       | Die Controller Klasse         |High                   | 2             |               |2              |Done           |       
+|                      |                                                       | ResourceManagerController     |                               |               |               |               |                       |
+|                      |                                                       | implementieren                        |                               |               |               |               |                       |
+*-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
+| 7.6          |                                                       | Testklasse für                       |High                   | 3             |               |3              |Done           |       
+|                      |                                                       | ResourceManagerController     |                               |               |               |               |                       |
+|                      |                                                       | implementieren                        |                               |               |               |               |                       |
+*-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
+| 7.7          |                                                       | Abstrakte Klasse                      |High                   | 2             |               |2              |Done           |       
+|                      |                                                       | Controller                            |                               |               |               |               |                       |
+|                      |                                                       | implementieren                        |                               |               |               |               |                       |
+*-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
+| 7.8          |                                                       | in User klasse Collection     |High                   | 1             |               |1              |Done           |       
+|                      |                                                       | mit Rollen hinzufügen                |                               |               |               |               |                       |
+|                      |                                                       |                                                       |                               |               |               |               |                       |
+*-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
+| 7.9          |                                                       | Testklasse für User          |High                   | 1             |               |1              |Done           |       
+|                      |                                                       | anpassen                                      |                               |               |               |               |                       |
+|                      |                                                       |                                                       |                               |               |               |               |                       |
+*-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
+| 7.10         |                                                       | Klasse Role implementieren|High                       | 1             |               |1              |Done           |       
+|                      |                                                       |                                                       |                               |               |               |               |                       |
+|                      |                                                       |                                                       |                               |               |               |               |                       |
+*-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
+| 7.11         |                                                       | Klassenstruktur anpassen      |High                   | 3             |               |3              |Done           |       
+|                      |                                                       |                                                       |                               |               |               |               |                       |
+|                      |                                                       |                                                       |                               |               |               |               |                       |
 *-----------+---------------------------+---------------------------+---------------+-------+-------+-------+-----------+
\ No newline at end of file
diff --git a/src/site/resources/images/AI_Graph.png b/src/site/resources/images/AI_Graph.png
new file mode 100644 (file)
index 0000000..19958bb
Binary files /dev/null and b/src/site/resources/images/AI_Graph.png differ
index 7d45029..7f8f142 100644 (file)
Binary files a/src/site/resources/images/SSD.png and b/src/site/resources/images/SSD.png differ
index 9ea0a66..782bcdb 100644 (file)
Binary files a/src/site/resources/images/context_diagram.png and b/src/site/resources/images/context_diagram.png differ
index 7cc8c28..48128a8 100644 (file)
Binary files a/src/site/resources/images/packageDiagram.png and b/src/site/resources/images/packageDiagram.png differ
index 57ab366..fd345bc 100644 (file)
Binary files a/src/site/resources/images/seq_userlogin_diagram.png and b/src/site/resources/images/seq_userlogin_diagram.png differ
index 5de511f..8c7226d 100644 (file)
@@ -37,7 +37,8 @@
                        <item name="System Sequence Diagram" href="SSD.html" />
                        <item name="Sequence Diagram US1" href="seq_userlogin_diagram.html" />
                        <item name="Sequence Diagram US5" href="seq_usereditres_diagram.html" />
-                       <item name="Package Diagram" href="package_diagram.html" /><!--
+                       <item name="Package Diagram" href="package_diagram.html" />
+                   <item name="Package Design" href="package_design.html" /><!--
                        <item name="Detailed Design Document" href="detailed_design_document.html" />
                        <item name="System Architecture Document" href="system_aarchitecture_document.html" />
                        <item name="Other Specs" href="other_specs.html" />
diff --git a/src/test/java/ch/bfh/ti/srs/controller/ResourceManagerControllerTest.java b/src/test/java/ch/bfh/ti/srs/controller/ResourceManagerControllerTest.java
new file mode 100644 (file)
index 0000000..add2367
--- /dev/null
@@ -0,0 +1,119 @@
+/*\r
+ * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
+ *\r
+ * Project Smart Reservation System.\r
+ *\r
+ * Distributable under GPL license. See terms of license at gnu.org.\r
+ */\r
+package ch.bfh.ti.srs.controller;\r
+\r
+import org.junit.Test;\r
+\r
+import ch.bfh.ti.srs.datahandler.DataHandler;\r
+import ch.bfh.ti.srs.datahandler.DataHandlerForTests;\r
+import ch.bfh.ti.srs.dataschema.Resource;\r
+\r
+public class ResourceManagerControllerTest {\r
+\r
+       @Test\r
+       public void AddResourceTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
+\r
+               rmc.addResource("N321", "class room");\r
+       }\r
+\r
+       @Test\r
+       public void ChangeResourceTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
+               Resource testResource = new Resource("N321", "class room");\r
+\r
+               rmc.addResource("N321", "class room");\r
+               testResource.setType("lecture hall");\r
+               rmc.changeResource(testResource);\r
+       }\r
+\r
+       @Test\r
+       public void DeleteResourceTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
+               Resource testResource = new Resource("N321", "class room");\r
+\r
+               rmc.addResource("N321", "class room");\r
+               rmc.deleteResource(testResource);\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void AddResourceInvalidDatahandlerTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               ResourceManagerController rmc = new ResourceManagerController(null, sc);\r
+\r
+               rmc.addResource("N321", "class room");\r
+\r
+       }\r
+\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void AddResourceInvalidResourceTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
+\r
+               rmc.addResource(null, null);\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void ChangeResourceInvalidDatahandlerTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               ResourceManagerController rmc1 = new ResourceManagerController(dh, sc);\r
+               ResourceManagerController rmc2 = new ResourceManagerController(null, sc);\r
+               Resource testResource = new Resource("N321", "class room");\r
+\r
+               rmc1.addResource("N321", "class room");\r
+               testResource.setType("lecture hall");\r
+               rmc2.changeResource(testResource);\r
+       }\r
+\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void ChangeResourceInvalidResourceTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
+               Resource testResource = new Resource("N321", "class room");\r
+\r
+               rmc.addResource("N321", "class room");\r
+               testResource = null;\r
+               rmc.changeResource(testResource);\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void DeleteResourceInvalidDatahandlerTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               ResourceManagerController rmc1 = new ResourceManagerController(dh, sc);\r
+               ResourceManagerController rmc2 = new ResourceManagerController(null, sc);\r
+               Resource testResource = new Resource("N321", "class room");\r
+\r
+               rmc1.addResource("N321", "class room");\r
+               rmc2.deleteResource(testResource);\r
+\r
+       }\r
+\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void DeleteResourceInvalidResourceTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
+               Resource testResource = new Resource("N321", "class room");\r
+\r
+               rmc.addResource("N321", "class room");\r
+               testResource = null;\r
+               rmc.deleteResource(testResource);\r
+       }\r
+\r
+}\r
diff --git a/src/test/java/ch/bfh/ti/srs/controller/SessionControllerTest.java b/src/test/java/ch/bfh/ti/srs/controller/SessionControllerTest.java
new file mode 100644 (file)
index 0000000..4a0aa3c
--- /dev/null
@@ -0,0 +1,208 @@
+/*\r
+ * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
+ *\r
+ * Project Smart Reservation System.\r
+ *\r
+ * Distributable under GPL license. See terms of license at gnu.org.\r
+ */\r
+package ch.bfh.ti.srs.controller;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\r
+\r
+import java.util.Set;\r
+\r
+import org.junit.Test;\r
+\r
+import ch.bfh.ti.srs.datahandler.DataHandler;\r
+import ch.bfh.ti.srs.datahandler.DataHandlerForTests;\r
+import ch.bfh.ti.srs.dataschema.Role;\r
+import ch.bfh.ti.srs.dataschema.User;\r
+\r
+public class SessionControllerTest {\r
+\r
+       @Test\r
+       public void logInTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               SessionController sc2 = new SessionController(); // dummy, just to\r
+                                                                                                                       // trigger this\r
+                                                                                                                       // constructor..\r
+\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
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void logInException1Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\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
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void logInInvalidCredetialsTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\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
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test\r
+       public void getLoggedUserNameTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\r
+               // uc.setDataHandler(dh);\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
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void getLoggedUserNameExceptionTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\r
+               sc.getLoggedUserName();\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test\r
+       public void getLoggedUserMailTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\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
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void getLoggedMailExceptionTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\r
+               sc.getLoggedMail();\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test\r
+       public void getLoggedNameTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\r
+               // uc.setDataHandler(dh);\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
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void getLoggedNameExceptionTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\r
+               sc.getLoggedName();\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test\r
+       public void getLoggedLastnameTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\r
+               // uc.setDataHandler(dh);\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
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void getLoggedLastnameExceptionTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\r
+               sc.getLoggedLastname();\r
+       }\r
+\r
+       @Test\r
+       public void getLoggedUserTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\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
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
+       @Test\r
+       public void logOutTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\r
+               // uc.setDataHandler(dh);\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
+               sc.logOut();\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void logOutException1Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+\r
+               sc.logOut();\r
+       }\r
+\r
+       @Test(expected = Exception.class)\r
+       public void logOutException2Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(null);\r
+\r
+               sc.logOut();\r
+       }\r
+\r
+}\r
index 5b06f2a..366f43d 100644 (file)
@@ -13,19 +13,15 @@ import static org.junit.Assert.assertTrue;
 \r
 import java.util.ArrayList;\r
 import java.util.Date;\r
-import java.util.HashSet;\r
-import java.util.Iterator;\r
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.Set;\r
 import java.util.UUID;\r
 \r
-import org.junit.Ignore;\r
 import org.junit.Test;\r
 \r
 import ch.bfh.ti.daterange.DateRange;\r
 import ch.bfh.ti.daterange.impl.pojo.DateRangeImpl;\r
-import ch.bfh.ti.srs.controller.UserController;\r
 import ch.bfh.ti.srs.datahandler.DataHandler;\r
 import ch.bfh.ti.srs.datahandler.DataHandlerForTests;\r
 import ch.bfh.ti.srs.dataschema.Reservation;\r
@@ -36,249 +32,88 @@ import ch.bfh.ti.srs.dataschema.User;
  * @author Michael Grossen\r
  */\r
 public class UserControllerTest {\r
-\r
        @Test\r
        public void addUserTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
-               uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
-       }\r
-\r
-       @Test(expected = Exception.class)\r
-       public void addUserExceptionTest() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-       }\r
-\r
-       @Test\r
-       public void logInTest() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.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
-               uc.logIn("TestUser3", "pass3");\r
-       }\r
-\r
-       @Test(expected = Exception.class)\r
-       public void logInException1Test() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.logIn("TestUser3", "pass3");\r
-       }\r
-\r
-       @Test(expected = Exception.class)\r
-       public void logInException2Test() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-\r
-               uc.logIn("TestUser1", "pass1");\r
-               uc.logIn("TestUser2", "pass2");\r
-       }\r
-\r
-       @Test\r
-       public void logInInvalidCredetialsTest() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-\r
-               assertFalse(uc.logIn("TestUser3", "pass3"));\r
-               assertFalse(uc.logIn("TestUser1", "pass2"));\r
-               assertTrue(uc.logIn("TestUser1", "pass1"));\r
-       }\r
-\r
-       @Test\r
-       public void getLoggedUserNameTest() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.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
-               uc.logIn("TestUser1", "pass1");\r
-               assertEquals("TestUser1", uc.getLoggedUserName());\r
-       }\r
-\r
-       @Test(expected = Exception.class)\r
-       public void getLoggedUserNameExceptionTest() throws Exception {\r
-               UserController uc = new UserController();\r
-               String currentUserName = uc.getLoggedUserName();\r
-       }\r
-\r
-       @Test\r
-       public void getLoggedUserMailTest() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "hanfli@bfh.ch", null, null);\r
-               uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
-               uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
-\r
-               uc.logIn("TestUser2", "pass2");\r
-               assertEquals("hanfli@bfh.ch", uc.getLoggedMail());\r
-       }\r
+               SessionController sc = new SessionController(dh);\r
 \r
-       @Test(expected = Exception.class)\r
-       public void getLoggedMailExceptionTest() throws Exception {\r
-               UserController uc = new UserController();\r
-               String currentMail = uc.getLoggedMail();\r
-       }\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
-       @Test\r
-       public void getLoggedNameTest() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-\r
-               uc.setDataHandler(dh);\r
+               UserController uc = new UserController(dh, sc);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser3", "pass3", "grosm9@bfh.ch", "Hanfli", null);\r
-               uc.addUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
-\r
-               uc.logIn("TestUser3", "pass3");\r
-               assertEquals("Hanfli", uc.getLoggedName());\r
        }\r
 \r
        @Test(expected = Exception.class)\r
-       public void getLoggedNameExceptionTest() throws Exception {\r
-               UserController uc = new UserController();\r
-               uc.getLoggedName();\r
-       }\r
-\r
-       @Test\r
-       public void getLoggedLastnameTest() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.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
+       public void addUserExceptionTest1() throws Exception {\r
+               SessionController sc = new SessionController(null);\r
 \r
-               uc.logIn("TestUser4", "pass4");\r
-               assertEquals("User", uc.getLoggedLastname());\r
+               sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
        }\r
 \r
        @Test(expected = Exception.class)\r
-       public void getLoggedLastnameExceptionTest() throws Exception {\r
-               UserController uc = new UserController();\r
-               String currentLastName = uc.getLoggedLastname();\r
-       }\r
-\r
-       @Test\r
-       public void getLoggedUserTest() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+       public void addUserExceptionTest2() throws Exception {\r
+               UserController uc = new UserController(null, null);\r
 \r
-               uc.setDataHandler(dh);\r
                uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               assertEquals(null, uc.getLoggedUser());\r
-               uc.logIn("TestUser1", "pass1");\r
-               assertEquals("TestUser1", uc.getLoggedUser().getUserName());\r
        }\r
 \r
-       // @Test(expected=Exception.class)\r
-       // public void getLoggedUserExceptionTest() throws Exception{\r
-       // DataHandler dh = new DataHandlerForTests();\r
-       // UserController uc = new UserController();\r
-       //\r
-       // uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-       // uc.logIn("TestUser1", "pass1");\r
-       // assertEquals("TestUser1", uc.getLoggedUser().getUserName());\r
-       // }\r
-\r
        @Test\r
        public void getUserTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
 \r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.logIn("TestUser1", "pass1");\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();\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\r
-       public void logOutTest() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.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
-               uc.logIn("TestUser1", "pass1");\r
-               assertEquals("TestUser1", uc.getLoggedUserName());\r
-               uc.logOut();\r
-       }\r
-\r
-       @Test(expected = Exception.class)\r
-       public void logOutException1Test() throws Exception {\r
-               DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-\r
-               uc.logOut();\r
-       }\r
-\r
        @Test(expected = Exception.class)\r
-       public void logOutException2Test() throws Exception {\r
+       public void getUserExpectionTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = null;\r
 \r
-               uc.setDataHandler(dh);\r
-               uc.logOut();\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
-       @Test(expected = Exception.class)\r
-       public void getUserExpectionTest() throws Exception {\r
-               UserController uc = new UserController();\r
+               uc.setDataHandler(null);\r
                uc.getUser(null);\r
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
        @Test\r
        public void getReservationTests() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\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(2015, 11, 28, 11, 00, 00);\r
@@ -292,17 +127,19 @@ public class UserControllerTest {
                dh.addResource(resource2);\r
                dh.addResource(resource3);\r
 \r
-               User loggedUser = uc.getLoggedUser();\r
                User testUser2 = uc.getUser("TestUser2");\r
 \r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\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
+               Reservation reservation4 = new Reservation(UUID.randomUUID(), testUser2, resource3, dateRange,\r
+                               "Test reservation3");\r
                dh.addReservation(reservation1);\r
                dh.addReservation(reservation2);\r
                dh.addReservation(reservation3);\r
+               dh.addReservation(reservation4);\r
 \r
                Map<Reservation, Boolean> loggedUserReservation = uc.getUserReservations(null);\r
                Map<Reservation, Boolean> reservationMap = uc.getUserReservations(testUser2);\r
@@ -330,68 +167,92 @@ public class UserControllerTest {
 \r
        @Test(expected = Exception.class)\r
        public void getReservationGroupException1Test() throws Exception {\r
-               UserController uc = new UserController();\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = new UserController(dh, sc);\r
+\r
+               uc.setDataHandler(null);\r
                uc.getReservationGroup(null);\r
        }\r
 \r
        @Test(expected = IllegalArgumentException.class)\r
        public void getReservationGroupException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\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
-               UserController uc = new UserController();\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController sc = new SessionController(dh);\r
+               UserController uc = new UserController(dh, sc);\r
+\r
+               uc.setDataHandler(null);\r
                uc.getUserReservations(null);\r
        }\r
 \r
        @Test(expected = Exception.class)\r
        public void getUserReservationException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\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
-               UserController uc = new UserController();\r
+               DataHandler dh = new DataHandlerForTests();\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();\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();\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();\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
+       @SuppressWarnings("deprecation")\r
        @Test\r
        public void makeReservationTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-               uc.logIn("TestUser1", "pass1");\r
+               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
@@ -405,18 +266,24 @@ 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
+       @SuppressWarnings("deprecation")\r
        @Test\r
        public void makeInvalidReservationTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-               uc.logIn("TestUser1", "pass1");\r
+               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
@@ -441,18 +308,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();\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
@@ -466,18 +339,24 @@ 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
+       @SuppressWarnings("deprecation")\r
        @Test(expected = IllegalArgumentException.class)\r
        public void makeReservationException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-               uc.logIn("TestUser1", "pass1");\r
+               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
@@ -494,14 +373,20 @@ public class UserControllerTest {
                assertEquals(null, uc.makeReservation(null, null, dtList, "remark"));\r
        }\r
 \r
-       @Test(expected = IllegalArgumentException.class)\r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
        public void makeReservationException3Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-               uc.logIn("TestUser1", "pass1");\r
+               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
@@ -515,17 +400,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();\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
@@ -539,14 +429,50 @@ public class UserControllerTest {
                assertEquals(null, uc.makeReservation(null, resource1, dtList, "remark"));\r
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
+       @Test(expected = Exception.class)\r
+       public void makeReservationException5Test() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\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
+               Resource resource3 = new Resource("Room101", "Class room");\r
+               dh.addResource(resource1);\r
+               dh.addResource(resource2);\r
+               dh.addResource(resource3);\r
+\r
+               List<DateRange> dtList = new ArrayList<DateRange>();\r
+               for (int i = 1; i < 10; i++) {\r
+                       dtList.add(new DateRangeImpl(new Date(2015, 12, 2 + i, 11, 00, 00), new Date(2015, 12, 2 + i, 12, 00, 00)));\r
+               }\r
+\r
+               assertEquals(null, uc.makeReservation(null, resource1, null, "remark"));\r
+       }\r
+\r
+       @SuppressWarnings("deprecation")\r
        @Test\r
        public void changeReservationTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-               uc.logIn("TestUser1", "pass1");\r
+               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
@@ -554,10 +480,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               User loggedUser = uc.getLoggedUser();\r
-               User testUser2 = uc.getUser("TestUser2");\r
-\r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -570,14 +493,20 @@ public class UserControllerTest {
                assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
        @Test(expected = Exception.class)\r
        public void changeReservationException1Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\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
@@ -589,10 +518,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               User loggedUser = uc.getLoggedUser();\r
-               User testUser2 = uc.getUser("TestUser2");\r
-\r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -608,14 +534,20 @@ public class UserControllerTest {
                assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
        @Test(expected = Exception.class)\r
        public void changeReservationException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\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
@@ -627,10 +559,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               User loggedUser = uc.getLoggedUser();\r
-               User testUser2 = uc.getUser("TestUser2");\r
-\r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -640,20 +569,26 @@ 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
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
        @Test(expected = IllegalArgumentException.class)\r
        public void changeReservationException3Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\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
@@ -665,10 +600,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               User loggedUser = uc.getLoggedUser();\r
-               User testUser2 = uc.getUser("TestUser2");\r
-\r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -683,14 +615,20 @@ public class UserControllerTest {
                assertEquals(newDateRange, uc.getReservation(reservationClone.getId()).getDateRange());\r
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
        @Test(expected = Exception.class)\r
        public void changeReservationException4Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               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
@@ -702,10 +640,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               User loggedUser = uc.getLoggedUser();\r
-               User testUser2 = uc.getUser("TestUser2");\r
-\r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -715,21 +650,27 @@ 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
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
        @Test\r
        public void deleteReservationTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-               uc.logIn("TestUser1", "pass1");\r
+               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
@@ -741,10 +682,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               User loggedUser = uc.getLoggedUser();\r
-               User testUser2 = uc.getUser("TestUser2");\r
-\r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -753,14 +691,20 @@ public class UserControllerTest {
                assertEquals(null, uc.getReservation(reservation1.getId()));\r
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
        @Test(expected = Exception.class)\r
        public void deleteReservationException1Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\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
@@ -772,10 +716,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               User loggedUser = uc.getLoggedUser();\r
-               User testUser2 = uc.getUser("TestUser2");\r
-\r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -785,14 +726,20 @@ public class UserControllerTest {
                assertEquals(null, uc.getReservation(reservation1.getId()));\r
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
        @Test(expected = Exception.class)\r
        public void deleteReservationException2Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\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
@@ -804,27 +751,30 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               User loggedUser = uc.getLoggedUser();\r
-               User testUser2 = uc.getUser("TestUser2");\r
-\r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\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
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
        @Test(expected = IllegalArgumentException.class)\r
        public void deleteReservationException3Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\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
@@ -836,10 +786,7 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               User loggedUser = uc.getLoggedUser();\r
-               User testUser2 = uc.getUser("TestUser2");\r
-\r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\r
+               Reservation reservation1 = new Reservation(groupId, sc.getLoggedUser(), resource1, dateRange,\r
                                "Test reservation1");\r
                dh.addReservation(reservation1);\r
 \r
@@ -848,14 +795,20 @@ public class UserControllerTest {
                assertEquals(null, uc.getReservation(reservation1.getId()));\r
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
        @Test(expected = Exception.class)\r
        public void deleteReservationException4Test() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\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
@@ -867,28 +820,31 @@ public class UserControllerTest {
                Resource resource1 = new Resource("Room101", "Class room");\r
                dh.addResource(resource1);\r
 \r
-               User loggedUser = uc.getLoggedUser();\r
-               User testUser2 = uc.getUser("TestUser2");\r
-\r
-               Reservation reservation1 = new Reservation(groupId, uc.getLoggedUser(), resource1, dateRange,\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
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
        @Test\r
        public void getResourcesTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\r
-               uc.setDataHandler(dh);\r
-               uc.addUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
-               uc.addUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
-               uc.logIn("TestUser1", "pass1");\r
+               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
@@ -907,14 +863,20 @@ public class UserControllerTest {
                assertEquals(3, resList.size());\r
        }\r
 \r
+       @SuppressWarnings("deprecation")\r
        @Test(expected = Exception.class)\r
        public void getResourcesExceptionTest() throws Exception {\r
                DataHandler dh = new DataHandlerForTests();\r
-               UserController uc = new UserController();\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
index bb3737c..fbca7c3 100644 (file)
@@ -8,6 +8,8 @@
 package ch.bfh.ti.srs.datahandler;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
@@ -308,4 +310,71 @@ public class DataHandlerForTestsTest {
 
                assertEquals(3, allReservations.size());
        }
+
+       @Test
+       public void editUserTest() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+               dh.addUser(new User("TestUser1", "pass1"));
+               assertTrue(dh.editUser(new User("TestUser1", "pass1")));
+       }
+
+       @Test(expected = IllegalArgumentException.class)
+       public void editUserException1Test() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+
+               dh.editUser(null);
+       }
+
+       @Test
+       public void editUserException2Test() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+               dh.addUser(new User("TestUser1", "pass1"));
+               assertFalse(dh.editUser(new User("TestUser2", "pass1")));
+       }
+
+       @Test
+       public void deleteResourceTest() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+
+               Resource res = new Resource("Room1", "Testroom");
+               dh.addResource(res);
+               dh.deleteResource(res);
+       }
+
+       @Test(expected = IllegalArgumentException.class)
+       public void deleteResourceExceptionTest() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+
+               dh.deleteResource(null);
+       }
+
+       @Test
+       public void deleteResourceException1Test() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+
+               dh.deleteResource(new Resource("Room1", "Testroom"));
+       }
+
+       @Test
+       public void editResourceTest() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+
+               Resource res = new Resource("Room1", "Testroom");
+               dh.addResource(res);
+               dh.editResource(res);
+       }
+
+       @Test(expected = IllegalArgumentException.class)
+       public void editResourceExceptionTest() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+
+               dh.editResource(null);
+       }
+
+       @Test
+       public void editResourceException1Test() throws Exception {
+               DataHandlerForTests dh = new DataHandlerForTests();
+
+               dh.editResource(new Resource("Room1", "Testroom"));
+       }
 }
index c4c7a39..05256a2 100644 (file)
@@ -8,7 +8,9 @@
 package ch.bfh.ti.srs.dataschema;\r
 \r
 import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
 import static org.junit.Assert.assertNotEquals;\r
+import static org.junit.Assert.assertTrue;\r
 \r
 import java.util.UUID;\r
 \r
@@ -51,6 +53,22 @@ public class ReservationTest {
                assertEquals("TestReservation", testReservation.getRemark());\r
        }\r
 \r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void createReservationInvalidUserTest() throws Exception {\r
+               Resource testResource = new Resource("N321", "class room");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
+                               DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), null, testResource, testDr, "TestReservation");\r
+       }\r
+\r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void createReservationInvalidResourceTest() throws Exception {\r
+               User testUser = new User("TestUser", "pass");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
+                               DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, null, testDr, "TestReservation");\r
+       }\r
+\r
        @Test\r
        public void setAndGetNameTest() throws Exception {\r
                User testUser = new User("TestUser", "pass");\r
@@ -87,9 +105,9 @@ public class ReservationTest {
                Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
                                "TestReservation");\r
 \r
-               Resource OtherTestResource = new Resource("N421", "lecture hall");\r
-               testReservation.setResource(OtherTestResource);\r
-               assertEquals(OtherTestResource, testReservation.getResource());\r
+               Resource otherTestResource = new Resource("N421", "lecture hall");\r
+               testReservation.setResource(otherTestResource);\r
+               assertEquals(otherTestResource, testReservation.getResource());\r
        }\r
 \r
        @Test\r
@@ -106,4 +124,44 @@ public class ReservationTest {
                testReservation.setDateRange(otherTestDr);\r
                assertEquals(otherTestDr, testReservation.getDateRange());\r
        }\r
+\r
+       @Test\r
+       public void isModifiedTest() throws Exception {\r
+               User testUser = new User("TestUser", "pass");\r
+               Resource testResource = new Resource("N321", "class room");\r
+               DateRange testDr = factory.createDateRange(DateFactory.createDate(2015, 11, 9),\r
+                               DateFactory.createDate(2015, 11, 13));\r
+               Reservation testReservation = new Reservation(UUID.randomUUID(), testUser, testResource, testDr,\r
+                               "TestReservation");\r
+               Reservation clonedTestReservation = testReservation.clone();\r
+\r
+               assertTrue(testReservation.isModified(null));\r
+               assertFalse(testReservation.isModified(testReservation));\r
+               assertFalse(testReservation.isModified(clonedTestReservation));\r
+\r
+               User otherTestUser = new User("otherTestUser", "pass");\r
+               clonedTestReservation.setUser(otherTestUser);\r
+               assertTrue(testReservation.isModified(clonedTestReservation));\r
+\r
+               clonedTestReservation.setUser(testUser);\r
+               assertFalse(testReservation.isModified(clonedTestReservation));\r
+\r
+               Resource otherTestResource = new Resource("N421", "lecture hall");\r
+               clonedTestReservation.setResource(otherTestResource);\r
+               assertTrue(testReservation.isModified(clonedTestReservation));\r
+\r
+               clonedTestReservation.setResource(testResource);\r
+               assertFalse(testReservation.isModified(clonedTestReservation));\r
+\r
+               DateRange otherTestDr = factory.createDateRange(DateFactory.createDate(2015, 12, 9),\r
+                               DateFactory.createDate(2015, 12, 13));\r
+               clonedTestReservation.setDateRange(otherTestDr);\r
+               assertTrue(testReservation.isModified(clonedTestReservation));\r
+\r
+               clonedTestReservation.setDateRange(testDr);\r
+               assertFalse(testReservation.isModified(clonedTestReservation));\r
+\r
+               clonedTestReservation.setRemark("some other remark");\r
+               assertTrue(testReservation.isModified(clonedTestReservation));\r
+       }\r
 }\r
index 6e5b1f6..f582f66 100644 (file)
@@ -8,7 +8,9 @@
 package ch.bfh.ti.srs.dataschema;\r
 \r
 import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
 import static org.junit.Assert.assertNotEquals;\r
+import static org.junit.Assert.assertTrue;\r
 \r
 import org.junit.Test;\r
 \r
@@ -31,11 +33,11 @@ public class ResourceTest {
 \r
        @Test\r
        public void setAndGetNameTest() throws Exception {\r
-               Resource testRessource = new Resource("N321", "class room");\r
-               testRessource.setName("N421");\r
-               assertEquals("N421", testRessource.getName());\r
-               testRessource.setName(null);\r
-               assertEquals(null, testRessource.getName());\r
+               Resource testResource = new Resource("N321", "class room");\r
+               testResource.setName("N421");\r
+               assertEquals("N421", testResource.getName());\r
+               testResource.setName(null);\r
+               assertEquals(null, testResource.getName());\r
        }\r
 \r
        @Test\r
@@ -46,4 +48,20 @@ public class ResourceTest {
                testRessource.setType(null);\r
                assertEquals(null, testRessource.getType());\r
        }\r
+\r
+       @Test\r
+       public void isModifiedTest() throws Exception {\r
+               Resource testResource = new Resource("N321", "class room");\r
+               Resource clonedTestResource = testResource.clone();\r
+\r
+               assertFalse(testResource.isModified(clonedTestResource));\r
+               assertTrue(testResource.isModified(null));\r
+               assertFalse(testResource.isModified(testResource));\r
+               clonedTestResource.setName("N421");\r
+               assertTrue(testResource.isModified(clonedTestResource));\r
+               clonedTestResource.setName("N321");\r
+               assertFalse(testResource.isModified(clonedTestResource));\r
+               clonedTestResource.setType("lecture hall");\r
+               assertTrue(testResource.isModified(clonedTestResource));\r
+       }\r
 }\r
index 51696d3..91d82e9 100644 (file)
@@ -11,9 +11,10 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;\r
 import static org.junit.Assert.assertTrue;\r
 \r
+import java.util.Set;\r
+\r
 import org.junit.Test;\r
 \r
-import ch.bfh.ti.srs.dataschema.User;\r
 import ch.bfh.ti.srs.extern.Password;\r
 \r
 /**\r
@@ -160,4 +161,38 @@ public class UserTest {
                testUser.setLastname(null);\r
                assertEquals(null, testUser.getLastname());\r
        }\r
+\r
+       @Test\r
+       public void RoleTest() throws Exception {\r
+               User testUser = new User("TestUser", "pass");\r
+               Set<Role> roles = testUser.getRoles();\r
+               assertTrue(roles.contains(Role.User));\r
+               assertFalse(roles.contains(Role.ResourceManager));\r
+               assertFalse(roles.contains(Role.Admin));\r
+\r
+               testUser.addRole(Role.ResourceManager);\r
+               roles = testUser.getRoles();\r
+               assertTrue(roles.contains(Role.User));\r
+               assertTrue(roles.contains(Role.ResourceManager));\r
+               assertFalse(roles.contains(Role.Admin));\r
+\r
+               testUser.removeRole(Role.User);\r
+               roles = testUser.getRoles();\r
+               assertFalse(roles.contains(Role.User));\r
+               assertTrue(roles.contains(Role.ResourceManager));\r
+               assertFalse(roles.contains(Role.Admin));\r
+\r
+               testUser.removeRole(Role.Admin);\r
+               roles = testUser.getRoles();\r
+               assertFalse(roles.contains(Role.User));\r
+               assertTrue(roles.contains(Role.ResourceManager));\r
+               assertFalse(roles.contains(Role.Admin));\r
+       }\r
+\r
+       @Test\r
+       public void cloneTest() throws Exception {\r
+               User testUser = new User("TestUser", "pass");\r
+               User clonedUser = testUser.clone();\r
+               assertEquals(testUser.getUserName(), clonedUser.getUserName());\r
+       }\r
 }\r