WebsiteServiceImpl { public String fetchWebsite(String baseUrl, String htmlFile, String contextRoot) throws IOException { cache = cacheManager.getCache("default"); Document document = Jsoup.connect(baseUrl + htmlFile).get(); Elements cssElems = document.select("link[rel='stylesheet'], link[type='text/css']"); for(Element css : cssElems) { String cssHref = relativeToAbsolute(baseUrl, css.attr("href")); String cacheId = CacheIdUtil.createCacheId(baseUrl, cssHref, contextRoot); fetchText(cssHref, cacheId); css.attr("href", cacheId); } Elements jsElems = document.select("script[src!='']"); for(Element js : jsElems) { String jsSrc = relativeToAbsolute(baseUrl, js.attr("src")); String cacheId = CacheIdUtil.createCacheId(baseUrl, jsSrc, contextRoot); fetchText(jsSrc, cacheId); js.attr("src", cacheId); } Elements imgElems = document.select("img[src!='']"); for(Element img : imgElems) { String imgSrc = relativeToAbsolute(baseUrl, img.attr("src")); String cacheId = CacheIdUtil.createCacheId(baseUrl, imgSrc, contextRoot); fetchBinary(imgSrc, cacheId); img.attr("src", cacheId); } String content = document.outerHtml(); String cacheId = CacheIdUtil.createCacheId(baseUrl, htmlFile, contextRoot); cache.put(cacheId, content); return content; }  String fetchWebsite(String baseUrl, String htmlFile, String contextRoot); String fetchText(String file, String cacheId); byte[] fetchBinary(String file, String cacheId);  }
@Test public void testFetchWebsite() throws Exception { mockServer.when(request("/index.html")) .respond(response(TestUtil.getFileContents("website/index.html")) .withHeader(new Header(HttpHeaders.Names.CONTENT_TYPE, MediaType.TEXT_HTML_VALUE))); mockServer.when(request("/app/index.css")) .respond(response(TestUtil.getFileContents("website/index.css")) .withHeader(new Header(HttpHeaders.Names.CONTENT_TYPE, "text/css"))); mockServer.when(request("/app/index.module.js")) .respond(response(TestUtil.getFileContents("website/index.module.js")) .withHeader(new Header(HttpHeaders.Names.CONTENT_TYPE, "application/javascript"))); mockServer.when(request("/bower_components/angular-toastr/dist/angular-toastr.css")) .respond(response(TestUtil.getFileContents("website/angular-toastr.css")) .withHeader(new Header(HttpHeaders.Names.CONTENT_TYPE, "text/css"))); mockServer.when(request("/angular.png")) .respond(response(TestUtil.getFileContents("website/angular.png")) .withHeader(new Header(HttpHeaders.Names.CONTENT_TYPE, "image/png"))); String s = websiteService.fetchWebsite("http: Cache cache = cacheManager.getCache("default"); Assert.assertNotNull(cache.get("/mycontext/123/index.html")); Assert.assertNotNull(cache.get("/mycontext/123/app/index.css")); Assert.assertNotNull(cache.get("/mycontext/123/app/index.module.js")); Assert.assertNotNull(cache.get("/mycontext/123/bower_components/angular-toastr/dist/angular-toastr.css")); Assert.assertNotNull(cache.get("/mycontext/123/angular.png")); }