@Inject public AllJsIframeVersioner(FeatureRegistry registry) { StringBuilder jsBuf = new StringBuilder(); for (FeatureResource resource : registry.getAllFeatures()) { jsBuf.append(resource.getContent()).append(resource.getDebugContent()); } allJsChecksum = HashUtil.checksum(jsBuf.toString().getBytes()); }
@Inject public AllJsIframeVersioner(FeatureRegistry registry) { StringBuilder jsBuf = new StringBuilder(); for (FeatureResource resource : registry.getAllFeatures()) { jsBuf.append(resource.getContent()).append(resource.getDebugContent()); } allJsChecksum = HashUtil.checksum(jsBuf.toString().getBytes()); }
@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()); }
@Before public void setUp() { String featureContent = "THE_FEATURE_CONTENT"; String debugContent = "FEATURE_DEBUG_CONTENT"; featureChecksum = HashUtil.checksum((featureContent + debugContent).getBytes()); FeatureRegistry registry = createMock(FeatureRegistry.class); FeatureResource resource = new FeatureResource.Simple(featureContent, debugContent); List<FeatureResource> allResources = Lists.newArrayList(resource); expect(registry.getAllFeatures()).andReturn(allResources).once(); replay(registry); versioner = new AllJsIframeVersioner(registry); verify(registry); }
List<FeatureResource> resources = registry.getAllFeatures(); assertEquals(1, resources.size()); assertEquals(content, resources.get(0).getContent());
@Test public void getAllFeatures() throws Exception { setupFullRegistry("gadget", null); List<FeatureResource> resources = registry.getAllFeatures(); // 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()); }
@Before public void setUp() { String featureContent = "THE_FEATURE_CONTENT"; String debugContent = "FEATURE_DEBUG_CONTENT"; String charset = Charset.defaultCharset().name(); MessageDigest digest = HashUtil.getMessageDigest(); try{ digest.update(featureContent.getBytes(charset)); } catch (UnsupportedEncodingException e) { digest.update(featureContent.getBytes()); } try{ digest.update(debugContent.getBytes(charset)); } catch (UnsupportedEncodingException e) { digest.update(debugContent.getBytes()); } featureChecksum = HashUtil.bytesToHex(digest.digest()); FeatureRegistry registry = createMock(FeatureRegistry.class); FeatureResource resource = new FeatureResource.Simple(featureContent, debugContent, "js"); List<FeatureResource> allResources = Lists.newArrayList(resource); final FeatureRegistry.LookupResult lr = createMock(FeatureRegistry.LookupResult.class); expect(lr.getResources()).andReturn(allResources); replay(lr); expect(registry.getAllFeatures()).andReturn(lr).once(); replay(registry); versioner = new AllJsIframeVersioner(registry); verify(registry); }
@Before public void setUp() { String featureContent = "THE_FEATURE_CONTENT"; String debugContent = "FEATURE_DEBUG_CONTENT"; String charset = Charset.defaultCharset().name(); MessageDigest digest = HashUtil.getMessageDigest(); try{ digest.update(featureContent.getBytes(charset)); } catch (UnsupportedEncodingException e) { digest.update(featureContent.getBytes()); } try{ digest.update(debugContent.getBytes(charset)); } catch (UnsupportedEncodingException e) { digest.update(debugContent.getBytes()); } featureChecksum = HashUtil.bytesToHex(digest.digest()); FeatureRegistry registry = createMock(FeatureRegistry.class); FeatureResource resource = new FeatureResource.Simple(featureContent, debugContent, "js"); List<FeatureResource> allResources = Lists.newArrayList(resource); final FeatureRegistry.LookupResult lr = createMock(FeatureRegistry.LookupResult.class); expect(lr.getResources()).andReturn(allResources); replay(lr); expect(registry.getAllFeatures()).andReturn(lr).once(); replay(registry); versioner = new AllJsIframeVersioner(registry); verify(registry); }
@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 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()); }
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 registerOverrideFeature() throws Exception { // Feature 1 String content1 = "content1()"; Uri content1Uri = expectResource(content1); Uri feature1Uri = expectResource(xml(BOTTOM_TPL, "gadget", content1Uri.getPath(), null)); String content2 = "content_two()"; Uri content2Uri = expectResource(content2); Uri feature2Uri = expectResource(xml(BOTTOM_TPL, "gadget", content2Uri.getPath(), null)); registry = new TestFeatureRegistry(feature1Uri.toString()); List<FeatureResource> resources1 = registry.getAllFeatures(); assertEquals(1, resources1.size()); assertEquals(content1, resources1.get(0).getContent()); // Register it again, different def. registry = new TestFeatureRegistry(feature2Uri.toString()); List<FeatureResource> resources2 = registry.getAllFeatures(); assertEquals(1, resources2.size()); assertEquals(content2, resources2.get(0).getContent()); // Check cached resources too. List<FeatureResource> resourcesAgain = registry.getAllFeatures(); assertSame(resources2, resourcesAgain); }
@Test public void registerFromResourceIndex() throws Exception { // One with extern resource loaded content... String content1 = "content1()"; Uri content1Uri = expectResource(content1); Uri feature1Uri = expectResource(xml(MID_A_TPL, "gadget", content1Uri.getPath(), null)); // One feature with inline content (that it depends on)... String content2 = "inline()"; Uri feature2Uri = expectResource(xml(BOTTOM_TPL, "gadget", null, content2)); // .txt file to join the two Uri txtFile = expectResource(feature1Uri.toString() + '\n' + feature2Uri.toString(), ".txt"); // Load resources from the text file and do basic validation they're good. registry = new TestFeatureRegistry(txtFile.toString()); // Contents should be ordered based on the way they went in. List<FeatureResource> resources = registry.getAllFeatures(); assertEquals(2, resources.size()); assertEquals(content2, resources.get(0).getContent()); assertEquals(content1, resources.get(1).getContent()); }