private static String xml(String tpl, String type, String uri, String content, Map<String, String> attribs) { return xml(tpl, type, uri, content, attribs, Maps.<String, String>newHashMap()); }
private static String xml(String tpl, String type, String uri, String content, Map<String, String> attribs) { return xml(tpl, type, uri, content, attribs, Maps.<String, String>newHashMap()); }
private static String xml(String tpl, String type, String uri, String content, Map<String, String> attribs) { return xml(tpl, type, uri, content, attribs, Maps.<String, String>newHashMap()); }
private static String xml(String tpl, String type, String uri, String content) { return xml(tpl, type, uri, content, Maps.<String, String>newHashMap()); }
private static String xml(String tpl, String type, String uri, String content) { return xml(tpl, type, uri, content, Maps.<String, String>newHashMap()); }
private static String xml(String tpl, String type, String uri, String content) { return xml(tpl, type, uri, content, Maps.<String, String>newHashMap()); }
@Test public void registerFromResourceFeatureXmlRelativeContent() throws Exception { String content = "resource-content-relative()"; Uri contentUri = expectResource(content); String relativePath = contentUri.getPath().substring(contentUri.getPath().lastIndexOf('/') + 1); Uri featureUri = expectResource(xml(NODEP_TPL, "gadget", relativePath, null)); registry = new TestFeatureRegistry(featureUri.toString()); // Verify single resource works all the way through. List<FeatureResource> resources = registry.getAllFeatures(); assertEquals(1, resources.size()); assertEquals(content, resources.get(0).getContent()); }
@Test public void loopIsDetectedAndCrashes() throws Exception { // Set up a registry with features loop_a,b,c. C points back to A, which should // cause an exception to be thrown by the register method. String type = "gadget"; Uri loopAUri = expectResource(xml(LOOP_A_TPL, type, null, "loop_a")); Uri loopBUri = expectResource(xml(LOOP_B_TPL, type, null, "loop_b")); Uri loopCUri = expectResource(xml(LOOP_C_TPL, type, null, "loop_c")); Uri txtFile = expectResource(loopAUri.toString() + '\n' + loopBUri.toString() + '\n' + loopCUri.toString(), ".txt"); try { registry = new TestFeatureRegistry(txtFile.toString()); fail("Should have thrown a loop-detected exception"); } catch (GadgetException e) { assertEquals(GadgetException.Code.INVALID_CONFIG, e.getCode()); } }
@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 { String content = "resource-content()"; Uri contentUri = expectResource(content); Uri featureUri = expectResource(xml(NODEP_TPL, "gadget", contentUri.getPath(), null)); registry = new TestFeatureRegistry(featureUri.toString()); // Verify single resource works all the way through. List<FeatureResource> resources = registry.getAllFeatures(); assertEquals(1, resources.size()); assertEquals(content, resources.get(0).getContent()); }
@Test public void loopIsDetectedAndCrashes() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); // Set up a registry with features loop_a,b,c. C points back to A, which should // cause an exception to be thrown by the register method. String type = "gadget"; Uri loopAUri = builder.expectResource(xml(LOOP_A_TPL, type, null, "loop_a")); Uri loopBUri = builder.expectResource(xml(LOOP_B_TPL, type, null, "loop_b")); Uri loopCUri = builder.expectResource(xml(LOOP_C_TPL, type, null, "loop_c")); Uri txtFile = builder.expectResource(loopAUri.toString() + '\n' + loopBUri.toString() + '\n' + loopCUri.toString(), ".txt"); try { registry = builder.build(txtFile.toString()); fail("Should have thrown a loop-detected exception"); } catch (GadgetException e) { assertEquals(GadgetException.Code.INVALID_CONFIG, e.getCode()); } }
private void checkRegisterFromFileFeatureXml(boolean withScheme) throws Exception { String content = "content-" + (withScheme ? "withScheme" : "noScheme"); Uri resUri = makeFile(content); Uri featureFile = makeFile(xml(NODEP_TPL, "gadget", withScheme ? resUri.toString() : resUri.getPath(), null)); registry = new TestFeatureRegistry(withScheme ? featureFile.toString() : featureFile.getPath()); // Verify single resource works all the way through. List<FeatureResource> resources = registry.getAllFeatures(); assertEquals(1, resources.size()); assertEquals(content, resources.get(0).getContent()); }
@Test public void unavailableFeatureCrashes() throws Exception { Uri featUri = expectResource(xml(BAD_DEP_TPL, "gadget", null, "content")); try { registry = new TestFeatureRegistry(featUri.toString()); } catch (GadgetException e) { assertEquals(GadgetException.Code.INVALID_CONFIG, e.getCode()); } }
@Test public void unavailableFeatureCrashes() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); Uri featUri = builder.expectResource(xml(BAD_DEP_TPL, "gadget", null, "content")); try { registry = builder.build(featUri.toString()); } catch (GadgetException e) { assertEquals(GadgetException.Code.INVALID_CONFIG, e.getCode()); } }
@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 unavailableFeatureCrashes() throws Exception { TestFeatureRegistry.Builder builder = TestFeatureRegistry.newBuilder(); Uri featUri = builder.expectResource(xml(BAD_DEP_TPL, "gadget", null, "content")); try { registry = builder.build(featUri.toString()); } catch (GadgetException e) { assertEquals(GadgetException.Code.INVALID_CONFIG, e.getCode()); } }
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 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()); }