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