SessionController added/updated
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / controller / ResourceManagerControllerTest.java
CommitLineData
5fca88b4
MT
1/*\r
2 * Copyright (c) 2015 Berner Fachhochschule, Switzerland.\r
3 *\r
4 * Project Smart Reservation System.\r
5 *\r
6 * Distributable under GPL license. See terms of license at gnu.org.\r
7 */\r
8package ch.bfh.ti.srs.controller;\r
9\r
9b024b7c
MT
10import org.junit.Test;\r
11\r
12import ch.bfh.ti.srs.datahandler.DataHandler;\r
13import ch.bfh.ti.srs.datahandler.DataHandlerForTests;\r
14import ch.bfh.ti.srs.dataschema.Resource;\r
15\r
5fca88b4
MT
16public class ResourceManagerControllerTest {\r
17\r
9b024b7c
MT
18 \r
19 @Test\r
20 public void AddResourceTest() throws Exception {\r
21 DataHandler dh = new DataHandlerForTests();\r
30d10517 22 SessionController sc = new SessionController(dh);\r
9b024b7c
MT
23 ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
24 Resource testResource = new Resource("N321", "class room");\r
25 \r
26 rmc.addResource(testResource);\r
27 }\r
28 \r
29 @Test\r
30 public void ChangeResourceTest() throws Exception {\r
31 DataHandler dh = new DataHandlerForTests();\r
30d10517 32 SessionController sc = new SessionController(dh);\r
9b024b7c
MT
33 ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
34 Resource testResource = new Resource("N321", "class room");\r
35 \r
36 rmc.addResource(testResource);\r
37 testResource.setType("lecture hall");\r
38 rmc.changeResource(testResource);\r
39 }\r
40 \r
41 @Test\r
42 public void DeleteResourceTest() throws Exception {\r
43 DataHandler dh = new DataHandlerForTests();\r
30d10517 44 SessionController sc = new SessionController(dh);\r
9b024b7c
MT
45 ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
46 Resource testResource = new Resource("N321", "class room");\r
47 \r
48 rmc.addResource(testResource);\r
49 rmc.deleteResource(testResource);\r
50 }\r
51 \r
52 @Test(expected = Exception.class)\r
53 public void AddResourceInvalidDatahandlerTest() throws Exception {\r
30d10517
M
54 DataHandler dh = new DataHandlerForTests();\r
55 SessionController sc = new SessionController(dh);\r
9b024b7c
MT
56 ResourceManagerController rmc = new ResourceManagerController(null, sc);\r
57 Resource testResource = new Resource("N321", "class room");\r
58 \r
59 rmc.addResource(testResource);\r
60 \r
61 }\r
62 \r
63 @Test(expected = IllegalArgumentException.class)\r
64 public void AddResourceInvalidResourceTest() throws Exception {\r
65 DataHandler dh = new DataHandlerForTests();\r
30d10517 66 SessionController sc = new SessionController(dh);\r
9b024b7c
MT
67 ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
68 Resource testResource = null;\r
69 \r
70 rmc.addResource(testResource);\r
71 }\r
72 \r
73 @Test(expected = Exception.class)\r
74 public void ChangeResourceInvalidDatahandlerTest() throws Exception {\r
75 DataHandler dh = new DataHandlerForTests();\r
30d10517 76 SessionController sc = new SessionController(dh);\r
9b024b7c
MT
77 ResourceManagerController rmc1 = new ResourceManagerController(dh, sc);\r
78 ResourceManagerController rmc2 = new ResourceManagerController(null, sc);\r
79 Resource testResource = new Resource("N321", "class room");\r
80 \r
81 rmc1.addResource(testResource);\r
82 testResource.setType("lecture hall");\r
83 rmc2.changeResource(testResource);\r
84 }\r
85 \r
86 @Test(expected = IllegalArgumentException.class)\r
87 public void ChangeResourceInvalidResourceTest() throws Exception {\r
88 DataHandler dh = new DataHandlerForTests();\r
30d10517 89 SessionController sc = new SessionController(dh);\r
9b024b7c
MT
90 ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
91 Resource testResource = new Resource("N321", "class room");\r
92 \r
93 rmc.addResource(testResource);\r
94 testResource = null;\r
95 rmc.changeResource(testResource);\r
96 }\r
97 \r
98 @Test(expected = Exception.class)\r
99 public void DeleteResourceInvalidDatahandlerTest() throws Exception {\r
100 DataHandler dh = new DataHandlerForTests();\r
30d10517 101 SessionController sc = new SessionController(dh);\r
9b024b7c
MT
102 ResourceManagerController rmc1 = new ResourceManagerController(dh, sc);\r
103 ResourceManagerController rmc2 = new ResourceManagerController(null, sc);\r
104 Resource testResource = new Resource("N321", "class room");\r
105 \r
106 rmc1.addResource(testResource);\r
107 rmc2.deleteResource(testResource);\r
108 \r
109 }\r
110 \r
111 @Test(expected = IllegalArgumentException.class)\r
112 public void DeleteResourceInvalidResourceTest() throws Exception {\r
113 DataHandler dh = new DataHandlerForTests();\r
30d10517 114 SessionController sc = new SessionController(dh);\r
9b024b7c
MT
115 ResourceManagerController rmc = new ResourceManagerController(dh, sc);\r
116 Resource testResource = new Resource("N321", "class room");\r
117 \r
118 rmc.addResource(testResource);\r
119 testResource = null;\r
120 rmc.deleteResource(testResource);\r
121 }\r
122 \r
5fca88b4 123}\r