Blame view

src/test/java/fr/plil/sio/web/mvc/CheckUserInterceptorTest.java 1.44 KB
aa193b2b   Julien Iguchi-Cartigny   First version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  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();
      }
5e965ce4   Julien Iguchi-Cartigny   working version
25
  /*
aa193b2b   Julien Iguchi-Cartigny   First version
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
      @Test
      public void checkPreHandleServletPathIsLogin() throws IOException {
          request.setPathInfo("/login");
          assertTrue(interceptor.preHandle(request, response, null));
      }
  
      @Test
      public void checkPreHandleUsernameInSession() throws IOException {
          userSession.setUsername("admin");
          request.setPathInfo("/blabla");
          assertTrue(interceptor.preHandle(request, response, null));
      }
  
      @Test
      public void checkPreHandleUsernameNotInSession() throws IOException {
          request.setPathInfo("/blabla");
          assertFalse(interceptor.preHandle(request, response, null));
          assertEquals(response.getRedirectedUrl(),"login");
      }
5e965ce4   Julien Iguchi-Cartigny   working version
45
      */
aa193b2b   Julien Iguchi-Cartigny   First version
46
  }