private static <T> void assertAttributesNotEqual(ConfigurationMetadata<T> metadata, T actual, T expected) { for (AttributeMetadata attribute : metadata.getAttributes().values()) { Method getter = attribute.getGetter(); if (getter == null) { continue; } Object actualAttributeValue = invoke(actual, getter); Object expectedAttributeValue = invoke(expected, getter); assertNotEquals(actualAttributeValue, expectedAttributeValue, attribute.getName()); } }
private static <T> void assertAttributesNotEqual(ConfigurationMetadata<T> metadata, T actual, T expected) { for (AttributeMetadata attribute : metadata.getAttributes().values()) { Method getter = attribute.getGetter(); if (getter == null) { continue; } Object actualAttributeValue = invoke(actual, getter); Object expectedAttributeValue = invoke(expected, getter); assertNotEquals(actualAttributeValue, expectedAttributeValue, attribute.getName()); } }
private static <T> void assertAttributesEqual(ConfigurationMetadata<T> metadata, T actual, T expected) { for (AttributeMetadata attribute : metadata.getAttributes().values()) { Method getter = attribute.getGetter(); if (getter == null) { continue; } Object actualAttributeValue = invoke(actual, getter); Object expectedAttributeValue = invoke(expected, getter); assertEquals(actualAttributeValue, expectedAttributeValue, attribute.getName()); } }
private static <T> void assertAttributesEqual(ConfigurationMetadata<T> metadata, T actual, T expected) { for (AttributeMetadata attribute : metadata.getAttributes().values()) { Method getter = attribute.getGetter(); if (getter == null) { continue; } Object actualAttributeValue = invoke(actual, getter); Object expectedAttributeValue = invoke(expected, getter); assertEquals(actualAttributeValue, expectedAttributeValue, attribute.getName()); } }
private static <T> void assertAttributesEqual(ConfigurationMetadata<T> metadata, T actual, T expected) { for (AttributeMetadata attribute : metadata.getAttributes().values()) { Method getter = attribute.getGetter(); if (getter == null) { continue; } Object actualAttributeValue = invoke(actual, getter); Object expectedAttributeValue = invoke(expected, getter); Assert.assertEquals(actualAttributeValue, expectedAttributeValue, attribute.getName()); } }
private static void assertPropertiesSupported(ConfigurationMetadata<?> metadata, Set<String> propertyNames, boolean allowDeprecatedProperties) { Set<String> supportedProperties = new TreeSet<>(); Set<String> nonDeprecatedProperties = new TreeSet<>(); for (AttributeMetadata attribute : metadata.getAttributes().values()) { if (attribute.getInjectionPoint().getProperty() != null) { nonDeprecatedProperties.add(attribute.getInjectionPoint().getProperty()); supportedProperties.add(attribute.getInjectionPoint().getProperty()); } for (ConfigurationMetadata.InjectionPointMetaData deprecated : attribute.getLegacyInjectionPoints()) { supportedProperties.add(deprecated.getProperty()); } } if (!supportedProperties.containsAll(propertyNames)) { TreeSet<String> unsupportedProperties = new TreeSet<>(propertyNames); unsupportedProperties.removeAll(supportedProperties); fail("Unsupported properties: " + unsupportedProperties); } // check for usage of deprecated properties if (!allowDeprecatedProperties && !nonDeprecatedProperties.containsAll(propertyNames)) { TreeSet<String> deprecatedProperties = new TreeSet<>(propertyNames); deprecatedProperties.removeAll(nonDeprecatedProperties); fail("Deprecated properties: " + deprecatedProperties); } }
private static void assertPropertiesSupported(ConfigurationMetadata<?> metadata, Set<String> propertyNames, boolean allowDeprecatedProperties) { Set<String> supportedProperties = new TreeSet<>(); Set<String> nonDeprecatedProperties = new TreeSet<>(); for (AttributeMetadata attribute : metadata.getAttributes().values()) { if (attribute.getInjectionPoint().getProperty() != null) { nonDeprecatedProperties.add(attribute.getInjectionPoint().getProperty()); supportedProperties.add(attribute.getInjectionPoint().getProperty()); } for (ConfigurationMetadata.InjectionPointMetaData deprecated : attribute.getLegacyInjectionPoints()) { supportedProperties.add(deprecated.getProperty()); } } if (!supportedProperties.containsAll(propertyNames)) { TreeSet<String> unsupportedProperties = new TreeSet<>(propertyNames); unsupportedProperties.removeAll(supportedProperties); Assert.fail("Unsupported properties: " + unsupportedProperties); } // check for usage of deprecated properties if (!allowDeprecatedProperties && !nonDeprecatedProperties.containsAll(propertyNames)) { TreeSet<String> deprecatedProperties = new TreeSet<>(propertyNames); deprecatedProperties.removeAll(nonDeprecatedProperties); Assert.fail("Deprecated properties: " + deprecatedProperties); } }
private static void assertPropertiesSupported(ConfigurationMetadata<?> metadata, Set<String> propertyNames, boolean allowDeprecatedProperties) { Set<String> supportedProperties = new TreeSet<>(); Set<String> nonDeprecatedProperties = new TreeSet<>(); for (AttributeMetadata attribute : metadata.getAttributes().values()) { if (attribute.getInjectionPoint().getProperty() != null) { nonDeprecatedProperties.add(attribute.getInjectionPoint().getProperty()); supportedProperties.add(attribute.getInjectionPoint().getProperty()); } for (ConfigurationMetadata.InjectionPointMetaData deprecated : attribute.getLegacyInjectionPoints()) { supportedProperties.add(deprecated.getProperty()); } } if (!supportedProperties.containsAll(propertyNames)) { TreeSet<String> unsupportedProperties = new TreeSet<>(propertyNames); unsupportedProperties.removeAll(supportedProperties); fail("Unsupported properties: " + unsupportedProperties); } // check for usage of deprecated properties if (!allowDeprecatedProperties && !nonDeprecatedProperties.containsAll(propertyNames)) { TreeSet<String> deprecatedProperties = new TreeSet<>(propertyNames); deprecatedProperties.removeAll(nonDeprecatedProperties); fail("Deprecated properties: " + deprecatedProperties); } }
private static <T> void assertAttributesNotEqual(ConfigurationMetadata<T> metadata, T actual, T expected) { for (AttributeMetadata attribute : metadata.getAttributes().values()) { Method getter = attribute.getGetter(); if (getter == null) { continue; } Object actualAttributeValue = invoke(actual, getter); Object expectedAttributeValue = invoke(expected, getter); Assertions.assertNotEquals(actualAttributeValue, expectedAttributeValue, attribute.getName()); } }
public static <T> void assertFullMapping(Map<String, String> properties, T expected) { assertNotNull(properties, "properties"); assertNotNull(expected, "expected"); Class<T> configClass = (Class<T>) expected.getClass(); ConfigurationMetadata<T> metadata = ConfigurationMetadata.getValidConfigurationMetadata(configClass); // verify all supplied properties are supported and not deprecated assertPropertiesSupported(metadata, properties.keySet(), false); // verify that every (non-deprecated) property is tested Set<String> nonDeprecatedProperties = new TreeSet<>(); for (AttributeMetadata attribute : metadata.getAttributes().values()) { if (attribute.getInjectionPoint().getProperty() != null) { nonDeprecatedProperties.add(attribute.getInjectionPoint().getProperty()); } } if (!properties.keySet().equals(nonDeprecatedProperties)) { TreeSet<String> untestedProperties = new TreeSet<>(nonDeprecatedProperties); untestedProperties.removeAll(properties.keySet()); fail("Untested properties " + untestedProperties); } // verify that none of the values are the same as a default for the configuration T actual = newInstance(configClass, properties); T defaultInstance = newDefaultInstance(configClass); assertAttributesNotEqual(metadata, actual, defaultInstance); // verify that a configuration object created from the properties is equivalent to the expected object assertAttributesEqual(metadata, actual, expected); }
public static <T> void assertFullMapping(Map<String, String> properties, T expected) { assertNotNull(properties, "properties"); assertNotNull(expected, "expected"); Class<T> configClass = (Class<T>) expected.getClass(); ConfigurationMetadata<T> metadata = ConfigurationMetadata.getValidConfigurationMetadata(configClass); // verify all supplied properties are supported and not deprecated assertPropertiesSupported(metadata, properties.keySet(), false); // verify that every (non-deprecated) property is tested Set<String> nonDeprecatedProperties = new TreeSet<>(); for (AttributeMetadata attribute : metadata.getAttributes().values()) { if (attribute.getInjectionPoint().getProperty() != null) { nonDeprecatedProperties.add(attribute.getInjectionPoint().getProperty()); } } if (!properties.keySet().equals(nonDeprecatedProperties)) { TreeSet<String> untestedProperties = new TreeSet<>(nonDeprecatedProperties); untestedProperties.removeAll(properties.keySet()); fail("Untested properties " + untestedProperties); } // verify that none of the values are the same as a default for the configuration T actual = newInstance(configClass, properties); T defaultInstance = newDefaultInstance(configClass); assertAttributesNotEqual(metadata, actual, defaultInstance); // verify that a configuration object created from the properties is equivalent to the expected object assertAttributesEqual(metadata, actual, expected); }
public static <T> void assertFullMapping(Map<String, String> properties, T expected) { Assert.assertNotNull(properties, "properties"); Assert.assertNotNull(expected, "expected"); Class<T> configClass = (Class<T>) expected.getClass(); ConfigurationMetadata<T> metadata = ConfigurationMetadata.getValidConfigurationMetadata(configClass); // verify all supplied properties are supported and not deprecated assertPropertiesSupported(metadata, properties.keySet(), false); // verify that every (non-deprecated) property is tested Set<String> nonDeprecatedProperties = new TreeSet<>(); for (AttributeMetadata attribute : metadata.getAttributes().values()) { if (attribute.getInjectionPoint().getProperty() != null) { nonDeprecatedProperties.add(attribute.getInjectionPoint().getProperty()); } } if (!properties.keySet().equals(nonDeprecatedProperties)) { TreeSet<String> untestedProperties = new TreeSet<>(nonDeprecatedProperties); untestedProperties.removeAll(properties.keySet()); Assert.fail("Untested properties " + untestedProperties); } // verify that none of the values are the same as a default for the configuration T actual = newInstance(configClass, properties); T defaultInstance = newDefaultInstance(configClass); assertAttributesNotEqual(metadata, actual, defaultInstance); // verify that a configuration object created from the properties is equivalent to the expected object assertAttributesEqual(metadata, actual, expected); }
private void verifyMetaData(ConfigurationMetadata<?> metadata, Class<?> configClass, String description, Map<String, Set<String>> attributeProperties) throws Exception { Assert.assertEquals(metadata.getConfigClass(), configClass); if (metadata.getConstructor() != null) { Assert.assertEquals(metadata.getConstructor(), configClass.getDeclaredConstructor()); } else { try { configClass.getDeclaredConstructor(); Assert.fail(String.format("Expected configClass [%s] not to have a constructor", configClass.getName())); } catch (NoSuchMethodException expected) { } } Assert.assertEquals(metadata.getAttributes().size(), attributeProperties.keySet().size()); for (String name : attributeProperties.keySet()) { AttributeMetadata attribute = metadata.getAttributes().get(name); Assert.assertEquals(attribute.getConfigClass(), configClass); Set<String> namesToTest = Sets.newHashSet(); namesToTest.add(attribute.getInjectionPoint().getProperty()); for (ConfigurationMetadata.InjectionPointMetaData legacyInjectionPoint : attribute.getLegacyInjectionPoints()) { namesToTest.add(legacyInjectionPoint.getProperty()); } Assert.assertEquals(namesToTest, attributeProperties.get(name)); Assert.assertEquals(attribute.getDescription(), description); } }
private void verifyMetaData(ConfigurationMetadata<?> metadata, Class<?> configClass, String description, boolean securitySensitive, Map<String, Set<String>> attributeProperties) throws Exception { assertEquals(metadata.getConfigClass(), configClass); if (metadata.getConstructor() != null) { assertEquals(metadata.getConstructor(), configClass.getDeclaredConstructor()); } else { try { configClass.getDeclaredConstructor(); fail(String.format("Expected configClass [%s] not to have a constructor", configClass.getName())); } catch (NoSuchMethodException expected) { } } assertEquals(metadata.getAttributes().size(), attributeProperties.keySet().size()); for (String name : attributeProperties.keySet()) { AttributeMetadata attribute = metadata.getAttributes().get(name); assertEquals(attribute.getConfigClass(), configClass); Set<String> namesToTest = new HashSet<>(); namesToTest.add(attribute.getInjectionPoint().getProperty()); for (ConfigurationMetadata.InjectionPointMetaData legacyInjectionPoint : attribute.getLegacyInjectionPoints()) { namesToTest.add(legacyInjectionPoint.getProperty()); } assertEquals(namesToTest, attributeProperties.get(name)); assertEquals(attribute.getDescription(), description); assertEquals(attribute.isSecuritySensitive(), securitySensitive); } }
private void verifyMetaData(ConfigurationMetadata<?> metadata, Class<?> configClass, String description, boolean securitySensitive, Map<String, Set<String>> attributeProperties) throws Exception { assertEquals(metadata.getConfigClass(), configClass); if (metadata.getConstructor() != null) { assertEquals(metadata.getConstructor(), configClass.getDeclaredConstructor()); } else { try { configClass.getDeclaredConstructor(); fail(String.format("Expected configClass [%s] not to have a constructor", configClass.getName())); } catch (NoSuchMethodException expected) { } } assertEquals(metadata.getAttributes().size(), attributeProperties.keySet().size()); for (String name : attributeProperties.keySet()) { AttributeMetadata attribute = metadata.getAttributes().get(name); assertEquals(attribute.getConfigClass(), configClass); Set<String> namesToTest = new HashSet<>(); namesToTest.add(attribute.getInjectionPoint().getProperty()); for (ConfigurationMetadata.InjectionPointMetaData legacyInjectionPoint : attribute.getLegacyInjectionPoints()) { namesToTest.add(legacyInjectionPoint.getProperty()); } assertEquals(namesToTest, attributeProperties.get(name)); assertEquals(attribute.getDescription(), description); assertEquals(attribute.isSecuritySensitive(), securitySensitive); } }
@Test public void testEquivalence() { equivalenceTester() .addEquivalentGroup( ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class), ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class)) .addEquivalentGroup( ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class), ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class)) .check(); equivalenceTester() .addEquivalentGroup( ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class).getAttributes().get("Value"), ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class).getAttributes().get("Value")) .addEquivalentGroup( ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class).getAttributes().get("Value"), ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class).getAttributes().get("Value")) .check(); }
@Test public void testEquivalence() { equivalenceTester() .addEquivalentGroup( ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class), ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class)) .addEquivalentGroup( ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class), ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class)) .check(); equivalenceTester() .addEquivalentGroup( ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class).getAttributes().get("Value"), ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class).getAttributes().get("Value")) .addEquivalentGroup( ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class).getAttributes().get("Value"), ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class).getAttributes().get("Value")) .check(); }
@Test public void testEquivalence() { equivalenceTester() .addEquivalentGroup( ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class), ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class) ) .addEquivalentGroup( ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class), ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class) ) .check(); equivalenceTester() .addEquivalentGroup( ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class).getAttributes().get("Value"), ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class).getAttributes().get("Value") ) .addEquivalentGroup( ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class).getAttributes().get("Value"), ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class).getAttributes().get("Value") ) .check(); }
for (AttributeMetadata attribute : metadata.getAttributes().values()) { String propertyName = prefix + attribute.getInjectionPoint().getProperty(); Method getter = attribute.getGetter();
for (AttributeMetadata attribute : metadata.getAttributes().values()) { String propertyName = prefix + attribute.getInjectionPoint().getProperty(); Method getter = attribute.getGetter();