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();
      }
8d282680   Julien Iguchi-Cartigny   fixing tests with...
25
  
aa193b2b   Julien Iguchi-Cartigny   First version
26
27
      @Test
      public void checkPreHandleServletPathIsLogin() throws IOException {
8d282680   Julien Iguchi-Cartigny   fixing tests with...
28
          request.setServletPath("/login");
aa193b2b   Julien Iguchi-Cartigny   First version
29
30
31
32
33
34
          assertTrue(interceptor.preHandle(request, response, null));
      }
  
      @Test
      public void checkPreHandleUsernameInSession() throws IOException {
          userSession.setUsername("admin");
8d282680   Julien Iguchi-Cartigny   fixing tests with...
35
          request.setServletPath("/blabla");
aa193b2b   Julien Iguchi-Cartigny   First version
36
37
38
39
40
          assertTrue(interceptor.preHandle(request, response, null));
      }
  
      @Test
      public void checkPreHandleUsernameNotInSession() throws IOException {
8d282680   Julien Iguchi-Cartigny   fixing tests with...
41
          request.setServletPath("/blabla");
aa193b2b   Julien Iguchi-Cartigny   First version
42
43
44
          assertFalse(interceptor.preHandle(request, response, null));
          assertEquals(response.getRedirectedUrl(),"login");
      }
aa193b2b   Julien Iguchi-Cartigny   First version
45
  }