@Test public void registerFromFileInNestedDirectoryFeatureXmlFile() throws Exception { // Get the directory from dummyUri and create a subdir. File tmpFile = File.createTempFile("dummy", ".dat"); tmpFile.deleteOnExit(); File parentDir = tmpFile.getParentFile(); String childDirName = String.valueOf(Math.random()); File childDir = new File(parentDir, childDirName); childDir.mkdirs(); childDir.deleteOnExit(); File featureDir = new File(childDir, "thefeature"); featureDir.mkdirs(); featureDir.deleteOnExit(); File resFile = File.createTempFile("content", ".js", featureDir); resFile.deleteOnExit(); String content = "content-foo"; BufferedWriter out = new BufferedWriter(new FileWriter(resFile)); out.write(content); out.close(); File featureFile = File.createTempFile("feature", ".xml", featureDir); featureFile.deleteOnExit(); out = new BufferedWriter(new FileWriter(featureFile)); out.write(xml(NODEP_TPL, "gadget", resFile.toURI().toString(), null)); out.close(); registry = TestFeatureRegistry.newBuilder().build(childDir.toURI().toString()); // Verify single resource works all the way through. List<FeatureResource> resources = registry.getAllFeatures().getResources(); assertEquals(1, resources.size()); assertEquals(content, resources.get(0).getContent()); }
@Test public void registerFromFileInNestedDirectoryFeatureXmlFile() throws Exception { // Get the directory from dummyUri and create a subdir. File tmpFile = File.createTempFile("dummy", ".dat"); tmpFile.deleteOnExit(); File parentDir = tmpFile.getParentFile(); String childDirName = String.valueOf(Math.random()); File childDir = new File(parentDir, childDirName); childDir.mkdirs(); childDir.deleteOnExit(); File featureDir = new File(childDir, "thefeature"); featureDir.mkdirs(); featureDir.deleteOnExit(); File resFile = File.createTempFile("content", ".js", featureDir); resFile.deleteOnExit(); String content = "content-foo"; BufferedWriter out = new BufferedWriter(new FileWriter(resFile)); out.write(content); out.close(); File featureFile = File.createTempFile("feature", ".xml", featureDir); featureFile.deleteOnExit(); out = new BufferedWriter(new FileWriter(featureFile)); out.write(xml(NODEP_TPL, "gadget", resFile.toURI().toString(), null)); out.close(); registry = TestFeatureRegistry.newBuilder().build(childDir.toURI().toString()); // Verify single resource works all the way through. List<FeatureResource> resources = registry.getAllFeatures().getResources(); assertEquals(1, resources.size()); assertEquals(content, resources.get(0).getContent()); }
@Test public void getAllFeatures() throws Exception { setupFullRegistry("gadget", null); List<FeatureResource> resources = registry.getAllFeatures().getResources(); // No guaranteed order (top/mid/bottom bundle may be before nodep) // Just check that there are 5 resources around and let the above tests // handle transitivity checks. assertEquals(5, resources.size()); }
@Test public void getAllFeatures() throws Exception { setupFullRegistry("gadget", null); List<FeatureResource> resources = registry.getAllFeatures().getResources(); // No guaranteed order (top/mid/bottom bundle may be before nodep) // Just check that there are 5 resources around and let the above tests // handle transitivity checks. assertEquals(5, resources.size()); }
@Test public void registerFromResourceFeatureXmlRelativeContent() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); String content = "resource-content-relative()"; Uri contentUri = builder.expectResource(content); String relativePath = contentUri.getPath().substring(contentUri.getPath().lastIndexOf('/') + 1); Uri featureUri = builder.expectResource(xml(NODEP_TPL, "gadget", relativePath, null)); registry = builder.build(featureUri.toString()); // Verify single resource works all the way through. List<FeatureResource> resources = registry.getAllFeatures().getResources(); assertEquals(1, resources.size()); assertEquals(content, resources.get(0).getContent()); }
@Test public void registerFromResourceFeatureXmlRelativeContent() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); String content = "resource-content-relative()"; Uri contentUri = builder.expectResource(content); String relativePath = contentUri.getPath().substring(contentUri.getPath().lastIndexOf('/') + 1); Uri featureUri = builder.expectResource(xml(NODEP_TPL, "gadget", relativePath, null)); registry = builder.build(featureUri.toString()); // Verify single resource works all the way through. List<FeatureResource> resources = registry.getAllFeatures().getResources(); assertEquals(1, resources.size()); assertEquals(content, resources.get(0).getContent()); }
@Test public void registerFromResourceFeatureXml() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); String content = "resource-content()"; Uri contentUri = builder.expectResource(content); Uri featureUri = builder.expectResource(xml(NODEP_TPL, "gadget", contentUri.getPath(), null)); builder.addFeatureFile(featureUri.toString()); registry = builder.build(); // Verify single resource works all the way through. List<FeatureResource> resources = registry.getAllFeatures().getResources(); assertEquals(1, resources.size()); assertEquals(content, resources.get(0).getContent()); }
private void checkRegisterFromFileFeatureXml(boolean withScheme) throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); String content = "content-" + (withScheme ? "withScheme" : "noScheme"); Uri resUri = makeFile(content); Uri featureFile = makeFile(xml(NODEP_TPL, "gadget", withScheme ? resUri.toString() : resUri.getPath(), null)); registry = builder.build(withScheme ? featureFile.toString() : featureFile.getPath()); // Verify single resource works all the way through. List<FeatureResource> resources = registry.getAllFeatures().getResources(); assertEquals(1, resources.size()); assertEquals(content, resources.get(0).getContent()); }
private void checkRegisterFromFileFeatureXml(boolean withScheme) throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); String content = "content-" + (withScheme ? "withScheme" : "noScheme"); Uri resUri = makeFile(content); Uri featureFile = makeFile(xml(NODEP_TPL, "gadget", withScheme ? resUri.toString() : resUri.getPath(), null)); registry = builder.build(withScheme ? featureFile.toString() : featureFile.getPath()); // Verify single resource works all the way through. List<FeatureResource> resources = registry.getAllFeatures().getResources(); assertEquals(1, resources.size()); assertEquals(content, resources.get(0).getContent()); }
@Test public void registerOverrideFeature() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); // Feature 1 String content1 = "content1()"; Uri content1Uri = builder.expectResource(content1); Uri feature1Uri = builder.expectResource(xml(BOTTOM_TPL, "gadget", content1Uri.getPath(), null)); String content2 = "content_two()"; Uri content2Uri = builder.expectResource(content2); Uri feature2Uri = builder.expectResource(xml(BOTTOM_TPL, "gadget", content2Uri.getPath(), null)); registry = builder.build(feature1Uri.toString()); List<FeatureResource> resources1 = registry.getAllFeatures().getResources(); assertEquals(1, resources1.size()); assertEquals(content1, resources1.get(0).getContent()); // Register it again, different def. registry = builder.build(feature2Uri.toString()); List<FeatureResource> resources2 = registry.getAllFeatures().getResources(); assertEquals(1, resources2.size()); assertEquals(content2, resources2.get(0).getContent()); // Check cached resources too. List<FeatureResource> resourcesAgain = registry.getAllFeatures().getResources(); assertSame(resources2, resourcesAgain); }
@Test public void registerOverrideFeature() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); // Feature 1 String content1 = "content1()"; Uri content1Uri = builder.expectResource(content1); Uri feature1Uri = builder.expectResource(xml(BOTTOM_TPL, "gadget", content1Uri.getPath(), null)); String content2 = "content_two()"; Uri content2Uri = builder.expectResource(content2); Uri feature2Uri = builder.expectResource(xml(BOTTOM_TPL, "gadget", content2Uri.getPath(), null)); registry = builder.build(feature1Uri.toString()); List<FeatureResource> resources1 = registry.getAllFeatures().getResources(); assertEquals(1, resources1.size()); assertEquals(content1, resources1.get(0).getContent()); // Register it again, different def. registry = builder.build(feature2Uri.toString()); List<FeatureResource> resources2 = registry.getAllFeatures().getResources(); assertEquals(1, resources2.size()); assertEquals(content2, resources2.get(0).getContent()); // Check cached resources too. List<FeatureResource> resourcesAgain = registry.getAllFeatures().getResources(); assertSame(resources2, resourcesAgain); }
@Test public void registerFromResourceFeatureXml() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); String content = "resource-content()"; Uri contentUri = builder.expectResource(content); Uri featureUri = builder.expectResource(xml(NODEP_TPL, "gadget", contentUri.getPath(), null)); builder.addFeatureFile(featureUri.toString()); registry = builder.build(); // Verify single resource works all the way through. List<FeatureResource> resources = registry.getAllFeatures().getResources(); assertEquals(1, resources.size()); assertEquals(content, resources.get(0).getContent()); }
@Test public void registerFromResourceIndex() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); // One with extern resource loaded content... String content1 = "content1()"; Uri content1Uri = builder.expectResource(content1); Uri feature1Uri = builder.expectResource(xml(MID_A_TPL, "gadget", content1Uri.getPath(), null)); // One feature with inline content (that it depends on)... String content2 = "inline()"; Uri feature2Uri = builder.expectResource(xml(BOTTOM_TPL, "gadget", null, content2)); // .txt file to join the two Uri txtFile = builder.expectResource(feature1Uri.toString() + '\n' + feature2Uri.toString(), ".txt"); // Load resources from the text file and do basic validation they're good. registry = builder.build(txtFile.toString()); // Contents should be ordered based on the way they went in. List<FeatureResource> resources = registry.getAllFeatures().getResources(); assertEquals(2, resources.size()); assertEquals(content2, resources.get(0).getContent()); assertEquals(content1, resources.get(1).getContent()); }
@Test public void registerFromResourceIndex() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); // One with extern resource loaded content... String content1 = "content1()"; Uri content1Uri = builder.expectResource(content1); Uri feature1Uri = builder.expectResource(xml(MID_A_TPL, "gadget", content1Uri.getPath(), null)); // One feature with inline content (that it depends on)... String content2 = "inline()"; Uri feature2Uri = builder.expectResource(xml(BOTTOM_TPL, "gadget", null, content2)); // .txt file to join the two Uri txtFile = builder.expectResource(feature1Uri.toString() + '\n' + feature2Uri.toString(), ".txt"); // Load resources from the text file and do basic validation they're good. registry = builder.build(txtFile.toString()); // Contents should be ordered based on the way they went in. List<FeatureResource> resources = registry.getAllFeatures().getResources(); assertEquals(2, resources.size()); assertEquals(content2, resources.get(0).getContent()); assertEquals(content1, resources.get(1).getContent()); }