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