Added Javadoc to ResourceManager Controller
authorMoritz Trittibach <tritm3@bfh.ch>
Sun, 10 Jan 2016 00:49:28 +0000 (01:49 +0100)
committerMoritz Trittibach <tritm3@bfh.ch>
Sun, 10 Jan 2016 00:49:28 +0000 (01:49 +0100)
src/main/java/ch/bfh/ti/srs/controller/ResourceManagerController.java
src/test/java/ch/bfh/ti/srs/controller/ResourceManagerControllerTest.java

index 9337355..ed52f5b 100644 (file)
@@ -16,15 +16,41 @@ public class ResourceManagerController extends Controller {
        public ResourceManagerController(DataHandler dh, SessionController sc) {\r
                super(dh, sc);\r
        }\r
-       \r
-       public boolean addResource(Resource resource) throws Exception {\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 (resource == null)\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>\r
+        * referring 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
@@ -33,6 +59,18 @@ public class ResourceManagerController extends Controller {
                return dh.editResource(resource);\r
        }\r
        \r
+       /**\r
+        * Deletes the given resource in the set <code>DataHandler</code>\r
+        * referring 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
index 1a71767..d2a4d38 100644 (file)
@@ -21,9 +21,8 @@ public class ResourceManagerControllerTest {
                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(testResource);\r
+               rmc.addResource("N321", "class room");\r
        }\r
        \r
        @Test\r
@@ -33,7 +32,7 @@ public class ResourceManagerControllerTest {
                ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
                Resource testResource = new Resource("N321", "class room");\r
                \r
-               rmc.addResource(testResource);\r
+               rmc.addResource("N321", "class room");\r
                testResource.setType("lecture hall");\r
                rmc.changeResource(testResource);\r
        }\r
@@ -45,7 +44,7 @@ public class ResourceManagerControllerTest {
                ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
                Resource testResource = new Resource("N321", "class room");\r
                \r
-               rmc.addResource(testResource);\r
+               rmc.addResource("N321", "class room");\r
                rmc.deleteResource(testResource);\r
        }\r
        \r
@@ -54,9 +53,8 @@ public class ResourceManagerControllerTest {
                DataHandler dh = new DataHandlerForTests();\r
                SessionController  sc = new SessionController(dh);\r
                ResourceManagerController rmc = new ResourceManagerController(null, sc);\r
-               Resource testResource = new Resource("N321", "class room");\r
                \r
-               rmc.addResource(testResource);\r
+               rmc.addResource("N321", "class room");\r
                \r
        }\r
        \r
@@ -65,9 +63,8 @@ public class ResourceManagerControllerTest {
                DataHandler dh = new DataHandlerForTests();\r
                SessionController  sc = new SessionController(dh);\r
                ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
-               Resource testResource = null;\r
                \r
-               rmc.addResource(testResource);\r
+               rmc.addResource(null, null);\r
        }\r
        \r
        @Test(expected = Exception.class)\r
@@ -78,7 +75,7 @@ public class ResourceManagerControllerTest {
                ResourceManagerController rmc2 = new ResourceManagerController(null, sc);\r
                Resource testResource = new Resource("N321", "class room");\r
                \r
-               rmc1.addResource(testResource);\r
+               rmc1.addResource("N321", "class room");\r
                testResource.setType("lecture hall");\r
                rmc2.changeResource(testResource);\r
        }\r
@@ -90,7 +87,7 @@ public class ResourceManagerControllerTest {
                ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
                Resource testResource = new Resource("N321", "class room");\r
                \r
-               rmc.addResource(testResource);\r
+               rmc.addResource("N321", "class room");\r
                testResource = null;\r
                rmc.changeResource(testResource);\r
        }\r
@@ -103,7 +100,7 @@ public class ResourceManagerControllerTest {
                ResourceManagerController rmc2 = new ResourceManagerController(null, sc);\r
                Resource testResource = new Resource("N321", "class room");\r
                \r
-               rmc1.addResource(testResource);\r
+               rmc1.addResource("N321", "class room");\r
                rmc2.deleteResource(testResource);\r
                \r
        }\r
@@ -115,7 +112,7 @@ public class ResourceManagerControllerTest {
                ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
                Resource testResource = new Resource("N321", "class room");\r
                \r
-               rmc.addResource(testResource);\r
+               rmc.addResource("N321", "class room");\r
                testResource = null;\r
                rmc.deleteResource(testResource);\r
        }\r