@Inject public AllJsIframeVersioner(FeatureRegistry registry) { String charset = Charset.defaultCharset().name(); MessageDigest digest = HashUtil.getMessageDigest(); digest.reset(); for (FeatureResource resource : registry.getAllFeatures().getResources()) { // Emulate StringBuilder append of content update(digest, resource.getContent(), charset); update(digest, resource.getDebugContent(), charset); } allJsChecksum = HashUtil.bytesToHex(digest.digest()); }
private void expectFeatureLookup() throws GadgetException { List<FeatureResource> swfObjectResources = Lists.newArrayList(); swfObjectResources.add(new SwfResource()); final FeatureRegistry.LookupResult lr = EasyMock.createMock(FeatureRegistry.LookupResult.class); EasyMock.expect(lr.getResources()).andReturn(swfObjectResources); EasyMock.replay(lr); EasyMock.expect(featureRegistry .getFeatureResources(isA(GadgetContext.class), eq(ImmutableSet.of("swfobject")), EasyMock.<List<String>>isNull())).andReturn(lr); }
private void expectFeatureLookup() throws GadgetException { List<FeatureResource> swfObjectResources = Lists.newArrayList(); swfObjectResources.add(new SwfResource()); final FeatureRegistry.LookupResult lr = EasyMock.createMock(FeatureRegistry.LookupResult.class); EasyMock.expect(lr.getResources()).andReturn(swfObjectResources); EasyMock.replay(lr); EasyMock.expect(featureRegistry .getFeatureResources(isA(GadgetContext.class), eq(ImmutableSet.of("swfobject")), EasyMock.<List<String>>isNull())).andReturn(lr); }
private void checkNoContentValidFeatureResources( String type, RenderingContext rctx) throws Exception { setupFullRegistry(type, null); GadgetContext ctx = getCtx(rctx, null); List<String> needed = Lists.newArrayList("nodep", "bottom"); List<String> unsupported = Lists.newLinkedList(); List<FeatureResource> resources = registry.getFeatureResources(ctx, needed, unsupported).getResources(); assertEquals(0, resources.size()); }
private void expectReq(String feature, String content) { FeatureResource resource = new FeatureResource.Simple(content, "", "js"); Collection<String> libs = Lists.newArrayList(feature); List<String> loaded = ImmutableList.of(); List<FeatureResource> resources = Lists.newArrayList(resource); final FeatureRegistry.LookupResult lr = createMock(FeatureRegistry.LookupResult.class); expect(lr.getResources()).andReturn(resources).anyTimes(); replay(lr); expect(registry.getFeatureResources(isA(GadgetContext.class), eq(libs), EasyMock.<List<String>>isNull())).andReturn(lr).anyTimes(); } }
@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 filterFeaturesByContainerNoMatch() throws Exception { // Again test only for gadget case; above tests cover type <-> RenderingContext setupFullRegistry("gadget", "one, two, three"); GadgetContext ctx = getCtx(RenderingContext.GADGET, "four"); List<String> needed = Lists.newArrayList("nodep", "bottom"); List<String> unsupported = Lists.newLinkedList(); List<FeatureResource> resources = registry.getFeatureResources(ctx, needed, unsupported).getResources(); assertEquals(0, resources.size()); // no resource matches but all feature keys valid assertEquals(0, unsupported.size()); }
private void expectReq(String feature, String content) { FeatureResource resource = new FeatureResource.Simple(content, "", "js"); Collection<String> libs = Lists.newArrayList(feature); List<String> loaded = ImmutableList.of(); List<FeatureResource> resources = Lists.newArrayList(resource); final FeatureRegistry.LookupResult lr = createMock(FeatureRegistry.LookupResult.class); expect(lr.getResources()).andReturn(resources).anyTimes(); replay(lr); expect(registry.getFeatureResources(isA(GadgetContext.class), eq(libs), EasyMock.<List<String>>isNull())).andReturn(lr).anyTimes(); } }
@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 filterFeaturesByContainerNoMatch() throws Exception { // Again test only for gadget case; above tests cover type <-> RenderingContext setupFullRegistry("gadget", "one, two, three"); GadgetContext ctx = getCtx(RenderingContext.GADGET, "four"); List<String> needed = Lists.newArrayList("nodep", "bottom"); List<String> unsupported = Lists.newLinkedList(); List<FeatureResource> resources = registry.getFeatureResources(ctx, needed, unsupported).getResources(); assertEquals(0, resources.size()); // no resource matches but all feature keys valid assertEquals(0, unsupported.size()); }
private void checkNoContentValidFeatureResources( String type, RenderingContext rctx) throws Exception { setupFullRegistry(type, null); GadgetContext ctx = getCtx(rctx, null); List<String> needed = Lists.newArrayList("nodep", "bottom"); List<String> unsupported = Lists.newLinkedList(); List<FeatureResource> resources = registry.getFeatureResources(ctx, needed, unsupported).getResources(); assertEquals(0, resources.size()); }
private void checkExactFeatureResources(String type, RenderingContext rctx) throws Exception { setupFullRegistry(type, null); GadgetContext ctx = getCtx(rctx, null); List<String> needed = Lists.newArrayList("nodep", "bottom"); List<String> unsupported = Lists.newLinkedList(); List<FeatureResource> resources = registry.getFeatureResources(ctx, needed, unsupported).getResources(); assertEquals(0, unsupported.size()); assertEquals(2, resources.size()); assertEquals("nodep", resources.get(0).getContent()); assertEquals("bottom", resources.get(1).getContent()); }
@Test public void testGetContainerFromMixedRegistry() throws Exception { setupMixedFullRegistry(); GadgetContext ctx = getCtx(RenderingContext.CONTAINER, null); List<String> needed = Lists.newArrayList("top"); List<String> unsupported = Lists.newLinkedList(); List<FeatureResource> resources = registry.getFeatureResources(ctx, needed, unsupported).getResources(); assertEquals(4, resources.size()); assertEquals("bottom();all();", resources.get(0).getContent()); assertEquals("mid_b();container();", resources.get(1).getContent()); assertEquals("mid_a();container();", resources.get(2).getContent()); assertEquals("top();all();", resources.get(3).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()); }
private void checkExactFeatureResources(String type, RenderingContext rctx) throws Exception { setupFullRegistry(type, null); GadgetContext ctx = getCtx(rctx, null); List<String> needed = Lists.newArrayList("nodep", "bottom"); List<String> unsupported = Lists.newLinkedList(); List<FeatureResource> resources = registry.getFeatureResources(ctx, needed, unsupported).getResources(); assertEquals(0, unsupported.size()); assertEquals(2, resources.size()); assertEquals("nodep", resources.get(0).getContent()); assertEquals("bottom", resources.get(1).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 getFeatureResourcesNoTransitiveSingle() throws Exception { setupFullRegistry("gadget", null); GadgetContext ctx = getCtx(RenderingContext.GADGET, null); List<String> needed = Lists.newArrayList("top", "bottom"); List<String> unsupported = Lists.newLinkedList(); List<FeatureResource> resources = registry.getFeatureResources(ctx, needed, unsupported, false).getResources(); // Should return in order requested. assertEquals(2, resources.size()); assertEquals("top", resources.get(0).getContent()); assertEquals("bottom", resources.get(1).getContent()); assertEquals(0, unsupported.size()); }
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 testGetGadgetFromMixedRegistry() throws Exception { setupMixedFullRegistry(); GadgetContext ctx = getCtx(RenderingContext.GADGET, null); List<String> needed = Lists.newArrayList("top"); List<String> unsupported = Lists.newLinkedList(); List<FeatureResource> resources = registry.getFeatureResources(ctx, needed, unsupported).getResources(); assertEquals(4, resources.size()); assertEquals("bottom();all();", resources.get(0).getContent()); assertEquals("mid_b();gadget();", resources.get(1).getContent()); assertEquals("mid_a();all();", resources.get(2).getContent()); assertEquals("top();gadget();", resources.get(3).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()); }