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