CheckUserInterceptorTest.java
1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package fr.plil.sio.web.mvc;
import java.io.IOException;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
public class CheckUserInterceptorTest {
private CheckUserInterceptor interceptor;
private UserSession userSession;
private MockHttpServletRequest request;
private MockHttpServletResponse response;
@Before
public void createInstances() {
interceptor = new CheckUserInterceptor();
userSession = new UserSession();
interceptor.setUserSession(userSession);
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
}
@Test
public void checkPreHandleServletPathIsLogin() throws IOException {
request.setServletPath("/login");
assertTrue(interceptor.preHandle(request, response, null));
}
@Test
public void checkPreHandleUsernameInSession() throws IOException {
userSession.setUsername("admin");
request.setServletPath("/blabla");
assertTrue(interceptor.preHandle(request, response, null));
}
@Test
public void checkPreHandleUsernameNotInSession() throws IOException {
request.setServletPath("/blabla");
assertFalse(interceptor.preHandle(request, response, null));
assertEquals(response.getRedirectedUrl(),"login");
}
}