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); }
@SafeVarargs public static <T> void assertDeprecatedEquivalence( Class<T> configClass, Map<String, String> currentProperties, Map<String, String>... oldPropertiesList) { Assert.assertNotNull(configClass, "configClass"); Assert.assertNotNull(currentProperties, "currentProperties"); Assert.assertNotNull(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)) { TreeSet<String> untestedDeprecatedProperties = new TreeSet<>(knownDeprecatedProperties); untestedDeprecatedProperties.removeAll(suppliedDeprecatedProperties); Assert.fail("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); } }