ResourceManagerControllerTest completed
authorMoritz Trittibach <tritm3@bfh.ch>
Tue, 15 Dec 2015 09:33:27 +0000 (10:33 +0100)
committerMoritz Trittibach <tritm3@bfh.ch>
Tue, 15 Dec 2015 09:33:27 +0000 (10:33 +0100)
src/test/java/ch/bfh/ti/srs/controller/ResourceManagerControllerTest.java
src/test/java/ch/bfh/ti/srs/dataschema/ResourceTest.java

index 6d40293..4fcb251 100644 (file)
@@ -7,6 +7,116 @@
  */\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
+       \r
+       @Test\r
+       public void AddResourceTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController  sc = new SessionController();\r
+               ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
+               Resource testResource = new Resource("N321", "class room");\r
+               \r
+               rmc.addResource(testResource);\r
+       }\r
+       \r
+       @Test\r
+       public void ChangeResourceTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController  sc = new SessionController();\r
+               ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
+               Resource testResource = new Resource("N321", "class room");\r
+               \r
+               rmc.addResource(testResource);\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();\r
+               ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
+               Resource testResource = new Resource("N321", "class room");\r
+               \r
+               rmc.addResource(testResource);\r
+               rmc.deleteResource(testResource);\r
+       }\r
+       \r
+       @Test(expected = Exception.class)\r
+       public void AddResourceInvalidDatahandlerTest() throws Exception {\r
+               SessionController  sc = new SessionController();\r
+               ResourceManagerController rmc = new ResourceManagerController(null, sc);\r
+               Resource testResource = new Resource("N321", "class room");\r
+               \r
+               rmc.addResource(testResource);\r
+               \r
+       }\r
+       \r
+       @Test(expected = IllegalArgumentException.class)\r
+       public void AddResourceInvalidResourceTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController  sc = new SessionController();\r
+               ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
+               Resource testResource = null;\r
+               \r
+               rmc.addResource(testResource);\r
+       }\r
+       \r
+       @Test(expected = Exception.class)\r
+       public void ChangeResourceInvalidDatahandlerTest() throws Exception {\r
+               DataHandler dh = new DataHandlerForTests();\r
+               SessionController  sc = new SessionController();\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(testResource);\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();\r
+               ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
+               Resource testResource = new Resource("N321", "class room");\r
+               \r
+               rmc.addResource(testResource);\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();\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(testResource);\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();\r
+               ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
+               Resource testResource = new Resource("N321", "class room");\r
+               \r
+               rmc.addResource(testResource);\r
+               testResource = null;\r
+               rmc.deleteResource(testResource);\r
+       }\r
+       \r
 }\r
index 6114dbe..3e10260 100644 (file)
@@ -33,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
@@ -51,18 +51,18 @@ public class ResourceTest {
        \r
        @Test\r
        public void isModifiedTest() throws Exception {\r
-               Resource testRessource = new Resource("N321", "class room");\r
-               Resource clonedTestRessource = testRessource.clone();\r
+               Resource testResource = new Resource("N321", "class room");\r
+               Resource clonedTestResource = testResource.clone();\r
                \r
-               assertFalse(testRessource.isModified(clonedTestRessource));\r
-               assertTrue(testRessource.isModified(null));\r
-               assertFalse(testRessource.isModified(testRessource));\r
-               clonedTestRessource.setName("N421");\r
-               assertTrue(testRessource.isModified(clonedTestRessource));\r
-               clonedTestRessource.setName("N321");\r
-               assertFalse(testRessource.isModified(clonedTestRessource));\r
-               clonedTestRessource.setType("lecture hall");\r
-               assertTrue(testRessource.isModified(clonedTestRessource));\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
 \r