@SuppressWarnings("unchecked") private List<String> getEndpointsFromContainerConfig(String container, String host) { Map<String, Object> properties = (Map<String, Object>) containerConfig.getMap(container, GADGETS_FEATURES_CONFIG).get(OSAPI_FEATURE_CONFIG); if (properties != null) { return (List<String>) properties.get(OSAPI_BASE_ENDPOINTS); } return ImmutableList.of(); }
@SuppressWarnings("unchecked") protected List<String> getEndpointsFromContainerConfig(String container, String host) { Map<String, Object> properties = (Map<String, Object>) containerConfig.getMap(container, GADGETS_FEATURES_CONFIG).get(OSAPI_FEATURE_CONFIG); if (properties != null) { return (List<String>) properties.get(OSAPI_BASE_ENDPOINTS); } return ImmutableList.of(); }
@SuppressWarnings("unchecked") private List<String> getEndpointsFromContainerConfig(String container, String host) { Map<String, Object> properties = (Map<String, Object>) containerConfig.getMap(container, GADGETS_FEATURES_CONFIG).get(OSAPI_FEATURE_CONFIG); if (properties != null) { return (List<String>) properties.get(OSAPI_BASE_ENDPOINTS); } return ImmutableList.of(); }
public void containersChanged(ContainerConfig config, Collection<String> changed, Collection<String> removed) { for (String container : changed) { Integer maxPostSize = config.getInt(container, MAX_POST_SIZE_KEY); if (maxPostSize == 0) { maxPostSize = MAX_POST_SIZE_DEFAULT; } maxPostSizes.put(container, maxPostSize); Map<String, Map<String, String>> features = config.getMap(container, GADGETS_FEATURES); if (features != null) { Map<String, String> coreIO = (Map<String, String>) features.get(CORE_IO); if (coreIO != null) { unparseableCruftMsgs.put(container, coreIO.get(UNPARSEABLE_CRUFT)); } } } for (String container : removed) { maxPostSizes.remove(container); unparseableCruftMsgs.remove(container); } } }
public Map<String, Object> getConfig(String container, List<String> features, String host, Gadget gadget) { Map<String, Object> config = Maps.newHashMap(); // Perform global config for (ConfigContributor contrib : globalContributors) { contribute(contrib, config, container, host, gadget); } // Append some container specific things Map<String, Object> featureConfig = containerConfig.getMap(container, GADGETS_FEATURES_KEY); if (featureConfig != null) { // Discard what we don't care about. for (String name : features) { Object conf = featureConfig.get(name); // Add from containerConfig. if (conf != null) { config.put(name, conf); } contribute(featureContributors.get(name), config, container, host, gadget); } } return config; }
/** * Returns the services, keyed by endpoint for the given container. * * @param container The particular container whose services we want. * @return Map endpoints and their serviceMethod list */ public Multimap<String, String> getServicesForContainer(String container, String host) { if (containerConfig == null) { return ImmutableMultimap.<String, String>builder().build(); } LinkedHashMultimap<String, String> endpointServices = LinkedHashMultimap.create(); // First check services directly declared in container config @SuppressWarnings("unchecked") Map<String, Object> declaredServices = (Map<String, Object>) containerConfig.getMap(container, GADGETS_FEATURES_CONFIG).get(OSAPI_SERVICES); if (declaredServices != null) { for (Map.Entry<String, Object> entry : declaredServices.entrySet()) { @SuppressWarnings("unchecked") Iterable<String> entryValue = (Iterable<String>) entry.getValue(); endpointServices.putAll(entry.getKey(), entryValue); } } // Merge services lazily loaded from the endpoints if any List<String> endpoints = getEndpointsFromContainerConfig(container, host); for (String endpoint : endpoints) { endpointServices.putAll(endpoint, retrieveServices(endpoint.replace("%host%", host))); } return ImmutableMultimap.copyOf(endpointServices); }
@Before public void setUp() { config = createMock(ContainerConfig.class); expect(config.getMap(CONTAINER, DefaultConfigProcessor.GADGETS_FEATURES_KEY)).andReturn(CONFIG_FEATURE_MAP); replay(config); }
@Before public void setUp() { config = createMock(ContainerConfig.class); expect(config.getMap(CONTAINER, DefaultConfigProcessor.GADGETS_FEATURES_KEY)).andReturn(CONFIG_FEATURE_MAP); replay(config); }
private void checkNoFeaturesDoesNothing(RenderingContext ctx) throws Exception { JsResponseBuilder builder = prepareRequestReturnBuilder(ctx); expect(containerConfig.getMap(CONTAINER, ConfigInjectionProcessor.GADGETS_FEATURES_KEY)) .andReturn(null); List<String> libs = ImmutableList.of(); expect(jsUri.getLibs()).andReturn(libs); expect(jsUri.getLoadedLibs()).andReturn(EMPTY_LIST); expect(registry.getFeatures(libs)).andReturn(libs); expect(request.getHost()).andReturn("host"); control.replay(); assertTrue(processor.process(request, builder)); control.verify(); assertEquals(BASE_CODE, builder.build().toJsString()); }
private void checkNoMatchingFeaturesDoesNothing(RenderingContext ctx) throws Exception { JsResponseBuilder builder = prepareRequestReturnBuilder(ctx); Map<String, Object> baseConfig = Maps.newHashMap(); baseConfig.put("feature1", "config1"); Map<String, String> f2MapConfig = Maps.newHashMap(); f2MapConfig.put("key1", "val1"); f2MapConfig.put("key2", "val2"); baseConfig.put("feature2", f2MapConfig); expect(containerConfig.getMap(CONTAINER, ConfigInjectionProcessor.GADGETS_FEATURES_KEY)) .andReturn(baseConfig); List<String> libs = ImmutableList.of("lib1", "lib2"); expect(jsUri.getLibs()).andReturn(libs); expect(jsUri.getLoadedLibs()).andReturn(EMPTY_LIST); expect(registry.getFeatures(libs)).andReturn(libs); expect(request.getHost()).andReturn("host"); control.replay(); assertTrue(processor.process(request, builder)); control.verify(); assertEquals(BASE_CODE, builder.build().toJsString()); }
private void checkNoFeaturesDoesNothing(RenderingContext ctx) throws Exception { JsResponseBuilder builder = prepareRequestReturnBuilder(ctx); expect(containerConfig.getMap(CONTAINER, ConfigInjectionProcessor.GADGETS_FEATURES_KEY)) .andReturn(null); List<String> libs = ImmutableList.of(); expect(jsUri.getLibs()).andReturn(libs); expect(jsUri.getLoadedLibs()).andReturn(EMPTY_LIST); expect(registry.getFeatures(libs)).andReturn(libs); expect(request.getHost()).andReturn("host"); control.replay(); assertTrue(processor.process(request, builder)); control.verify(); assertEquals(BASE_CODE, builder.build().toJsString()); }
private void checkNoMatchingFeaturesDoesNothing(RenderingContext ctx) throws Exception { JsResponseBuilder builder = prepareRequestReturnBuilder(ctx); Map<String, Object> baseConfig = Maps.newHashMap(); baseConfig.put("feature1", "config1"); Map<String, String> f2MapConfig = Maps.newHashMap(); f2MapConfig.put("key1", "val1"); f2MapConfig.put("key2", "val2"); baseConfig.put("feature2", f2MapConfig); expect(containerConfig.getMap(CONTAINER, ConfigInjectionProcessor.GADGETS_FEATURES_KEY)) .andReturn(baseConfig); List<String> libs = ImmutableList.of("lib1", "lib2"); expect(jsUri.getLibs()).andReturn(libs); expect(jsUri.getLoadedLibs()).andReturn(EMPTY_LIST); expect(registry.getFeatures(libs)).andReturn(libs); expect(request.getHost()).andReturn("host"); control.replay(); assertTrue(processor.process(request, builder)); control.verify(); assertEquals(BASE_CODE, builder.build().toJsString()); }
@Test public void parseWithDefaultInheritance() throws Exception { JSONObject json = new JSONObject(); json.put(CONTAINER_KEY, new String[]{CHILD_CONTAINER}); json.put(PARENT_KEY, DEFAULT_CONTAINER); json.put(ARRAY_NAME, ARRAY_ALT_VALUE); // small nested data. JSONObject nested = new JSONObject(); nested.put(NESTED_NAME, NESTED_ALT_VALUE); json.put(NESTED_KEY, nested); File childFile = createContainer(json); File parentFile = createDefaultContainer(); ContainerConfig config = new JsonContainerConfig(childFile.getAbsolutePath() + JsonContainerConfigLoader.FILE_SEPARATOR + parentFile.getAbsolutePath(), Expressions.forTesting()); String value = config.getString(CHILD_CONTAINER, TOP_LEVEL_NAME); assertEquals(TOP_LEVEL_VALUE, value); Map<String, Object> nestedObj = config.getMap(CHILD_CONTAINER, NESTED_KEY); String nestedValue = nestedObj.get(NESTED_NAME).toString(); assertEquals(NESTED_ALT_VALUE, nestedValue); String arrayValue = config.getString(CHILD_CONTAINER, ARRAY_NAME); assertEquals(ARRAY_ALT_VALUE, arrayValue); // Verify that the parent value wasn't overwritten as well. List<String> actual = new ArrayList<String>(); for (Object val : config.getList(DEFAULT_CONTAINER, ARRAY_NAME)) { actual.add(val.toString()); } List<String> expected = Arrays.asList(ARRAY_VALUE); assertEquals(expected, actual); }
@Test public void parseBasicConfig() throws Exception { ContainerConfig config = new JsonContainerConfig(createDefaultContainer().getAbsolutePath(), Expressions.forTesting()); assertEquals(1, config.getContainers().size()); for (String container : config.getContainers()) { assertEquals(DEFAULT_CONTAINER, container); } String value = config.getString(DEFAULT_CONTAINER, TOP_LEVEL_NAME); assertEquals(TOP_LEVEL_VALUE, value); Map<String, Object> nested = config.getMap(DEFAULT_CONTAINER, NESTED_KEY); String nestedValue = nested.get(NESTED_NAME).toString(); assertEquals(NESTED_VALUE, nestedValue); }
@Test public void parseBasicConfig() throws Exception { ContainerConfig config = new JsonContainerConfig(createDefaultContainer().getAbsolutePath(), Expressions.forTesting()); assertEquals(1, config.getContainers().size()); for (String container : config.getContainers()) { assertEquals(DEFAULT_CONTAINER, container); } String value = config.getString(DEFAULT_CONTAINER, TOP_LEVEL_NAME); assertEquals(TOP_LEVEL_VALUE, value); Map<String, Object> nested = config.getMap(DEFAULT_CONTAINER, NESTED_KEY); String nestedValue = nested.get(NESTED_NAME).toString(); assertEquals(NESTED_VALUE, nestedValue); }
@Test public void parseBasicConfig() throws Exception { ContainerConfig config = new JsonContainerConfig(createDefaultContainer().getAbsolutePath(), Expressions.forTesting()); assertEquals(1, config.getContainers().size()); for (String container : config.getContainers()) { assertEquals(DEFAULT_CONTAINER, container); } String value = config.getString(DEFAULT_CONTAINER, TOP_LEVEL_NAME); assertEquals(TOP_LEVEL_VALUE, value); Map<String, Object> nested = config.getMap(DEFAULT_CONTAINER, NESTED_KEY); String nestedValue = nested.get(NESTED_NAME).toString(); assertEquals(NESTED_VALUE, nestedValue); }
@Test public void parseBasicConfig() throws Exception { ContainerConfig config = new JsonContainerConfig(createDefaultContainer().getAbsolutePath(), Expressions.forTesting()); assertEquals(1, config.getContainers().size()); for (String container : config.getContainers()) { assertEquals(DEFAULT_CONTAINER, container); } String value = config.getString(DEFAULT_CONTAINER, TOP_LEVEL_NAME); assertEquals(TOP_LEVEL_VALUE, value); Map<String, Object> nested = config.getMap(DEFAULT_CONTAINER, NESTED_KEY); String nestedValue = nested.get(NESTED_NAME).toString(); assertEquals(NESTED_VALUE, nestedValue); }
@Test public void parseBasicConfig() throws Exception { ContainerConfig config = new JsonContainerConfig(createDefaultContainer().getAbsolutePath(), Expressions.forTesting()); assertEquals(1, config.getContainers().size()); for (String container : config.getContainers()) { assertEquals(DEFAULT_CONTAINER, container); } String value = config.getString(DEFAULT_CONTAINER, TOP_LEVEL_NAME); assertEquals(TOP_LEVEL_VALUE, value); Map<String, Object> nested = config.getMap(DEFAULT_CONTAINER, NESTED_KEY); String nestedValue = nested.get(NESTED_NAME).toString(); assertEquals(NESTED_VALUE, nestedValue); }
@Test public void testPropertyTypes() throws Exception { String container = "misc"; config.newTransaction().addContainer(makeContainer("misc", "bool", Boolean.valueOf(true), "bool2", "true", "badbool", Integer.valueOf(1234), "badbool2", "notabool", "int", Integer.valueOf(1234), "int2", "1234", "badint", "notanint", "string", "abcd", "list", ImmutableList.of("a"), "badlist", "notalist", "map", ImmutableMap.of("a", "b"), "badmap", "notamap")).commit(); assertEquals(true, config.getBool(container, "bool")); assertEquals(true, config.getBool(container, "bool2")); assertEquals(false, config.getBool(container, "badbool")); assertEquals(false, config.getBool(container, "badbool2")); assertEquals(1234, config.getInt(container, "int")); assertEquals(1234, config.getInt(container, "int2")); assertEquals(0, config.getInt(container, "badint")); assertEquals("abcd", config.getString(container, "string")); assertEquals(ImmutableList.of("a"), config.getList(container, "list")); assertTrue(config.getList(container, "badlist").isEmpty()); assertEquals(ImmutableMap.of("a", "b"), config.getMap(container, "map")); assertTrue(config.getMap(container, "badmap").isEmpty()); }
@Test public void testPropertyTypes() throws Exception { String container = "misc"; config.newTransaction().addContainer(makeContainer("misc", "bool", Boolean.valueOf(true), "bool2", "true", "badbool", Integer.valueOf(1234), "badbool2", "notabool", "int", Integer.valueOf(1234), "int2", "1234", "badint", "notanint", "string", "abcd", "list", ImmutableList.of("a"), "badlist", "notalist", "map", ImmutableMap.of("a", "b"), "badmap", "notamap")).commit(); assertEquals(true, config.getBool(container, "bool")); assertEquals(true, config.getBool(container, "bool2")); assertEquals(false, config.getBool(container, "badbool")); assertEquals(false, config.getBool(container, "badbool2")); assertEquals(1234, config.getInt(container, "int")); assertEquals(1234, config.getInt(container, "int2")); assertEquals(0, config.getInt(container, "badint")); assertEquals("abcd", config.getString(container, "string")); assertEquals(ImmutableList.of("a"), config.getList(container, "list")); assertTrue(config.getList(container, "badlist").isEmpty()); assertEquals(ImmutableMap.of("a", "b"), config.getMap(container, "map")); assertTrue(config.getMap(container, "badmap").isEmpty()); }