protected final List<JsContent> getSurfaceJsContents( FeatureRegistry featureRegistry, String featureName) { ImmutableList.Builder<JsContent> result = ImmutableList.builder(); LookupResult lookup = featureRegistry.getFeatureResources(context.get(), ImmutableList.of(featureName), null); for (FeatureBundle bundle : lookup.getBundles()) { for (FeatureResource resource : bundle.getResources()) { result.add(JsContent.fromFeature( resource.getDebugContent(), resource.getName(), bundle, resource)); } } return result.build(); }
@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()); }
LookupResult result = new LookupResult(bundlesBuilder.build()); if (useCache && (unsupported == null || unsupported.isEmpty())) { cache.addElement(cacheKey, result);
List<String> emptyList = Lists.newLinkedList(); final FeatureRegistry.LookupResult externLr = createMock(FeatureRegistry.LookupResult.class); expect(externLr.getResources()).andReturn(externResources); replay(externLr); final FeatureRegistry.LookupResult gadgetLr = createMock(FeatureRegistry.LookupResult.class); expect(gadgetLr.getResources()).andReturn(gadgetResources); replay(gadgetLr); expect(featureRegistry.getFeatureResources(same(gadgetContext), eq(externLibs), eq(emptyList)))
List<String> unsupported = Lists.newArrayList(); List<FeatureResource> resources = registry.getFeatureResources( getCtx(RenderingContext.GADGET, theContainer), needed, unsupported).getResources(); getCtx(RenderingContext.GADGET, "foo"), needed, unsupported).getResources(); getCtx(RenderingContext.CONTAINER, theContainer), needed, unsupported).getResources(); getCtx(RenderingContext.GADGET, theContainer), needed, unsupported).getResources(); assertSame(resources, resources2); getCtx(RenderingContext.GADGET, "foo"), needed, unsupported).getResources(); assertSame(resourcesNoMatch, resourcesNoMatch2); getCtx(RenderingContext.CONTAINER, theContainer), needed, unsupported).getResources(); assertSame(ctxMismatch, ctxMismatch2); getCtx(RenderingContext.GADGET, theContainer, true), needed, unsupported).getResources(); assertNotSame(resources, resourcesIC);
List<String> emptyList = Lists.newLinkedList(); final FeatureRegistry.LookupResult externLr = createMock(FeatureRegistry.LookupResult.class); expect(externLr.getResources()).andReturn(externResources); replay(externLr); final FeatureRegistry.LookupResult gadgetLr = createMock(FeatureRegistry.LookupResult.class); expect(gadgetLr.getResources()).andReturn(gadgetResources); replay(gadgetLr); expect(featureRegistry.getFeatureResources(same(gadgetContext), eq(externLibs), eq(emptyList)))
List<String> unsupported = Lists.newArrayList(); List<FeatureResource> resources = registry.getFeatureResources( getCtx(RenderingContext.GADGET, theContainer), needed, unsupported).getResources(); getCtx(RenderingContext.GADGET, "foo"), needed, unsupported).getResources(); getCtx(RenderingContext.CONTAINER, theContainer), needed, unsupported).getResources(); getCtx(RenderingContext.GADGET, theContainer), needed, unsupported).getResources(); assertSame(resources, resources2); getCtx(RenderingContext.GADGET, "foo"), needed, unsupported).getResources(); assertSame(resourcesNoMatch, resourcesNoMatch2); getCtx(RenderingContext.CONTAINER, theContainer), needed, unsupported).getResources(); assertSame(ctxMismatch, ctxMismatch2); getCtx(RenderingContext.GADGET, theContainer, true), needed, unsupported).getResources(); assertNotSame(resources, resourcesIC);
expect(lr.getResources()).andReturn(ImmutableList.<FeatureResource>of()).anyTimes(); replay(lr); expect(featureRegistry.getFeatureResources(same(gadget.getContext()),
expect(lr.getResources()).andReturn(ImmutableList.<FeatureResource>of()).anyTimes(); replay(lr); expect(featureRegistry.getFeatureResources(same(gadget.getContext()),
expect(lr.getResources()).andReturn(ImmutableList.<FeatureResource>of()); replay(lr); expect(featureRegistry.getFeatureResources(same(gadget.getContext()), .andReturn(lr); final FeatureRegistry.LookupResult lr2 = createMock(FeatureRegistry.LookupResult.class); expect(lr2.getResources()).andReturn(ImmutableList.<FeatureResource>of()); replay(lr2); assertTrue(gadget.getDirectFeatureDeps().contains("core"));
expect(lr.getResources()).andReturn(ImmutableList.<FeatureResource>of()); replay(lr); expect(featureRegistry.getFeatureResources(same(gadget.getContext()), .andReturn(lr); final FeatureRegistry.LookupResult lr2 = createMock(FeatureRegistry.LookupResult.class); expect(lr2.getResources()).andReturn(ImmutableList.<FeatureResource>of()); replay(lr2); assertTrue(gadget.getDirectFeatureDeps().contains("core"));
expect(lr.getResources()).andReturn(ImmutableList.<FeatureResource>of()); replay(lr); expect(featureRegistry.getFeatureResources(same(gadget.getContext()), .andReturn(lr); final FeatureRegistry.LookupResult lr2 = createMock(FeatureRegistry.LookupResult.class); expect(lr2.getResources()).andReturn(ImmutableList.<FeatureResource>of()); replay(lr2); assertTrue(gadget.getDirectFeatureDeps().contains("core"));
List<String> unsupported = Lists.newArrayList(); List<FeatureResource> resources = registry.getFeatureResources( getCtx(RenderingContext.GADGET, theContainer), needed, unsupported).getResources(); getCtx(RenderingContext.GADGET, theContainer), needed, null).getResources(); getCtx(RenderingContext.GADGET, theContainer), needed, unsupported).getResources(); assertSame(resources, resources2); getCtx(RenderingContext.GADGET, theContainer), needed, null).getResources(); assertSame(resourcesUnsup, resourcesUnsup2); getCtx(RenderingContext.GADGET, theContainer, true), needed, unsupported).getResources(); assertNotSame(resources, resourcesIgnoreCache); assertEquals(1, resourcesIgnoreCache.size());
ctx, jsUri.getLibs(), null).getBundles(); List<FeatureBundle> loadedBundles = registry.getFeatureResources( ctx, jsUri.getLoadedLibs(), null).getBundles();
List<String> unsupported = Lists.newArrayList(); List<FeatureResource> resources = registry.getFeatureResources( getCtx(RenderingContext.GADGET, theContainer), needed, unsupported).getResources(); getCtx(RenderingContext.GADGET, theContainer), needed, null).getResources(); getCtx(RenderingContext.GADGET, theContainer), needed, unsupported).getResources(); assertSame(resources, resources2); getCtx(RenderingContext.GADGET, theContainer), needed, null).getResources(); assertSame(resourcesUnsup, resourcesUnsup2); getCtx(RenderingContext.GADGET, theContainer, true), needed, unsupported).getResources(); assertNotSame(resources, resourcesIgnoreCache); assertEquals(1, resourcesIgnoreCache.size());
List<String> unsupported = Lists.newArrayList(); List<FeatureResource> resources = registry.getFeatureResources( getCtx(RenderingContext.GADGET, theContainer), needed, unsupported).getResources();
expect(lr.getResources()).andReturn(ImmutableList.<FeatureResource>of()); replay(lr); expect(featureRegistry.getFeatureResources(same(gadget.getContext()), .andReturn(lr); final FeatureRegistry.LookupResult lr2 = createMock(FeatureRegistry.LookupResult.class); expect(lr2.getResources()).andReturn(ImmutableList.<FeatureResource>of()); replay(lr2); assertTrue(gadget.getDirectFeatureDeps().contains("core"));
@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()); }
@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); }
List<String> unsupported = Lists.newArrayList(); List<FeatureResource> resources = registry.getFeatureResources( getCtx(RenderingContext.GADGET, theContainer), needed, unsupported).getResources();