/** * Helper method retrieving feature resources, including transitive dependencies. * @param ctx Context for the request. * @param needed List of all needed features. * @param unsupported If non-null, a List populated with unknown features from the needed list. * @return List of FeatureResources that may be used to render the needed features. */ public LookupResult getFeatureResources(GadgetContext ctx, Collection<String> needed, List<String> unsupported) { return getFeatureResources(ctx, needed, unsupported, true); }
/** * Helper method retrieving feature resources, including transitive dependencies. * @param ctx Context for the request. * @param needed List of all needed features. * @param unsupported If non-null, a List populated with unknown features from the needed list. * @return List of FeatureResources that may be used to render the needed features. */ public List<FeatureResource> getFeatureResources(GadgetContext ctx, Collection<String> needed, List<String> unsupported) { return getFeatureResources(ctx, needed, unsupported, true); }
/** * Helper method retrieving feature resources, including transitive dependencies. * @param ctx Context for the request. * @param needed List of all needed features. * @param unsupported If non-null, a List populated with unknown features from the needed list. * @return List of FeatureResources that may be used to render the needed features. */ public List<FeatureResource> getFeatureResources(GadgetContext ctx, Collection<String> needed, List<String> unsupported) { return getFeatureResources(ctx, needed, unsupported, true); }
/** * Returns all known FeatureResources in dependency order, as described in getFeatureResources. * Returns only GADGET-context resources. This is a convenience method largely for calculating * JS checksum. * @return List of all known (RenderingContext.GADGET) FeatureResources. */ public LookupResult getAllFeatures() { return getFeatureResources(new GadgetContext(), featureMap.keySet(), null); }
/** * Returns all known FeatureResources in dependency order, as described in getFeatureResources. * Returns only GADGET-context resources. This is a convenience method largely for calculating * JS checksum. * @return List of all known (RenderingContext.GADGET) FeatureResources. */ public List<FeatureResource> getAllFeatures() { return getFeatureResources(new GadgetContext(), featureMap.keySet(), null); }
private List<FeatureBundle> getSupportDeferBundles(FeatureRegistry registry, JsRequest jsRequest) { List<FeatureBundle> result = Lists.newArrayList(); LookupResult lookup = registry.getFeatureResources(context.get(), jsRequest.getNewFeatures(), null, false); for (FeatureBundle bundle : lookup.getBundles()) { if (bundle.isSupportDefer()) { result.add(bundle); } } return result; } }
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 expectFeatureLookup() throws GadgetException { List<FeatureResource> swfObjectResources = Lists.newArrayList(); swfObjectResources.add(new SwfResource()); EasyMock.expect(featureRegistry .getFeatureResources(isA(GadgetContext.class), eq(ImmutableSet.of("swfobject")), EasyMock.<List<String>>isNull())).andReturn(swfObjectResources); }
@SuppressWarnings("unchecked") private FeatureRegistry mockRegistry(LookupResult lookupMock) { FeatureRegistry result = createMock(FeatureRegistry.class); expect(result.getFeatureResources( isA(GadgetContext.class), isA(List.class), EasyMock.isNull(List.class))). andReturn(lookupMock).anyTimes(); replay(result); return result; }
@SuppressWarnings("unchecked") private FeatureRegistry mockRegistry(LookupResult lookupMock) { FeatureRegistry result = createMock(FeatureRegistry.class); expect(result.getFeatureResources( isA(GadgetContext.class), isA(List.class), EasyMock.isNull(List.class))). andReturn(lookupMock).anyTimes(); replay(result); return result; }
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(); } }
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(); } }
private void expectReq(String feature, String content) { FeatureResource resource = new FeatureResource.Simple(content, ""); Collection<String> libs = Lists.newArrayList(feature); List<FeatureResource> resources = Lists.newArrayList(resource); expect(registry.getFeatureResources(isA(GadgetContext.class), eq(libs), EasyMock.<List<String>>isNull())).andReturn(resources).anyTimes(); } }
@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); assertEquals(0, resources.size()); // no resource matches but all feature keys valid assertEquals(0, unsupported.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); assertEquals(0, unsupported.size()); assertEquals(2, resources.size()); assertEquals("nodep", resources.get(0).getContent()); assertEquals("bottom", resources.get(1).getContent()); }
@SuppressWarnings("unchecked") private void setupMockRegistry(List<String> features) { EasyMock.expect(mockRegistry.getFeatures(EasyMock.isA(List.class))) .andReturn(Lists.newArrayList(features)).anyTimes(); FeatureBundle featureBundle = createMockFeatureBundle(); FeatureRegistry.LookupResult lr = createMockLookupResult(ImmutableList.of(featureBundle)); EasyMock.expect( mockRegistry.getFeatureResources(isA(GadgetContext.class), eq(Lists.newArrayList(features)), EasyMock.<List<String>> isNull())) .andReturn(lr).anyTimes(); replay(); }
@SuppressWarnings("unchecked") private void setupMockRegistry(List<String> features) { EasyMock.expect(mockRegistry.getFeatures(EasyMock.isA(Collection.class))) .andReturn(Lists.newArrayList(features)).anyTimes(); FeatureBundle featureBundle = createMockFeatureBundle(); FeatureRegistry.LookupResult lr = createMockLookupResult(ImmutableList.of(featureBundle)); EasyMock.expect( mockRegistry.getFeatureResources(isA(GadgetContext.class), eq(Lists.newArrayList(features)), EasyMock.<List<String>> isNull())) .andReturn(lr).anyTimes(); replay(); }
@Test public void filterFeaturesByContainerMatch() throws Exception { // Again test only for gadget case; above tests cover type <-> RenderingContext setupFullRegistry("gadget", "one, two , three"); GadgetContext ctx = getCtx(RenderingContext.GADGET, "two"); List<String> needed = Lists.newArrayList("nodep", "bottom"); List<String> unsupported = Lists.newLinkedList(); List<FeatureResource> resources = registry.getFeatureResources(ctx, needed, unsupported); assertEquals(2, resources.size()); assertEquals("nodep", resources.get(0).getContent()); assertEquals("bottom", resources.get(1).getContent()); assertEquals(0, unsupported.size()); }
@SuppressWarnings("unchecked") private void setupMockRegistry(List<String> features) { EasyMock.expect(mockRegistry.getFeatures(EasyMock.isA(List.class))) .andReturn(Lists.newArrayList(features)).anyTimes(); FeatureBundle featureBundle = createMockFeatureBundle(); FeatureRegistry.LookupResult lr = createMockLookupResult(ImmutableList.of(featureBundle)); EasyMock.expect( mockRegistry.getFeatureResources(isA(GadgetContext.class), eq(Lists.newArrayList(features)), EasyMock.<List<String>> isNull())) .andReturn(lr).anyTimes(); replay(); }