private Pair<Uri, File> makeFile(String suffix, String content) throws Exception { File tmpFile = File.createTempFile("restmp", suffix); return makeFile(tmpFile, content); }
private Pair<Uri, File> makeFile(File file, String content) throws Exception { file.deleteOnExit(); setFileContent(file, content); return Pair.of(new UriBuilder().setScheme("file").setPath(file.getPath()).toUri(), file); }
@Test public void loadFileUpdateBehavior() throws Exception { loader.setSupportFileUpdates(5000); // set in millis Pair<Uri, File> optUri = makeFile(".opt.js", FILE_JS); File dbgFile = new File(optUri.one.getPath().replace(".opt.js", ".js")); dbgFile.createNewFile(); Pair<Uri, File> dbgUri = makeFile(dbgFile, UNCOMPRESSED_FILE_JS); FeatureResource resource = loader.load(dbgUri.one, null); assertEquals(FILE_JS, resource.getContent()); setFileContent(optUri.two, UPDATED_FILE_JS); loader.forceFileChanged.put(optUri.two.getAbsolutePath(), true); setFileContent(dbgUri.two, UPDATED_UNCOMPRESSED_FILE_JS); loader.forceFileChanged.put(dbgUri.two.getAbsolutePath(), true);
@Test public void loadUriInline() throws Exception { Uri uri = Uri.parse("http://apache.org/resource.js"); Map<String, String> attribs = Maps.newHashMap(); attribs.put("inline", "true"); mockFetcher(uri, URL_JS); FeatureResource resource = loader.load(uri, attribs); assertEquals(URL_JS, resource.getContent()); assertEquals(URL_JS, resource.getDebugContent()); assertTrue(resource.isProxyCacheable()); assertFalse(resource.isExternal()); }
@Test public void loadFileUpdateBehavior() throws Exception { loader.setSupportFileUpdates(5000); // set in millis Pair<Uri, File> optUri = makeFile(".opt.js", FILE_JS); File dbgFile = new File(optUri.one.getPath().replace(".opt.js", ".js")); dbgFile.createNewFile(); Pair<Uri, File> dbgUri = makeFile(dbgFile, UNCOMPRESSED_FILE_JS); FeatureResource resource = loader.load(dbgUri.one, null); assertEquals(FILE_JS, resource.getContent()); setFileContent(optUri.two, UPDATED_FILE_JS); loader.forceFileChanged.put(optUri.two.getAbsolutePath(), true); setFileContent(dbgUri.two, UPDATED_UNCOMPRESSED_FILE_JS); loader.forceFileChanged.put(dbgUri.two.getAbsolutePath(), true);
@Test public void loadUriInline() throws Exception { Uri uri = Uri.parse("http://apache.org/resource.js"); Map<String, String> attribs = Maps.newHashMap(); attribs.put("inline", "true"); mockFetcher(uri, URL_JS); FeatureResource resource = loader.load(uri, attribs); assertEquals(URL_JS, resource.getContent()); assertEquals(URL_JS, resource.getDebugContent()); assertTrue(resource.isProxyCacheable()); assertFalse(resource.isExternal()); }
@Test public void loadFileUpdateBehavior() throws Exception { loader.setSupportFileUpdates(5000); // set in millis Pair<Uri, File> optUri = makeFile(".opt.js", FILE_JS); File dbgFile = new File(optUri.one.getPath().replace(".opt.js", ".js")); dbgFile.createNewFile(); Pair<Uri, File> dbgUri = makeFile(dbgFile, UNCOMPRESSED_FILE_JS); FeatureResource resource = loader.load(dbgUri.one, null); assertEquals(FILE_JS, resource.getContent()); setFileContent(optUri.two, UPDATED_FILE_JS); loader.forceFileChanged.put(optUri.two.getAbsolutePath(), true); setFileContent(dbgUri.two, UPDATED_UNCOMPRESSED_FILE_JS); loader.forceFileChanged.put(dbgUri.two.getAbsolutePath(), true);
private Pair<Uri, File> makeFile(String suffix, String content) throws Exception { File tmpFile = File.createTempFile("restmp", suffix); return makeFile(tmpFile, content); }
@Test public void loadUriInline() throws Exception { Uri uri = Uri.parse("http://apache.org/resource.js"); Map<String, String> attribs = Maps.newHashMap(); attribs.put("inline", "true"); HttpFetcher fetcher = mockFetcher(uri, URL_JS); loader.setHttpFetcher(fetcher); FeatureResource resource = loader.load(uri, attribs); assertEquals(URL_JS, resource.getContent()); assertEquals(URL_JS, resource.getDebugContent()); assertTrue(resource.isProxyCacheable()); assertFalse(resource.isExternal()); }
private Pair<Uri, File> makeFile(File file, String content) throws Exception { file.deleteOnExit(); setFileContent(file, content); return Pair.of(new UriBuilder().setScheme("file").setPath(file.getPath()).toUri(), file); }
@Test public void loadFileUpdateIgnoredIfUpdatesDisabled() throws Exception { Pair<Uri, File> optUri = makeFile(".opt.js", FILE_JS); FeatureResource resource = loader.load(optUri.one, null); assertEquals(FILE_JS, resource.getContent()); assertEquals(FILE_JS, resource.getDebugContent()); assertFalse(resource.isExternal()); assertTrue(resource.isProxyCacheable()); setFileContent(optUri.two, UPDATED_FILE_JS); // Advance the time. Update checks disabled by default. timeSource.incrementSeconds(10); // Same asserts. assertEquals(FILE_JS, resource.getContent()); assertEquals(FILE_JS, resource.getDebugContent()); assertFalse(resource.isExternal()); assertTrue(resource.isProxyCacheable()); }
private Pair<Uri, File> makeFile(String suffix, String content) throws Exception { File tmpFile = File.createTempFile("restmp", suffix); return makeFile(tmpFile, content); }
@Test public void loadUriExtern() throws Exception { String theUrl = "http://apache.org/resource.js"; Uri uri = Uri.parse(theUrl); Map<String, String> attribs = Maps.newHashMap(); mockFetcher(uri, URL_JS); FeatureResource resource = loader.load(uri, attribs); assertEquals(theUrl, resource.getContent()); assertEquals(theUrl, resource.getDebugContent()); assertTrue(resource.isProxyCacheable()); assertTrue(resource.isExternal()); }
private Pair<Uri, File> makeFile(File file, String content) throws Exception { file.deleteOnExit(); setFileContent(file, content); return Pair.of(new UriBuilder().setScheme("file").setPath(file.getPath()).toUri(), file); }
@Test public void loadFileUpdateIgnoredIfUpdatesDisabled() throws Exception { Pair<Uri, File> optUri = makeFile(".opt.js", FILE_JS); FeatureResource resource = loader.load(optUri.one, null); assertEquals(FILE_JS, resource.getContent()); assertEquals(FILE_JS, resource.getDebugContent()); assertFalse(resource.isExternal()); assertTrue(resource.isProxyCacheable()); setFileContent(optUri.two, UPDATED_FILE_JS); // Advance the time. Update checks disabled by default. timeSource.incrementSeconds(10); // Same asserts. assertEquals(FILE_JS, resource.getContent()); assertEquals(FILE_JS, resource.getDebugContent()); assertFalse(resource.isExternal()); assertTrue(resource.isProxyCacheable()); }
@Test public void loadFileBothModesAvailable() throws Exception { Pair<Uri, File> optUri = makeFile(".opt.js", FILE_JS); File dbgFile = new File(optUri.one.getPath().replace(".opt.js", ".js")); dbgFile.createNewFile(); Pair<Uri, File> dbgUri = makeFile(dbgFile, UNCOMPRESSED_FILE_JS); FeatureResource resource = loader.load(dbgUri.one, null); assertEquals(FILE_JS, resource.getContent()); assertEquals(UNCOMPRESSED_FILE_JS, resource.getDebugContent()); assertFalse(resource.isExternal()); assertTrue(resource.isProxyCacheable()); }
@Test public void loadUriExtern() throws Exception { String theUrl = "http://apache.org/resource.js"; Uri uri = Uri.parse(theUrl); Map<String, String> attribs = Maps.newHashMap(); mockFetcher(uri, URL_JS); FeatureResource resource = loader.load(uri, attribs); assertEquals(theUrl, resource.getContent()); assertEquals(theUrl, resource.getDebugContent()); assertTrue(resource.isProxyCacheable()); assertTrue(resource.isExternal()); }
@Test public void loadFileUpdateIgnoredIfUpdatesDisabled() throws Exception { Pair<Uri, File> optUri = makeFile(".opt.js", FILE_JS); FeatureResource resource = loader.load(optUri.one, null); assertEquals(FILE_JS, resource.getContent()); assertEquals(FILE_JS, resource.getDebugContent()); assertFalse(resource.isExternal()); assertTrue(resource.isProxyCacheable()); setFileContent(optUri.two, UPDATED_FILE_JS); // Advance the time. Update checks disabled by default. timeSource.incrementSeconds(10); // Same asserts. assertEquals(FILE_JS, resource.getContent()); assertEquals(FILE_JS, resource.getDebugContent()); assertFalse(resource.isExternal()); assertTrue(resource.isProxyCacheable()); }
@Test public void loadFileBothModesAvailable() throws Exception { Pair<Uri, File> optUri = makeFile(".opt.js", FILE_JS); File dbgFile = new File(optUri.one.getPath().replace(".opt.js", ".js")); dbgFile.createNewFile(); Pair<Uri, File> dbgUri = makeFile(dbgFile, UNCOMPRESSED_FILE_JS); FeatureResource resource = loader.load(dbgUri.one, null); assertEquals(FILE_JS, resource.getContent()); assertEquals(UNCOMPRESSED_FILE_JS, resource.getDebugContent()); assertFalse(resource.isExternal()); assertTrue(resource.isProxyCacheable()); }
@Test public void loadUriExtern() throws Exception { String theUrl = "http://apache.org/resource.js"; Uri uri = Uri.parse(theUrl); Map<String, String> attribs = Maps.newHashMap(); HttpFetcher fetcher = mockFetcher(uri, URL_JS); loader.setHttpFetcher(fetcher); // should have no effect on its own FeatureResource resource = loader.load(uri, attribs); assertEquals(theUrl, resource.getContent()); assertEquals(theUrl, resource.getDebugContent()); assertTrue(resource.isProxyCacheable()); assertTrue(resource.isExternal()); }