@Test
  public void testDoFilterGzipResponseCompression() throws Exception {
    MockHttpServletRequest request =
        new MockHttpServletRequest(HttpMethod.POST.name(), "http://localhost:8080/gzip");
    request.addHeader(HttpHeaders.ACCEPT_ENCODING, "gzip");

    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain filterChain =
        new MockFilterChain(
            servlet,
            new GzipServletFilter(),
            new OncePerRequestFilter() {
              @Override
              protected void doFilterInternal(
                  HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
                  throws ServletException, IOException {
                response.getOutputStream().write("Should be compressed".getBytes());
              }
            });
    filterChain.doFilter(request, response);

    ByteArrayOutputStream unzippedStream = new ByteArrayOutputStream();
    StreamUtils.copy(
        new GZIPInputStream(new ByteArrayInputStream(response.getContentAsByteArray())),
        unzippedStream);
    String unzipped = new String(unzippedStream.toByteArray());

    Assert.assertEquals(unzipped, "Should be compressed");
  }
  @Test
  public void testAttemptAuthentication() throws IOException, ServletException {
    VistaBasicAuthenticationFilter f = new VistaBasicAuthenticationFilter();
    f.setAuthenticationManager(mockAuthenticationManager);
    f.setAuthenticationEntryPoint(authenticationEntryPoint);
    f.afterPropertiesSet();

    String vistaId = "9F2B";
    String division = "500";
    String accessCode = "10VEHU";
    String verifyCode = "VEHU10";

    byte[] token =
        new String(vistaId + ";" + division + ":" + accessCode + ";" + verifyCode)
            .getBytes("UTF-8");
    request.addHeader("Authorization", "Basic " + new String(Base64.encodeBase64(token), "UTF-8"));
    request.setRemoteAddr("10.0.1.34");
    request.setRemoteHost("www.example.org");
    request.setRequestURI("/foo.xml");
    request.setMethod("GET");

    VistaAuthenticationToken authRequest =
        new VistaAuthenticationToken(
            "9F2B", "500", "10VEHU", "VEHU10", "10.0.1.34", "www.example.org");
    when(mockAuthenticationManager.authenticate(AuthenticationTokenMatchers.eq(authRequest)))
        .thenReturn(
            new VistaAuthenticationToken(
                new VistaUser(
                    new RpcHost("localhost"),
                    "9F2B",
                    "500",
                    "500",
                    "12345",
                    "500:10VEHU;VEHU10",
                    "Vehu,Ten",
                    true,
                    true,
                    true,
                    true,
                    new ArrayList<GrantedAuthority>()),
                "500:10VEHU;VEHU10",
                "10.0.1.34",
                null,
                new ArrayList<GrantedAuthority>()));

    f.doFilter(request, response, filterChain);

    assertSame(request, filterChain.getRequest());
    assertSame(response, filterChain.getResponse());

    verify(mockAuthenticationManager).authenticate(AuthenticationTokenMatchers.eq(authRequest));
  }
  @Test
  public void testDoFilterNoCompression() throws Exception {
    MockHttpServletRequest request =
        new MockHttpServletRequest(HttpMethod.POST.name(), "http://localhost:8080/gzip");

    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain filterChain =
        new MockFilterChain(
            servlet,
            new GzipServletFilter(),
            new OncePerRequestFilter() {
              @Override
              protected void doFilterInternal(
                  HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
                  throws ServletException, IOException {
                response.getOutputStream().write("Should be compressed".getBytes());
              }
            });
    filterChain.doFilter(request, response);

    String unzipped = new String(response.getContentAsByteArray());
    Assert.assertEquals(unzipped, "Should be compressed");
  }