DataHandlerForTestsTest updated
[staff/due1/sed-hs15-srs-purple.git] / src / test / java / ch / bfh / ti / srs / controller / SessionControllerTest.java
CommitLineData
30d10517
M
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
10import static org.junit.Assert.assertEquals;\r
11import static org.junit.Assert.assertFalse;\r
12import static org.junit.Assert.assertTrue;\r
13\r
14import java.util.Set;\r
15\r
16import org.junit.Test;\r
17\r
18import ch.bfh.ti.srs.datahandler.DataHandler;\r
19import ch.bfh.ti.srs.datahandler.DataHandlerForTests;\r
20import ch.bfh.ti.srs.dataschema.Role;\r
21import ch.bfh.ti.srs.dataschema.User;\r
22\r
23public class SessionControllerTest {\r
24\r
25 \r
26 @Test\r
27 public void logInTest() throws Exception {\r
28 DataHandler dh = new DataHandlerForTests();\r
29 SessionController sc = new SessionController(dh);\r
c1191616 30 SessionController sc2 = new SessionController(); //dummy, just to trigger this constructor..\r
30d10517 31\r
c1191616
M
32 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
33 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
34 sc.registUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
35 sc.registUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
30d10517
M
36 \r
37 Set<Controller> controllers = sc.logIn("TestUser3", "pass3");\r
38 assertFalse(controllers.isEmpty());\r
39 }\r
40\r
41 @Test(expected = Exception.class)\r
42 public void logInException1Test() throws Exception {\r
43 DataHandler dh = new DataHandlerForTests();\r
44 SessionController sc = new SessionController(dh);\r
30d10517 45\r
c1191616
M
46 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
47 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
30d10517
M
48\r
49 sc.logIn("TestUser1", "pass1");\r
50 sc.logIn("TestUser2", "pass2");\r
51 }\r
52\r
53 @Test(expected = Exception.class)\r
54 public void logInInvalidCredetialsTest() throws Exception {\r
55 DataHandler dh = new DataHandlerForTests();\r
56 SessionController sc = new SessionController(dh);\r
30d10517 57\r
c1191616
M
58 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
59 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
30d10517
M
60\r
61 sc.logIn("TestUser3", "pass3");\r
62 }\r
63\r
64 @SuppressWarnings("deprecation")\r
65 @Test\r
66 public void getLoggedUserNameTest() throws Exception {\r
67 DataHandler dh = new DataHandlerForTests();\r
68 SessionController sc = new SessionController(dh);\r
30d10517
M
69\r
70 //uc.setDataHandler(dh);\r
c1191616
M
71 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
72 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
73 sc.registUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
74 sc.registUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
30d10517
M
75\r
76 sc.logIn("TestUser1", "pass1");\r
77 assertEquals("TestUser1", sc.getLoggedUserName());\r
78 }\r
79\r
80 @SuppressWarnings("deprecation")\r
81 @Test(expected = Exception.class)\r
82 public void getLoggedUserNameExceptionTest() throws Exception {\r
83 DataHandler dh = new DataHandlerForTests();\r
84 SessionController sc = new SessionController(dh);\r
85\r
86 sc.getLoggedUserName();\r
87 }\r
88\r
89 @SuppressWarnings("deprecation")\r
90 @Test\r
91 public void getLoggedUserMailTest() throws Exception {\r
92 DataHandler dh = new DataHandlerForTests();\r
93 SessionController sc = new SessionController(dh);\r
30d10517 94\r
c1191616
M
95 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
96 sc.registUser("TestUser2", "pass2", "hanfli@bfh.ch", null, null);\r
97 sc.registUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
98 sc.registUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
30d10517
M
99\r
100 sc.logIn("TestUser2", "pass2");\r
101 assertEquals("hanfli@bfh.ch", sc.getLoggedMail());\r
102 }\r
103\r
104 @SuppressWarnings("deprecation")\r
105 @Test(expected = Exception.class)\r
106 public void getLoggedMailExceptionTest() throws Exception {\r
107 DataHandler dh = new DataHandlerForTests();\r
108 SessionController sc = new SessionController(dh);\r
109\r
110 sc.getLoggedMail();\r
111 }\r
112\r
113 @SuppressWarnings("deprecation")\r
114 @Test\r
115 public void getLoggedNameTest() throws Exception {\r
116 DataHandler dh = new DataHandlerForTests();\r
117 SessionController sc = new SessionController(dh);\r
30d10517
M
118\r
119 //uc.setDataHandler(dh);\r
c1191616
M
120 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
121 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
122 sc.registUser("TestUser3", "pass3", "grosm9@bfh.ch", "Hanfli", null);\r
123 sc.registUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
30d10517
M
124\r
125 sc.logIn("TestUser3", "pass3");\r
126 assertEquals("Hanfli", sc.getLoggedName());\r
127 }\r
128\r
129 @SuppressWarnings("deprecation")\r
130 @Test(expected = Exception.class)\r
131 public void getLoggedNameExceptionTest() throws Exception {\r
132 DataHandler dh = new DataHandlerForTests();\r
133 SessionController sc = new SessionController(dh);\r
134\r
135 sc.getLoggedName();\r
136 }\r
137\r
138 @SuppressWarnings("deprecation")\r
139 @Test\r
140 public void getLoggedLastnameTest() throws Exception {\r
141 DataHandler dh = new DataHandlerForTests();\r
142 SessionController sc = new SessionController(dh);\r
30d10517
M
143\r
144 //uc.setDataHandler(dh);\r
c1191616
M
145 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
146 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
147 sc.registUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
148 sc.registUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
30d10517
M
149\r
150 sc.logIn("TestUser4", "pass4");\r
151 assertEquals("User", sc.getLoggedLastname());\r
152 }\r
153\r
154 @SuppressWarnings("deprecation")\r
155 @Test(expected = Exception.class)\r
156 public void getLoggedLastnameExceptionTest() throws Exception {\r
157 DataHandler dh = new DataHandlerForTests();\r
158 SessionController sc = new SessionController(dh);\r
159\r
160 sc.getLoggedLastname();\r
161 }\r
162\r
163 @Test\r
164 public void getLoggedUserTest() throws Exception {\r
165 DataHandler dh = new DataHandlerForTests();\r
166 SessionController sc = new SessionController(dh);\r
30d10517 167\r
c1191616 168 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
30d10517
M
169 assertEquals(null, sc.getLoggedUser());\r
170 sc.logIn("TestUser1", "pass1");\r
171 assertEquals("TestUser1", sc.getLoggedUser().getUserName());\r
172 }\r
173\r
174 @SuppressWarnings("deprecation")\r
175 @Test\r
176 public void logOutTest() throws Exception {\r
177 DataHandler dh = new DataHandlerForTests();\r
178 SessionController sc = new SessionController(dh);\r
30d10517
M
179\r
180 //uc.setDataHandler(dh);\r
c1191616
M
181 sc.registUser("TestUser1", "pass1", "grosm9@bfh.ch", null, null);\r
182 sc.registUser("TestUser2", "pass2", "grosm9@bfh.ch", null, null);\r
183 sc.registUser("TestUser3", "pass3", "grosm9@bfh.ch", "Test", null);\r
184 sc.registUser("TestUser4", "pass4", "grosm9@bfh.ch", "Test", "User");\r
30d10517
M
185\r
186 sc.logIn("TestUser1", "pass1");\r
187 assertEquals("TestUser1", sc.getLoggedUserName());\r
188 sc.logOut();\r
189 }\r
190\r
191 @Test(expected = Exception.class)\r
192 public void logOutException1Test() throws Exception {\r
193 DataHandler dh = new DataHandlerForTests();\r
194 SessionController sc = new SessionController(dh);\r
195\r
196 sc.logOut();\r
197 }\r
198\r
199 @Test(expected = Exception.class)\r
200 public void logOutException2Test() throws Exception {\r
201 DataHandler dh = new DataHandlerForTests();\r
202 SessionController sc = new SessionController(null);\r
203\r
204 sc.logOut();\r
205 }\r
206\r
207\r
208\r
209}\r