This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 9b1a8d6ae2618dea4efcd5f3d4ee708d4ab79a04 Author: Alex Heneveld <[email protected]> AuthorDate: Fri Oct 2 00:10:59 2020 +0100 fix remaining tests, remove extra logging --- .../brooklyn/CustomTypeConfigYamlOsgiTest.java | 4 +- .../camp/brooklyn/CustomTypeConfigYamlTest.java | 45 ++++++++++++++-------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlOsgiTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlOsgiTest.java index 3911aae..dd46564 100644 --- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlOsgiTest.java +++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlOsgiTest.java @@ -60,9 +60,7 @@ public class CustomTypeConfigYamlOsgiTest extends CustomTypeConfigYamlTest { OsgiBundleInstallationResult r = result.getWithError(); RegisteredType rt = r.getTypesInstalled().stream().filter(rti -> "sampleBean:0.1.0".equals(rti.getId())).findAny() - .orElseThrow(() -> { - throw Asserts.fail("Bean not found; RTs were: " + r.getTypesInstalled()); - }); + .orElseThrow(() -> Asserts.fail("Bean not found; RTs were: " + r.getTypesInstalled())); Asserts.assertEquals(rt.getKind(), RegisteredTypeKind.BEAN); Object b1 = mgmt().getTypeRegistry().create(rt, null, null); diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlTest.java index 71064b2..34fa2bf 100644 --- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlTest.java +++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/CustomTypeConfigYamlTest.java @@ -101,27 +101,38 @@ public class CustomTypeConfigYamlTest extends AbstractYamlTest { "test.confAnonymous", "Configuration key that's declared as an Object, but not defined on the Entity, and should be our custom type; was it coerced when created?"); public static final ConfigKey<TestingCustomType> CONF_ANONYMOUS_OBJECT_TYPED = ConfigKeys.newConfigKey(TestingCustomType.class, "test.confAnonymous", "Configuration key that's declared as our custom type, matching the key name as the Object, and also not defined on the Entity, and should be our custom type; is it coercible on read with this key (or already coerced)?"); - - public static final ConfigKey<TestingCustomType> CONF_TYPED = ConfigKeys.newConfigKey(TestingCustomType.class, - "test.confTyped", "Configuration key that's our custom type"); + // old behaviour; previously java wouldn't be deserialized, but now if we are in the context of an entity, + // we use its classpath when deserializing + // TODO ideally restrict this behaviour to the outermost layer, where the type is defined (and so we have to use java), + // but make any type: blocks within only valid for registered types +// @Test +// public void testJavaTypeDeclaredInValueOfAnonymousConfigKey_IgnoresType_ReturnsMap() throws Exception { +// // java types are not permitted as the type of a value of a config key - it gets deserialized as a map +// Entity testEntity = deployWithTestingCustomTypeObjectConfig(false, TestingCustomType.class.getName(), CONF_ANONYMOUS_OBJECT); +// Object customObj = testEntity.getConfig(CONF_ANONYMOUS_OBJECT); +// +// Assert.assertNotNull(customObj); +// +// Asserts.assertInstanceOf(customObj, Map.class); +// Asserts.assertEquals(((Map<?,?>)customObj).get("x"), "foo"); +// } +// @Test +// public void testJavaTypeDeclaredInValueOfAnonymousConfigKey_IgnoresType_FailsCoercionToCustomType() throws Exception { +// // and if we try to access it with a typed key it fails +// Asserts.assertFailsWith(() -> deployWithTestingCustomTypeObjectConfigAndAssert(TestingCustomType.class.getName(), CONF_ANONYMOUS_OBJECT_TYPED, "foo", null), +// e -> Asserts.expectedFailureContains(e, "TestingCustomType", "map", "test.confAnonymous")); +// } + // new behaviour, cf above @Test - public void testJavaTypeDeclaredInValueOfAnonymousConfigKey_IgnoresType_ReturnsMap() throws Exception { - // java types are not permitted as the type of a value of a config key - it gets deserialized as a map - Entity testEntity = deployWithTestingCustomTypeObjectConfig(false, TestingCustomType.class.getName(), CONF_ANONYMOUS_OBJECT); - Object customObj = testEntity.getConfig(CONF_ANONYMOUS_OBJECT); - - Assert.assertNotNull(customObj); - - Asserts.assertInstanceOf(customObj, Map.class); - Asserts.assertEquals(((Map<?,?>)customObj).get("x"), "foo"); + public void testJavaTypeDeclaredInValueOfAnonymousConfigKey_TypeInferred() throws Exception { + // java types now set on read, so okay as value for config + deployWithTestingCustomTypeObjectConfigAndAssert(TestingCustomType.class.getName(), CONF_ANONYMOUS_OBJECT_TYPED, "foo", null); } @Test - public void testJavaTypeDeclaredInValueOfAnonymousConfigKey_IgnoresType_FailsCoercionToCustomType() throws Exception { - // and if we try to access it with a typed key it fails - // TODO we might support this - as a type coercion - Asserts.assertFailsWith(() -> deployWithTestingCustomTypeObjectConfigAndAssert(TestingCustomType.class.getName(), CONF_TYPED, "foo", null), - e -> Asserts.expectedFailureContains(e, "TestingCustomType", "map", "test.confTyped")); + public void testJavaTypeDeclaredInValueOfAnonymousConfigKey_TypeMatched() throws Exception { + // java types now set on read, so okay as value for config + deployWithTestingCustomTypeObjectConfigAndAssert(TestingCustomType.class.getName(), CONF_ANONYMOUS_OBJECT_TYPED, "foo", null); } @Test
