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