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