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