ExcludePathAwareShallowETagFilter extends ShallowEtagHeaderFilter { @Override protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { final boolean shouldExclude = shouldExclude(request); if (shouldExclude) { filterChain.doFilter(request, response); } else { super.doFilterInternal(request, response, filterChain); } } ExcludePathAwareShallowETagFilter(final String... excludeAntPaths);   }
@Test public void excludePathDoesNotCalculateETag() throws ServletException, IOException { final String knownContextPath = "/bumlux/test"; final String knownUri = knownContextPath + "/exclude/download"; final String antPathExclusion = "/exclude/**"; when(servletRequestMock.getContextPath()).thenReturn(knownContextPath); when(servletRequestMock.getRequestURI()).thenReturn(knownUri); final ExcludePathAwareShallowETagFilter filterUnderTest = new ExcludePathAwareShallowETagFilter( antPathExclusion); filterUnderTest.doFilterInternal(servletRequestMock, servletResponseMock, filterChainMock); assertThat(servletResponseMock.getHeader("ETag")) .as("ETag header should not be set during downloading, too expensive").isNull(); verify(filterChainMock, times(1)).doFilter(servletRequestMock, servletResponseMock); }
@Test public void pathNotExcludedETagIsCalculated() throws ServletException, IOException { final String knownContextPath = "/bumlux/test"; final String knownUri = knownContextPath + "/include/download"; final String antPathExclusion = "/exclude/**"; when(servletRequestMock.getContextPath()).thenReturn(knownContextPath); when(servletRequestMock.getRequestURI()).thenReturn(knownUri); final ExcludePathAwareShallowETagFilter filterUnderTest = new ExcludePathAwareShallowETagFilter( antPathExclusion); final ArgumentCaptor<HttpServletResponse> responseArgumentCaptor = ArgumentCaptor .forClass(HttpServletResponse.class); filterUnderTest.doFilterInternal(servletRequestMock, servletResponseMock, filterChainMock); verify(filterChainMock, times(1)).doFilter(Mockito.eq(servletRequestMock), responseArgumentCaptor.capture()); assertThat(mockingDetails(responseArgumentCaptor.getValue()).isMock()).isFalse(); }