@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 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 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 loadFileDebugOnlyAvailable() throws Exception { Pair<Uri, File> dbgUri = makeFile(".js", UNCOMPRESSED_FILE_JS); FeatureResource resource = loader.load(dbgUri.one, null); assertEquals(UNCOMPRESSED_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(expected=IllegalArgumentException.class) public void loadFileNothingAvailable() throws Exception { Uri nilUri = new UriBuilder().setScheme("file").setPath("/does/not/exist.js").toUri(); loader.load(nilUri, null); fail("Should have failed indicating could not find: " + nilUri.toString()); }
@Test public void loadFileOptOnlyAvailable() 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()); }
@Test public void loadFileDebugOnlyAvailable() throws Exception { Pair<Uri, File> dbgUri = makeFile(".js", UNCOMPRESSED_FILE_JS); FeatureResource resource = loader.load(dbgUri.one, null); assertEquals(UNCOMPRESSED_FILE_JS, resource.getContent()); assertEquals(UNCOMPRESSED_FILE_JS, resource.getDebugContent()); assertFalse(resource.isExternal()); assertTrue(resource.isProxyCacheable()); }
@Test public void loadFileNoOptPathCalculable() throws Exception { // File doesn't end in .js, so it's loaded for both opt and debug. Pair<Uri, File> dbgUri = makeFile(".notjssuffix", UNCOMPRESSED_FILE_JS); FeatureResource resource = loader.load(dbgUri.one, null); assertEquals(UNCOMPRESSED_FILE_JS, resource.getContent()); assertEquals(UNCOMPRESSED_FILE_JS, resource.getDebugContent()); assertFalse(resource.isExternal()); assertTrue(resource.isProxyCacheable()); }
@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(expected=IllegalArgumentException.class) public void loadFileNothingAvailable() throws Exception { Uri nilUri = new UriBuilder().setScheme("file").setPath("/does/not/exist.js").toUri(); loader.load(nilUri, null); fail("Should have failed indicating could not find: " + nilUri.toString()); }
@Test public void loadFileOptOnlyAvailable() 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()); }
@Test(expected=IllegalArgumentException.class) public void loadFileNothingAvailable() throws Exception { Uri nilUri = new UriBuilder().setScheme("file").setPath("/does/not/exist.js").toUri(); loader.load(nilUri, null); fail("Should have failed indicating could not find: " + nilUri.toString()); }
@Test public void loadFileNoOptPathCalculable() throws Exception { // File doesn't end in .js, so it's loaded for both opt and debug. Pair<Uri, File> dbgUri = makeFile(".notjssuffix", UNCOMPRESSED_FILE_JS); FeatureResource resource = loader.load(dbgUri.one, null); assertEquals(UNCOMPRESSED_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 loadUriInlineNoFetcherSet() throws Exception { Uri uri = Uri.parse("http://apache.org/resource.js"); Map<String, String> attribs = Maps.newHashMap(); attribs.put("inline", "true"); FeatureResource resource = loader.load(uri, attribs); assertNull(resource.getContent()); assertNull(resource.getDebugContent()); assertFalse(resource.isProxyCacheable()); assertFalse(resource.isExternal()); }
@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 loadFileNoOptPathCalculable() throws Exception { // File doesn't end in .js, so it's loaded for both opt and debug. Pair<Uri, File> dbgUri = makeFile(".notjssuffix", UNCOMPRESSED_FILE_JS); FeatureResource resource = loader.load(dbgUri.one, null); assertEquals(UNCOMPRESSED_FILE_JS, resource.getContent()); assertEquals(UNCOMPRESSED_FILE_JS, resource.getDebugContent()); assertFalse(resource.isExternal()); assertTrue(resource.isProxyCacheable()); }
@Test public void loadFileOptOnlyAvailable() 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()); }
@Test public void loadFileDebugOnlyAvailable() throws Exception { Pair<Uri, File> dbgUri = makeFile(".js", UNCOMPRESSED_FILE_JS); FeatureResource resource = loader.load(dbgUri.one, null); assertEquals(UNCOMPRESSED_FILE_JS, resource.getContent()); assertEquals(UNCOMPRESSED_FILE_JS, resource.getDebugContent()); assertFalse(resource.isExternal()); assertTrue(resource.isProxyCacheable()); }