Пример #1
0
  @Test
  public void handleRequest_nullChain() throws Exception {
    compressionHandler.setFilterChain(null);

    FilterDirector director = compressionHandler.handleRequest(request, response);

    assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.intValue(), director.getResponseStatusCode());
    assertThat(director.getFilterAction(), equalTo(FilterAction.RETURN));
  }
Пример #2
0
  @Test
  public void handleRequest_validRequest() throws Exception {
    compressionHandler.setFilterChain(filterChain);
    doNothing().when(compressingFilter, "doFilter", request, response, filterChain);
    when(response.getStatus()).thenReturn(200);

    FilterDirector director = compressionHandler.handleRequest(request, response);

    assertEquals(HttpStatusCode.OK.intValue(), director.getResponseStatusCode());
    assertThat(director.getFilterAction(), equalTo(FilterAction.RETURN));
  }
Пример #3
0
  @Test
  public void handleRequest_handleGenericIOError() throws Exception {
    compressionHandler.setFilterChain(filterChain);
    doThrow(new IOException())
        .when(compressingFilter)
        .doFilter(any(ServletRequest.class), any(ServletResponse.class), any(FilterChain.class));

    FilterDirector director = compressionHandler.handleRequest(request, response);

    assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.intValue(), director.getResponseStatusCode());
    assertThat(director.getFilterAction(), equalTo(FilterAction.RETURN));
  }
Пример #4
0
  @Test
  public void handleRequest_handleGZIPError() throws Exception {
    compressionHandler.setFilterChain(filterChain);
    doThrow(new ZipException("Not in GZIP format"))
        .when(compressingFilter)
        .doFilter(any(ServletRequest.class), any(ServletResponse.class), any(FilterChain.class));

    FilterDirector director = compressionHandler.handleRequest(request, response);

    assertEquals(HttpStatusCode.BAD_REQUEST.intValue(), director.getResponseStatusCode());
    assertThat(director.getFilterAction(), equalTo(FilterAction.RETURN));
  }