StaticFileServer implements StaticFileHandler { protected void writeCacheHeaders(String filenameWithPath, HttpServletResponse response) { int resourceCacheTime = getCacheTime(filenameWithPath); String cacheControl; if (!deploymentConfiguration.isProductionMode()) { cacheControl = "no-cache"; } else if (resourceCacheTime > 0) { cacheControl = "max-age=" + resourceCacheTime; } else { cacheControl = "public, max-age=0, must-revalidate"; } response.setHeader("Cache-Control", cacheControl); } StaticFileServer(VaadinServletService servletService); @Override boolean isStaticResourceRequest(HttpServletRequest request); @Override boolean serveStaticResource(HttpServletRequest request,
            HttpServletResponse response);  }
@Test public void writeCacheHeadersCacheResource() { fileServer.overrideCacheTime = 12; fileServer.writeCacheHeaders("/folder/myfile.txt", response); Assert.assertTrue(headers.get("Cache-Control").contains("max-age=12")); }
@Test public void nonProductionMode_writeCacheHeadersCacheResource_noCache() { Mockito.when(configuration.isProductionMode()).thenReturn(false); fileServer.overrideCacheTime = 12; fileServer.writeCacheHeaders("/folder/myfile.txt", response); Assert.assertTrue(headers.get("Cache-Control").equals("no-cache")); }
@Test public void writeCacheHeadersDoNotCacheResource() { fileServer.overrideCacheTime = 0; fileServer.writeCacheHeaders("/folder/myfile.txt", response); Assert.assertTrue(headers.get("Cache-Control").contains("max-age=0")); Assert.assertTrue( headers.get("Cache-Control").contains("must-revalidate")); }
@Test public void nonProductionMode_writeCacheHeadersDoNotCacheResource() { Mockito.when(configuration.isProductionMode()).thenReturn(false); fileServer.overrideCacheTime = 0; fileServer.writeCacheHeaders("/folder/myfile.txt", response); Assert.assertTrue(headers.get("Cache-Control").equals("no-cache")); }