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