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 ConfigurationMetadata.InjectionPointMetaData findOperativeInjectionPoint(AttributeMetadata attribute, String prefix, Problems problems) throws ConfigurationException ConfigurationMetadata.InjectionPointMetaData operativeInjectionPoint = attribute.getInjectionPoint(); String operativeName = null; String operativeValue = null; if (attribute.getInjectionPoint() != null) { replacement = format("replaced. Use '%s' instead.", prefix + attribute.getInjectionPoint().getProperty());
if (attribute.getInjectionPoint().getProperty() != null) { nonDeprecatedAttributes.add(attribute.getName());
if (attribute.getInjectionPoint().getProperty() != null) { nonDeprecatedAttributes.add(attribute.getName());
Set<Method> validSetterMethods = new HashSet<>(); for (AttributeMetadata attribute : metadata.getAttributes().values()) { if (attribute.getInjectionPoint().getProperty() != null) { validSetterMethods.add(attribute.getInjectionPoint().getSetter()); if (invokedMethods.contains(attribute.getInjectionPoint().getSetter())) { if (attribute.getInjectionPoint().getProperty() != null) { Object value = invoke(config, attribute.getGetter()); attributeValues.put(attribute.getName(), value);
if (attribute.getInjectionPoint().getProperty() != null) { nonDeprecatedAttributes.add(attribute.getName());
Set<Method> validSetterMethods = new HashSet<>(); for (AttributeMetadata attribute : metadata.getAttributes().values()) { if (attribute.getInjectionPoint().getProperty() != null) { validSetterMethods.add(attribute.getInjectionPoint().getSetter()); if (invokedMethods.contains(attribute.getInjectionPoint().getSetter())) { if (attribute.getInjectionPoint().getProperty() != null) { Object value = invoke(config, attribute.getGetter()); attributeValues.put(attribute.getName(), value);
private ConfigurationMetadata.InjectionPointMetaData findOperativeInjectionPoint(AttributeMetadata attribute, String prefix, Problems problems) throws ConfigurationException ConfigurationMetadata.InjectionPointMetaData operativeInjectionPoint = attribute.getInjectionPoint(); String operativeName = null; String operativeValue = null; if (value != null) { String replacement = "deprecated."; if (attribute.getInjectionPoint() != null) { replacement = format("replaced. Use '%s' instead.", prefix + attribute.getInjectionPoint().getProperty());
Set<Method> validSetterMethods = new HashSet<>(); for (AttributeMetadata attribute : metadata.getAttributes().values()) { if (attribute.getInjectionPoint().getProperty() != null) { validSetterMethods.add(attribute.getInjectionPoint().getSetter()); if (invokedMethods.contains(attribute.getInjectionPoint().getSetter())) { if (attribute.getInjectionPoint().getProperty() != null) { Object value = invoke(config, attribute.getGetter()); attributeValues.put(attribute.getName(), value);
String propertyName = prefix + attribute.getInjectionPoint().getProperty(); Method getter = attribute.getGetter();
String propertyName = prefix + attribute.getInjectionPoint().getProperty(); Method getter = attribute.getGetter();
String propertyName = prefix + attribute.getInjectionPoint().getProperty(); Method getter = attribute.getGetter();
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); } }
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); } }
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); }