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