DefaultStaticContentHandler implements StaticContentHandler { public boolean requestingStaticFile(HttpServletRequest request) throws MalformedURLException { URL resourceUrl = context.getResource(uriRelativeToContextRoot(request)); return resourceUrl != null && isAFile(resourceUrl); } DefaultStaticContentHandler(ServletContext context); boolean requestingStaticFile(HttpServletRequest request); void deferProcessingToContainer(FilterChain filterChain, HttpServletRequest request,
			HttpServletResponse response);  }
@Test public void returnsTrueForRealStaticResources() throws Exception { File file = File.createTempFile("_test", ".xml"); String key = file.getAbsolutePath(); when(request.getRequestURI()).thenReturn("/contextName/" +key); when(request.getContextPath()).thenReturn("/contextName/"); when(context.getResource(key)).thenReturn(file.toURI().toURL()); boolean result = new DefaultStaticContentHandler(context).requestingStaticFile(request); assertThat(result, is(equalTo(true))); }
@Test public void returnsTrueForRealStaticResourcesWithQueryString() throws Exception { File file = File.createTempFile("_test", ".xml"); String key = file.getAbsolutePath(); when(request.getRequestURI()).thenReturn("/contextName/" + key + "?jsesssionid=12lkjahfsd12414"); when(request.getContextPath()).thenReturn("/contextName/"); when(context.getResource(key)).thenReturn(file.toURI().toURL()); boolean result = new DefaultStaticContentHandler(context).requestingStaticFile(request); assertThat(result, is(equalTo(true))); }
@Test public void returnsTrueForRealStaticResourcesWithJSessionId() throws Exception { File file = File.createTempFile("_test", ".xml"); String key = file.getAbsolutePath(); when(request.getRequestURI()).thenReturn("/contextName/" + key + ";jsesssionid=12lkjahfsd12414"); when(request.getContextPath()).thenReturn("/contextName/"); when(context.getResource(key)).thenReturn(file.toURI().toURL()); boolean result = new DefaultStaticContentHandler(context).requestingStaticFile(request); assertThat(result, is(equalTo(true))); }
@Test public void returnsFalseForNonStaticResources() throws Exception { File file = new File("_test_unknown.xml"); String key = file.getAbsolutePath(); when(request.getRequestURI()).thenReturn("/contextName/" +key); when(request.getContextPath()).thenReturn("/contextName/"); when(context.getResource(key)).thenReturn(null); boolean result = new DefaultStaticContentHandler(context).requestingStaticFile(request); assertThat(result, is(equalTo(false))); }