Search in sources :

Example 16 with FilterChain

use of javax.servlet.FilterChain in project neo4j by neo4j.

the class NoCacheHtmlFilterTest method shouldAddCacheControlHeaderToHtmlResponses.

@Test
public void shouldAddCacheControlHeaderToHtmlResponses() throws Exception {
    // given
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getServletPath()).thenReturn("index.html");
    HttpServletResponse response = mock(HttpServletResponse.class);
    FilterChain filterChain = mock(FilterChain.class);
    // when
    new NoCacheHtmlFilter().doFilter(request, response, filterChain);
    // then
    verify(response).addHeader("Cache-Control", "no-cache");
    verify(filterChain).doFilter(request, response);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test)

Example 17 with FilterChain

use of javax.servlet.FilterChain in project hadoop by apache.

the class TestCheckUploadContentTypeFilter method test.

private void test(String method, String operation, String contentType, boolean upload, boolean error) throws Exception {
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    Mockito.reset(request);
    Mockito.when(request.getMethod()).thenReturn(method);
    Mockito.when(request.getParameter(HttpFSFileSystem.OP_PARAM)).thenReturn(operation);
    Mockito.when(request.getParameter(HttpFSParametersProvider.DataParam.NAME)).thenReturn(Boolean.toString(upload));
    Mockito.when(request.getContentType()).thenReturn(contentType);
    FilterChain chain = Mockito.mock(FilterChain.class);
    Filter filter = new CheckUploadContentTypeFilter();
    filter.doFilter(request, response, chain);
    if (error) {
        Mockito.verify(response).sendError(Mockito.eq(HttpServletResponse.SC_BAD_REQUEST), Mockito.contains("Data upload"));
    } else {
        Mockito.verify(chain).doFilter(request, response);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Filter(javax.servlet.Filter) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 18 with FilterChain

use of javax.servlet.FilterChain in project OpenAM by OpenRock.

the class XUIFilterTest method loginRedirectsToXUIWithQuery.

@Test
public void loginRedirectsToXUIWithQuery() throws Exception {
    String pathInfo = "/UI/Login";
    String query = "locale=fr&realm=/";
    String xuiLoginPath = "/XUI/#login/";
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse responseLogin = mock(HttpServletResponse.class);
    FilterChain filterChain = mock(FilterChain.class);
    when(request.getRequestURI()).thenReturn(pathInfo);
    when(request.getQueryString()).thenReturn(query);
    filter.doFilter(request, responseLogin, filterChain);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(responseLogin).sendRedirect(captor.capture());
    assertThat(captor.getValue()).isEqualTo(CONTEXT + xuiLoginPath + "&" + query);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Example 19 with FilterChain

use of javax.servlet.FilterChain in project OpenAM by OpenRock.

the class XUIFilterTest method testLogout.

@Test
public void testLogout() throws Exception {
    String xuiLogoutPath = "/XUI/#logout/";
    String logoutPath = "/UI/Logout";
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse responseLogout = mock(HttpServletResponse.class);
    FilterChain filterChain = mock(FilterChain.class);
    when(request.getRequestURI()).thenReturn(logoutPath);
    when(request.getQueryString()).thenReturn(null);
    filter.doFilter(request, responseLogout, filterChain);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(responseLogout).sendRedirect(captor.capture());
    assertThat(captor.getValue()).isEqualTo(CONTEXT + xuiLogoutPath);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Example 20 with FilterChain

use of javax.servlet.FilterChain in project OpenAM by OpenRock.

the class XUIFilterTest method testEndUserPage.

@Test
public void testEndUserPage() throws Exception {
    String profilePage = "/XUI/#profile/";
    String endUserPath = "/idm/EndUser";
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse responseEndUser = mock(HttpServletResponse.class);
    FilterChain filterChain = mock(FilterChain.class);
    when(request.getRequestURI()).thenReturn(endUserPath);
    when(request.getQueryString()).thenReturn(null);
    filter.doFilter(request, responseEndUser, filterChain);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(responseEndUser).sendRedirect(captor.capture());
    assertThat(captor.getValue()).isEqualTo(CONTEXT + profilePage);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Aggregations

FilterChain (javax.servlet.FilterChain)418 HttpServletRequest (javax.servlet.http.HttpServletRequest)317 HttpServletResponse (javax.servlet.http.HttpServletResponse)269 Test (org.junit.Test)246 ServletResponse (javax.servlet.ServletResponse)135 ServletRequest (javax.servlet.ServletRequest)118 FilterConfig (javax.servlet.FilterConfig)80 Filter (javax.servlet.Filter)68 ServletException (javax.servlet.ServletException)54 IOException (java.io.IOException)48 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)46 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)46 Injector (com.google.inject.Injector)32 ServletTestUtils.newFakeHttpServletRequest (com.google.inject.servlet.ServletTestUtils.newFakeHttpServletRequest)25 ServletContext (javax.servlet.ServletContext)25 Test (org.testng.annotations.Test)25 HttpSession (javax.servlet.http.HttpSession)24 MockFilterChain (org.springframework.mock.web.MockFilterChain)24 InvocationOnMock (org.mockito.invocation.InvocationOnMock)22 Properties (java.util.Properties)19