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