GzipFilter implements Filter { Action getAction(final ServletRequest req) { final String enabled = System.getProperty(ORG_UBERFIRE_GZIP_ENABLE); if (enabled != null && !enabled.equals("true")) { return Action.DO_NOT_COMPRESS; } if (!(req instanceof HttpServletRequest)) { return Action.HALT; } final String acceptEncodingHeader = ((HttpServletRequest) req).getHeader(ACCEPT_ENCODING); if (acceptEncodingHeader == null || !acceptEncodingHeader.contains(GZIP)) { return Action.DO_NOT_ACCEPT_GZIP; } return Action.COMPRESS; }  void init(final FilterConfig filterConfig); void doFilter(final ServletRequest req,
                         final ServletResponse res,
                         final FilterChain chain); void destroy();  }
@Test public void getAction_notHttpServletRequest() { final GzipFilter gzipFilter = new GzipFilter(); assertEquals(HALT, gzipFilter.getAction(mock(ServletRequest.class))); }
@Test public void getAction_disableGzipCompressionViaSystemProperty() { final GzipFilter gzipFilter = new GzipFilter(); System.setProperty(ORG_UBERFIRE_GZIP_ENABLE, "false"); assertEquals(DO_NOT_COMPRESS, gzipFilter.getAction(mock(HttpServletRequest.class))); System.setProperty(ORG_UBERFIRE_GZIP_ENABLE, "falsy"); assertEquals(DO_NOT_COMPRESS, gzipFilter.getAction(mock(HttpServletRequest.class))); }
@Test public void getAction_doNotAcceptEncodingGzip() { final GzipFilter gzipFilter = new GzipFilter(); final HttpServletRequest mock = mock(HttpServletRequest.class); assertEquals(DO_NOT_ACCEPT_GZIP, gzipFilter.getAction(mock)); when(mock.getHeader(eq(ACCEPT_ENCODING))).thenReturn("foo"); assertEquals(DO_NOT_ACCEPT_GZIP, gzipFilter.getAction(mock)); }
@Test public void getAction_acceptEncodingGzip() { final GzipFilter gzipFilter = new GzipFilter(); final HttpServletRequest mock = mock(HttpServletRequest.class); when(mock.getHeader(eq(ACCEPT_ENCODING))).thenReturn(GZIP); assertEquals(COMPRESS, gzipFilter.getAction(mock)); }