@Override @Deprecated public <T> T setConfig(ConfigKey<T> key, T val) { return config().set(key, val); }
@Test public void testConfigEqualTo() throws Exception { loc.config().set(TestEntity.CONF_NAME, "myname"); assertTrue(LocationPredicates.configEqualTo(TestEntity.CONF_NAME, "myname").apply(loc)); assertFalse(LocationPredicates.configEqualTo(TestEntity.CONF_NAME, "wrongname").apply(loc)); }
@Test public void testReturnsFileSuffixFromRequirements() throws Exception { // uses ${driver.downloadFileSuffix} String entityVersion = "myversion"; String fileSuffix = "mysuffix"; String expectedFilename = (entitySimpleType+"-"+entityVersion+"."+fileSuffix).toLowerCase(); entity.config().set(BrooklynConfigKeys.SUGGESTED_VERSION, entityVersion); BasicDownloadRequirement req = new BasicDownloadRequirement(driver, ImmutableMap.of("fileSuffix", fileSuffix)); assertResolves(req, String.format("file://$HOME/.brooklyn/repository/%s/%s/%s", entitySimpleType, entityVersion, expectedFilename)); }
@Test public void testConfigSetterOverridesConstructorValue() throws Exception { TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class) .configure(strKey, "aval")); entity.config().set(strKey, "diffval"); assertEquals(entity.getConfig(strKey), "diffval"); }
@Test public void testConfigCanBeSetOnPolicyBeforeAddedToEntity() throws Exception { MyPolicy policy = new MyPolicy(); policy.config().set(MyPolicy.STR_KEY, "aval"); policy.config().set(MyPolicy.INT_KEY, 2); app.policies().add(policy); assertEquals(policy.getConfig(MyPolicy.STR_KEY), "aval"); assertEquals(policy.getConfig(MyPolicy.INT_KEY), (Integer)2); }
@Test public void testEntitySpecificUrlOverridesGlobalUrl() throws Exception { brooklynProperties.put("brooklyn.downloads.all.url", "version=${version}"); brooklynProperties.put("brooklyn.downloads.entity.TestEntity.url", "overridden,version=${version}"); entity.config().set(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); assertResolves("overridden,version=myversion", "version=myversion"); }
@Test public void testSubstitutionsAppliedToFallbackUrl() throws Exception { brooklynProperties.put("brooklyn.downloads.all.fallbackurl", "version=${version}"); entity.config().set(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion"); assertResolves(ImmutableList.<String>of(), ImmutableList.of("version=myversion")); }
@Test public void testMapConfigSetMod() throws Exception { entity.config().set(TestEntity.CONF_MAP_THING.subKey("akey"), "aval"); entity.config().set(TestEntity.CONF_MAP_THING, MapModifications.set(ImmutableMap.of("bkey","bval"))); assertEquals(entity.getConfig(TestEntity.CONF_MAP_THING), ImmutableMap.of("bkey","bval")); }
@Test // ListConfigKey deprecated, as order no longer guaranteed public void testListConfigKeyAddAllMod() throws Exception { entity.config().set(TestEntity.CONF_LIST_THING.subKey(), "aval"); entity.config().set(TestEntity.CONF_LIST_THING, ListModifications.addAll(ImmutableList.of("bval", "cval"))); //assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), ["aval","bval","cval"]) assertEquals(ImmutableSet.copyOf(entity.getConfig(TestEntity.CONF_LIST_THING)), ImmutableSet.of("aval","bval","cval")); }
@Test // ListConfigKey deprecated, as order no longer guaranteed public void testListConfigKeyAddDirect() throws Exception { entity.config().set(TestEntity.CONF_LIST_THING.subKey(), "aval"); entity.config().set((ConfigKey)TestEntity.CONF_LIST_THING, "bval"); //assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), ["aval","bval"]) assertEquals(ImmutableSet.copyOf(entity.getConfig(TestEntity.CONF_LIST_THING)), ImmutableSet.of("aval","bval")); }
@Test(enabled=false) public void testListDotExtensionUsageMultiValues() throws Exception { entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_LIST_THING.getName()+".a"), "x"); entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_LIST_THING.getName()+".c"), "w"); entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_LIST_THING.getName()+".b"), "x"); log.info("List-DotExt: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), ImmutableList.of("x", "w", "x")); }
@Test(enabled=false) public void testListPutDirectUsageMultiValues() throws Exception { entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_LIST_THING.getName()), ImmutableList.of("x", "w", "x")); log.info("List-Direct: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), ImmutableList.of("x", "w", "x")); }
public void testListDotExtensionUsage() throws Exception { entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_LIST_THING.getName()+".a"), "x"); entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_LIST_THING.getName()+".b"), "x"); log.info("List-DotExt: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), ImmutableList.of("x", "x")); }
public void testListModUsage() throws Exception { entity.config().set(TestEntity.CONF_LIST_THING, ListModifications.add("x", "x")); log.info("List-Mod: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), ImmutableList.of("x", "x")); }
public void testSetManyWays() throws Exception { entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_SET_THING.getName()), ImmutableSet.of("directX")); entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_SET_THING.getName()+".dotext"), "dotextX"); entity.config().set(TestEntity.CONF_SET_THING.subKey(), "subkeyX"); log.info("Set-ManyWays: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_SET_THING), ImmutableSet.of("directX", "subkeyX", "dotextX")); }
public void testSetDotExtensionUsage() throws Exception { entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_SET_THING.getName()+".a"), "x"); log.info("Set-DotExt: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_SET_THING), ImmutableSet.of("x")); }
public void testMapDirectUsage() throws Exception { entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_MAP_OBJ_THING.getName()), ImmutableMap.<String,Object>of("a", 1)); log.info("Map-Direct: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_MAP_OBJ_THING), ImmutableMap.<String,Object>of("a", 1)); }
@Test public void testSetAndGetDynamicConfigUsingDeprecatedName() throws Exception { // Using BasicEntity, which doesn't know about KEY_1 EntityInternal entity = (EntityInternal) app.addChild(EntitySpec.create(BasicEntity.class)); // Set using deprecated name entity.config().putAll(ImmutableMap.of("oldKey1", "myval3")); assertEquals(entity.config().get(KEY_1), "myval3"); // Set using pseudo-generated strongly typed key with deprecated name entity.config().set(ConfigKeys.newConfigKey(Object.class, "oldKey1"), "myval4"); assertEquals(entity.config().get(KEY_1), "myval4"); }
@Test public void testRenameClass() throws Exception { ConfigKey<Object> CONF1 = new BasicConfigKey<Object>(Object.class, "test.conf1"); origApp.config().set(CONF1, new OrigType("myfieldval")); CompoundTransformer transformer = CompoundTransformer.builder() .renameClassTag(OrigType.class.getName(), RenamedType.class.getName()) .build(); newApp = transformAndRebind(transformer); Object newConfVal = newApp.getConfig(CONF1); assertEquals(((RenamedType)newConfVal).myfield, "myfieldval"); }