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