use of io.airlift.configuration.ConfigurationMetadata.AttributeMetadata in project airlift by airlift.
the class ConfigAssertions method assertAttributesNotEqual.
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);
if (Objects.deepEquals(actualAttributeValue, expectedAttributeValue)) {
throw new AssertionError("Attribute value matches the default: " + attribute.getName());
}
}
}
use of io.airlift.configuration.ConfigurationMetadata.AttributeMetadata in project airlift by airlift.
the class ConfigAssertions method assertFullMapping.
public static <T> void assertFullMapping(Map<String, String> properties, T expected) {
requireNonNull(properties, "properties");
requireNonNull(expected, "expected");
Class<T> configClass = getClass(expected);
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)) {
Set<String> untestedProperties = new TreeSet<>(nonDeprecatedProperties);
untestedProperties.removeAll(properties.keySet());
throw new AssertionError("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);
}
use of io.airlift.configuration.ConfigurationMetadata.AttributeMetadata in project airlift by airlift.
the class ConfigAssertions method assertAttributesEqual.
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);
if (!Objects.deepEquals(actualAttributeValue, expectedAttributeValue)) {
throw new AssertionError(notEquals(attribute.getName(), actualAttributeValue, expectedAttributeValue));
}
}
}
use of io.airlift.configuration.ConfigurationMetadata.AttributeMetadata in project airlift by airlift.
the class ConfigAssertions method assertDeprecatedEquivalence.
@SafeVarargs
public static <T> void assertDeprecatedEquivalence(Class<T> configClass, Map<String, String> currentProperties, Map<String, String>... oldPropertiesList) {
requireNonNull(configClass, "configClass");
requireNonNull(currentProperties, "currentProperties");
requireNonNull(oldPropertiesList, "oldPropertiesList");
ConfigurationMetadata<T> metadata = ConfigurationMetadata.getValidConfigurationMetadata(configClass);
// verify all current properties are supported and not deprecated
assertPropertiesSupported(metadata, currentProperties.keySet(), false);
// verify all old properties are supported (deprecation allowed)
for (Map<String, String> evenOlderProperties : oldPropertiesList) {
assertPropertiesSupported(metadata, evenOlderProperties.keySet(), true);
}
// verify that all deprecated properties are tested
Set<String> knownDeprecatedProperties = new TreeSet<>();
for (AttributeMetadata attribute : metadata.getAttributes().values()) {
for (ConfigurationMetadata.InjectionPointMetaData deprecated : attribute.getLegacyInjectionPoints()) {
knownDeprecatedProperties.add(deprecated.getProperty());
}
}
Set<String> suppliedDeprecatedProperties = new TreeSet<>();
for (Map<String, String> evenOlderProperties : oldPropertiesList) {
suppliedDeprecatedProperties.addAll(evenOlderProperties.keySet());
}
if (!suppliedDeprecatedProperties.containsAll(knownDeprecatedProperties)) {
Set<String> untestedDeprecatedProperties = new TreeSet<>(knownDeprecatedProperties);
untestedDeprecatedProperties.removeAll(suppliedDeprecatedProperties);
throw new AssertionError("Untested deprecated properties: " + untestedDeprecatedProperties);
}
// verify property sets create equivalent configurations
T currentConfiguration = newInstance(configClass, currentProperties);
for (Map<String, String> evenOlderProperties : oldPropertiesList) {
T evenOlderConfiguration = newInstance(configClass, evenOlderProperties);
assertAttributesEqual(metadata, currentConfiguration, evenOlderConfiguration);
}
}
use of io.airlift.configuration.ConfigurationMetadata.AttributeMetadata in project airlift by airlift.
the class TestConfigurationMetadata method verifyMetaData.
private void verifyMetaData(ConfigurationMetadata<?> metadata, Class<?> configClass, String description, boolean securitySensitive, boolean hidden, 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);
assertEquals(attribute.isHidden(), hidden);
}
}
Aggregations