diff --git a/cdi/src/main/java/io/smallrye/config/inject/ConfigExtension.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigExtension.java index 4cf745669..5bbd60451 100644 --- a/cdi/src/main/java/io/smallrye/config/inject/ConfigExtension.java +++ b/cdi/src/main/java/io/smallrye/config/inject/ConfigExtension.java @@ -17,7 +17,6 @@ import static io.smallrye.config.ConfigMappings.registerConfigMappings; import static io.smallrye.config.ConfigMappings.registerConfigProperties; -import static io.smallrye.config.ConfigMappings.ConfigClassWithPrefix.configClassWithPrefix; import static io.smallrye.config.inject.ConfigProducer.isClassHandledByConfigProducer; import static io.smallrye.config.inject.InjectionMessages.formatInjectionPoint; import static io.smallrye.config.inject.SecuritySupport.getContextClassLoader; @@ -57,7 +56,7 @@ import org.eclipse.microprofile.config.inject.ConfigProperty; import io.smallrye.config.ConfigMapping; -import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix; +import io.smallrye.config.ConfigMappings.ConfigClass; import io.smallrye.config.ConfigValidationException; import io.smallrye.config.SmallRyeConfig; @@ -69,13 +68,13 @@ public class ConfigExtension implements Extension { private final Set configPropertyInjectionPoints = new HashSet<>(); /** ConfigProperties for SmallRye Config */ - private final Set configProperties = new HashSet<>(); + private final Set configProperties = new HashSet<>(); /** ConfigProperties for CDI */ - private final Set configPropertiesBeans = new HashSet<>(); + private final Set configPropertiesBeans = new HashSet<>(); /** ConfigMappings for SmallRye Config */ - private final Set configMappings = new HashSet<>(); + private final Set configMappings = new HashSet<>(); /** ConfigMappings for CDI */ - private final Set configMappingBeans = new HashSet<>(); + private final Set configMappingBeans = new HashSet<>(); public ConfigExtension() { } @@ -95,20 +94,16 @@ protected void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManage protected void processConfigProperties( @Observes @WithAnnotations(ConfigProperties.class) ProcessAnnotatedType processAnnotatedType) { // Even if we filter in the CDI event, beans containing injection points of ConfigProperties are also fired. - if (processAnnotatedType.getAnnotatedType().isAnnotationPresent(ConfigProperties.class)) { + AnnotatedType annotatedType = processAnnotatedType.getAnnotatedType(); + if (annotatedType.isAnnotationPresent(ConfigProperties.class)) { // We are going to veto, because it may be a managed bean, and we will use a configurator bean processAnnotatedType.veto(); // Each config class is both in SmallRyeConfig and managed by a configurator bean. // CDI requires more beans for injection points due to binding prefix. - ConfigClassWithPrefix properties = configClassWithPrefix(processAnnotatedType.getAnnotatedType().getJavaClass(), - processAnnotatedType.getAnnotatedType().getAnnotation(ConfigProperties.class).prefix()); - // Unconfigured is represented as an empty String in SmallRye Config - if (!properties.getPrefix().equals(ConfigProperties.UNCONFIGURED_PREFIX)) { - configProperties.add(properties); - } else { - configProperties.add(ConfigClassWithPrefix.configClassWithPrefix(properties.getKlass(), "")); - } + ConfigClass properties = ConfigClass.configClass(annotatedType.getJavaClass(), + annotatedType.getAnnotation(ConfigProperties.class).prefix()); + configProperties.add(properties); configPropertiesBeans.add(properties); } } @@ -116,27 +111,28 @@ protected void processConfigProperties( protected void processConfigMappings( @Observes @WithAnnotations(ConfigMapping.class) ProcessAnnotatedType processAnnotatedType) { // Even if we filter in the CDI event, beans containing injection points of ConfigMapping are also fired. - if (processAnnotatedType.getAnnotatedType().isAnnotationPresent(ConfigMapping.class)) { + AnnotatedType annotatedType = processAnnotatedType.getAnnotatedType(); + if (annotatedType.isAnnotationPresent(ConfigMapping.class)) { // We are going to veto, because it may be a managed bean, and we will use a configurator bean processAnnotatedType.veto(); // Each config class is both in SmallRyeConfig and managed by a configurator bean. // CDI requires a single configurator bean per class due to non-binding prefix. - ConfigClassWithPrefix mapping = configClassWithPrefix(processAnnotatedType.getAnnotatedType().getJavaClass(), - processAnnotatedType.getAnnotatedType().getAnnotation(ConfigMapping.class).prefix()); + ConfigClass mapping = ConfigClass.configClass(annotatedType.getJavaClass()); configMappings.add(mapping); configMappingBeans.add(mapping); } } protected void processConfigInjectionPoints(@Observes ProcessInjectionPoint pip) { - if (pip.getInjectionPoint().getAnnotated().isAnnotationPresent(ConfigProperty.class)) { - configPropertyInjectionPoints.add(pip.getInjectionPoint()); + InjectionPoint injectionPoint = pip.getInjectionPoint(); + if (injectionPoint.getAnnotated().isAnnotationPresent(ConfigProperty.class)) { + configPropertyInjectionPoints.add(injectionPoint); } - if (pip.getInjectionPoint().getAnnotated().isAnnotationPresent(ConfigProperties.class)) { - ConfigClassWithPrefix properties = configClassWithPrefix((Class) pip.getInjectionPoint().getType(), - pip.getInjectionPoint().getAnnotated().getAnnotation(ConfigProperties.class).prefix()); + if (injectionPoint.getAnnotated().isAnnotationPresent(ConfigProperties.class)) { + ConfigClass properties = ConfigClass.configClass((Class) injectionPoint.getType(), + injectionPoint.getAnnotated().getAnnotation(ConfigProperties.class).prefix()); // If the prefix is empty at the injection point, fallbacks to the class prefix (already registered) if (!properties.getPrefix().equals(ConfigProperties.UNCONFIGURED_PREFIX)) { @@ -147,9 +143,9 @@ protected void processConfigInjectionPoints(@Observes ProcessInjectionPoint) pip.getInjectionPoint().getType(), - pip.getInjectionPoint().getAnnotated().getAnnotation(ConfigMapping.class).prefix()); + if (injectionPoint.getAnnotated().isAnnotationPresent(ConfigMapping.class)) { + ConfigClass mapping = ConfigClass.configClass((Class) injectionPoint.getType(), + injectionPoint.getAnnotated().getAnnotation(ConfigMapping.class).prefix()); // If the prefix is empty at the injection point, fallbacks to the class prefix (already registered) if (!mapping.getPrefix().isEmpty()) { configMappings.add(mapping); diff --git a/cdi/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java index ed88adb33..6796665e2 100644 --- a/cdi/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java +++ b/cdi/src/main/java/io/smallrye/config/inject/ConfigMappingInjectionBean.java @@ -17,21 +17,21 @@ import org.eclipse.microprofile.config.ConfigProvider; import io.smallrye.config.ConfigMapping; -import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix; +import io.smallrye.config.ConfigMappings.ConfigClass; import io.smallrye.config.SmallRyeConfig; public class ConfigMappingInjectionBean implements Bean { private final BeanManager bm; - private final ConfigClassWithPrefix configClassWithPrefix; + private final ConfigClass configClass; - public ConfigMappingInjectionBean(final ConfigClassWithPrefix configClassWithPrefix, final BeanManager bm) { + public ConfigMappingInjectionBean(final ConfigClass configClass, final BeanManager bm) { this.bm = bm; - this.configClassWithPrefix = configClassWithPrefix; + this.configClass = configClass; } @Override public Class getBeanClass() { - return (Class) configClassWithPrefix.getKlass(); + return (Class) configClass.getKlass(); } @Override @@ -44,7 +44,7 @@ public T create(final CreationalContext creationalContext) { InjectionPoint injectionPoint = (InjectionPoint) bm.getInjectableReference(new MetadataInjectionPoint(), creationalContext); - String prefix = configClassWithPrefix.getPrefix(); + String prefix = configClass.getPrefix(); if (injectionPoint != null && injectionPoint.getAnnotated() != null) { ConfigMapping configMapping = injectionPoint.getAnnotated().getAnnotation(ConfigMapping.class); if (configMapping != null) { @@ -63,7 +63,7 @@ public void destroy(final T instance, final CreationalContext creationalConte @Override public Set getTypes() { - return Collections.singleton(configClassWithPrefix.getKlass()); + return Collections.singleton(configClass.getKlass()); } @Override @@ -78,7 +78,7 @@ public Class getScope() { @Override public String getName() { - return this.getClass().getSimpleName() + "_" + configClassWithPrefix.getKlass().getName(); + return this.getClass().getSimpleName() + "_" + configClass.getKlass().getName(); } @Override diff --git a/cdi/src/main/java/io/smallrye/config/inject/ConfigPropertiesInjectionBean.java b/cdi/src/main/java/io/smallrye/config/inject/ConfigPropertiesInjectionBean.java index d0653ee06..11210ac2a 100644 --- a/cdi/src/main/java/io/smallrye/config/inject/ConfigPropertiesInjectionBean.java +++ b/cdi/src/main/java/io/smallrye/config/inject/ConfigPropertiesInjectionBean.java @@ -15,21 +15,21 @@ import org.eclipse.microprofile.config.ConfigProvider; import org.eclipse.microprofile.config.inject.ConfigProperties; -import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix; +import io.smallrye.config.ConfigMappings.ConfigClass; import io.smallrye.config.SmallRyeConfig; public class ConfigPropertiesInjectionBean implements Bean { - private final ConfigClassWithPrefix configClassWithPrefix; + private final ConfigClass configClass; private final Set qualifiers; - ConfigPropertiesInjectionBean(final ConfigClassWithPrefix configClassWithPrefix) { - this.configClassWithPrefix = configClassWithPrefix; - this.qualifiers = Collections.singleton(ConfigProperties.Literal.of(configClassWithPrefix.getPrefix())); + ConfigPropertiesInjectionBean(final ConfigClass configClass) { + this.configClass = configClass; + this.qualifiers = Collections.singleton(ConfigProperties.Literal.of(configClass.getPrefix())); } @Override public Class getBeanClass() { - return (Class) configClassWithPrefix.getKlass(); + return (Class) configClass.getKlass(); } @Override @@ -39,9 +39,9 @@ public Set getInjectionPoints() { @Override public T create(final CreationalContext creationalContext) { - String prefix = configClassWithPrefix.getPrefix(); + String prefix = configClass.getPrefix(); if (prefix.equals(ConfigProperties.UNCONFIGURED_PREFIX)) { - prefix = configClassWithPrefix.getKlass().getAnnotation(ConfigProperties.class).prefix(); + prefix = configClass.getKlass().getAnnotation(ConfigProperties.class).prefix(); if (prefix.equals(ConfigProperties.UNCONFIGURED_PREFIX)) { prefix = ""; } @@ -58,7 +58,7 @@ public void destroy(final T instance, final CreationalContext creationalConte @Override public Set getTypes() { - return Collections.singleton(configClassWithPrefix.getKlass()); + return Collections.singleton(configClass.getKlass()); } @Override @@ -73,8 +73,8 @@ public Class getScope() { @Override public String getName() { - return this.getClass().getSimpleName() + "_" + configClassWithPrefix.getKlass().getName() + "_" - + configClassWithPrefix.getPrefix(); + return this.getClass().getSimpleName() + "_" + configClass.getKlass().getName() + "_" + + configClass.getPrefix(); } @Override diff --git a/implementation/src/main/java/io/smallrye/config/ConfigMapping.java b/implementation/src/main/java/io/smallrye/config/ConfigMapping.java index 9805f4802..16577577e 100644 --- a/implementation/src/main/java/io/smallrye/config/ConfigMapping.java +++ b/implementation/src/main/java/io/smallrye/config/ConfigMapping.java @@ -28,7 +28,10 @@ * * This annotation is also used in CDI aware environments to scan and register Config Mappings. Otherwise, Config * Mapping interfaces require registration via - * {@link SmallRyeConfigBuilder#withMapping(java.lang.Class, java.lang.String)}. + * {@link SmallRyeConfigBuilder#withMapping(java.lang.Class)}. + * + * @see SmallRyeConfigBuilder#withMapping(java.lang.Class) + * @see SmallRyeConfigBuilder#withMapping(ConfigMappings.ConfigClass) */ @Documented @Target({ FIELD, PARAMETER, TYPE }) @@ -69,7 +72,7 @@ enum NamingStrategy { private final Function function; - private NamingStrategy(Function function) { + NamingStrategy(Function function) { this.function = function; } diff --git a/implementation/src/main/java/io/smallrye/config/ConfigMappings.java b/implementation/src/main/java/io/smallrye/config/ConfigMappings.java index 26b3b88b8..c463298a7 100644 --- a/implementation/src/main/java/io/smallrye/config/ConfigMappings.java +++ b/implementation/src/main/java/io/smallrye/config/ConfigMappings.java @@ -1,6 +1,6 @@ package io.smallrye.config; -import static io.smallrye.config.ConfigMappings.ConfigClassWithPrefix.configClassWithPrefix; +import static io.smallrye.config.ConfigMappings.ConfigClass.configClass; import java.util.HashMap; import java.util.HashSet; @@ -8,6 +8,8 @@ import java.util.Objects; import java.util.Set; +import org.eclipse.microprofile.config.inject.ConfigProperties; + import io.smallrye.config.ConfigMappingInterface.Property; /** @@ -19,7 +21,7 @@ public final class ConfigMappings { * Registers additional {@link ConfigMapping} annotated classes with a {@link SmallRyeConfig} instance. *

* The recommended method of registering {@link ConfigMapping} is with a - * {@link SmallRyeConfigBuilder#withMapping(Class, String)}. In certain cases, this is not possible (ex. a CDI + * {@link SmallRyeConfigBuilder#withMapping(Class)}. In certain cases, this is not possible (ex. a CDI * runtime), where mapping classes can only be discovered after the Config instance creation. * * @param config the {@link SmallRyeConfig} instance @@ -27,7 +29,7 @@ public final class ConfigMappings { * @throws ConfigValidationException if a {@link ConfigMapping} cannot be registed with the * {@link SmallRyeConfig} instance */ - public static void registerConfigMappings(final SmallRyeConfig config, final Set configClasses) + public static void registerConfigMappings(final SmallRyeConfig config, final Set configClasses) throws ConfigValidationException { if (!configClasses.isEmpty()) { mapConfiguration(config, new SmallRyeConfigBuilder(), configClasses); @@ -38,7 +40,7 @@ public static void registerConfigMappings(final SmallRyeConfig config, final Set * Registers additional ConfigProperties annotated classes with a {@link SmallRyeConfig} instance. *

* The recommended method of registering ConfigProperties is with a - * {@link SmallRyeConfigBuilder#withMapping(Class, String)}. In certain cases, this is not possible (ex. a CDI + * {@link SmallRyeConfigBuilder#withMapping(Class)}. In certain cases, this is not possible (ex. a CDI * runtime), where mapping classes can only be discovered after the Config instance creation. * * @param config the {@link SmallRyeConfig} instance @@ -46,7 +48,7 @@ public static void registerConfigMappings(final SmallRyeConfig config, final Set * @throws ConfigValidationException if a ConfigProperties cannot be registed with the * {@link SmallRyeConfig} instance */ - public static void registerConfigProperties(final SmallRyeConfig config, final Set configClasses) + public static void registerConfigProperties(final SmallRyeConfig config, final Set configClasses) throws ConfigValidationException { if (!configClasses.isEmpty()) { mapConfiguration(config, new SmallRyeConfigBuilder().withValidateUnknown(false), configClasses); @@ -61,7 +63,7 @@ public static void registerConfigProperties(final SmallRyeConfig config, final S * @see ConfigMappingInterface#getProperties(ConfigMappingInterface) * @return a Map with all mapping class {@link Property}. */ - public static Map getProperties(final ConfigClassWithPrefix configClass) { + public static Map getProperties(final ConfigClass configClass) { Map properties = new HashMap<>(); // Because the properties key names do not include the path prefix we need to add it for (Map.Entry entry : ConfigMappingInterface @@ -74,7 +76,7 @@ public static Map getProperties(final ConfigClassWithPrefix co } @Deprecated - public static Set mappedProperties(final ConfigClassWithPrefix configClass, final Set properties) { + public static Set mappedProperties(final ConfigClass configClass, final Set properties) { ConfigMappingNames names = new ConfigMappingNames( ConfigMappingLoader.getConfigMapping(configClass.getKlass()).getNames()); Set mappedNames = new HashSet<>(); @@ -90,10 +92,10 @@ public static Set mappedProperties(final ConfigClassWithPrefix configCla private static void mapConfiguration( final SmallRyeConfig config, final SmallRyeConfigBuilder configBuilder, - final Set configClasses) + final Set configClasses) throws ConfigValidationException { - for (ConfigClassWithPrefix configClass : configClasses) { - configBuilder.withMapping(configClass.getKlass(), configClass.getPrefix()); + for (ConfigClass configClass : configClasses) { + configBuilder.withMapping(configClass); } config.getDefaultValues().addDefaults(configBuilder.getDefaultValues()); config.getMappings().putAll(config.buildMappings(configBuilder)); @@ -111,20 +113,14 @@ static String prefix(final String prefix, final String path) { } } - static String getPrefix(Class type) { - final ConfigMapping configMapping = type.getAnnotation(ConfigMapping.class); - return configMapping != null ? configMapping.prefix() : ""; - } - /** - * A representation of a {@link ConfigMapping} or @ConfigProperties with a Class and the - * prefix. + * A representation of a {@link ConfigMapping} or @ConfigProperties. */ - public static final class ConfigClassWithPrefix { + public static final class ConfigClass { private final Class klass; private final String prefix; - public ConfigClassWithPrefix(final Class klass, final String prefix) { + public ConfigClass(final Class klass, final String prefix) { this.klass = klass; this.prefix = prefix; } @@ -145,7 +141,7 @@ public boolean equals(final Object o) { if (o == null || getClass() != o.getClass()) { return false; } - final ConfigClassWithPrefix that = (ConfigClassWithPrefix) o; + final ConfigClass that = (ConfigClass) o; return klass.equals(that.klass) && prefix.equals(that.prefix); } @@ -154,12 +150,23 @@ public int hashCode() { return Objects.hash(klass, prefix); } - public static ConfigClassWithPrefix configClassWithPrefix(final Class klass, final String prefix) { - return new ConfigClassWithPrefix(klass, prefix); + public static ConfigClass configClass(final Class klass, final String prefix) { + return new ConfigClass(klass, prefix); } - public static ConfigClassWithPrefix configClassWithPrefix(final Class klass) { - return configClassWithPrefix(klass, ConfigMappings.getPrefix(klass)); + public static ConfigClass configClass(final Class klass) { + if (klass.isInterface()) { + ConfigMapping configMapping = klass.getAnnotation(ConfigMapping.class); + String prefix = configMapping != null ? configMapping.prefix() : ""; + return configClass(klass, prefix); + } else { + ConfigProperties configProperties = klass.getAnnotation(ConfigProperties.class); + String prefix = configProperties != null ? configProperties.prefix() : ""; + if (prefix.equals(ConfigProperties.UNCONFIGURED_PREFIX)) { + prefix = ""; + } + return configClass(klass, prefix); + } } } } diff --git a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java index a155c1a19..19b6f5623 100644 --- a/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java +++ b/implementation/src/main/java/io/smallrye/config/SmallRyeConfigBuilder.java @@ -57,6 +57,7 @@ import org.eclipse.microprofile.config.spi.Converter; import io.smallrye.common.constraint.Assert; +import io.smallrye.config.ConfigMappings.ConfigClass; import io.smallrye.config._private.ConfigMessages; /** @@ -533,9 +534,18 @@ public SmallRyeConfigBuilder withDefaultValues(Map defaultValues } public SmallRyeConfigBuilder withMapping(Class klass) { - return withMapping(klass, ConfigMappings.getPrefix(klass)); + return withMapping(ConfigClass.configClass(klass)); } + public SmallRyeConfigBuilder withMapping(ConfigClass configClass) { + mappingsBuilder.mapping(configClass); + return this; + } + + /** + * @deprecated Use {@link SmallRyeConfigBuilder#withMapping(ConfigClass)} instead. + */ + @Deprecated(forRemoval = true) public SmallRyeConfigBuilder withMapping(Class klass, String prefix) { mappingsBuilder.mapping(klass, prefix); return this; @@ -761,11 +771,15 @@ public SmallRyeConfig build() { return new SmallRyeConfig(this); } - final class MappingBuilder { + public final class MappingBuilder { private final Map, Set> mappings = new HashMap<>(); private final List ignoredPaths = new ArrayList<>(); - MappingBuilder mapping(Class type, String prefix) { + public void mapping(ConfigClass configClass) { + mapping(configClass.getKlass(), configClass.getPrefix()); + } + + public void mapping(Class type, String prefix) { Assert.checkNotNullParam("type", type); Assert.checkNotNullParam("path", prefix); Class mappingClass = getConfigMappingClass(type); @@ -780,20 +794,18 @@ MappingBuilder mapping(Class type, String prefix) { // Do not override builder defaults with mapping defaults defaultValues.putIfAbsent(prefix(prefix, defaultEntry.getKey()), defaultEntry.getValue()); } - return this; } - MappingBuilder ignoredPath(String ignoredPath) { + public void ignoredPath(String ignoredPath) { Assert.checkNotNullParam("ignoredPath", ignoredPath); ignoredPaths.add(ignoredPath); - return this; } - Map, Set> getMappings() { + public Map, Set> getMappings() { return mappings; } - List getIgnoredPaths() { + public List getIgnoredPaths() { return ignoredPaths; } } diff --git a/implementation/src/test/java/io/smallrye/config/ConfigMappingCollectionsTest.java b/implementation/src/test/java/io/smallrye/config/ConfigMappingCollectionsTest.java index 1e236277d..b0775a774 100644 --- a/implementation/src/test/java/io/smallrye/config/ConfigMappingCollectionsTest.java +++ b/implementation/src/test/java/io/smallrye/config/ConfigMappingCollectionsTest.java @@ -30,7 +30,7 @@ public interface ServerCollectionSimple { @Test void mappingCollectionsSimple() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerCollectionSimple.class, "server") + .withMapping(ServerCollectionSimple.class) .withSources(config("server.environments[0]", "dev", "server.environments[1]", "qa", "server.environments[2]", "prod")) @@ -71,7 +71,7 @@ interface App { @Test void mappingCollections() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerCollections.class, "server") + .withMapping(ServerCollections.class) .withSources(config( "server.environments[0].name", "dev", "server.environments[0].apps[0].name", "rest", @@ -124,7 +124,7 @@ interface App { @Test void mappingCollectionsWithName() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerCollectionName.class, "server") + .withMapping(ServerCollectionName.class) .withSources(config("server.envs[0].name", "dev", "server.envs[0].apps[0].name", "rest", "server.envs[0].apps[1].name", "batch", @@ -169,7 +169,7 @@ interface Environment { @Test void mappingCollectionsWithDefaults() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerCollectionsDefaults.class, "server") + .withMapping(ServerCollectionsDefaults.class) .withSources(config("server[0].name", "dev")) .build(); @@ -219,7 +219,7 @@ interface App { @Test void mappingCollectionsOptionals() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerCollectionsOptionals.class, "server") + .withMapping(ServerCollectionsOptionals.class) .withSources(config( "server.env[0].name", "dev", "server.env[1].name", "prod", @@ -287,7 +287,7 @@ public Host convert(final String value) throws IllegalArgumentException, NullPoi @Test void mappingCollectionsConverters() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerCollectionsConverters.class, "server") + .withMapping(ServerCollectionsConverters.class) .withSources(config("server.envs[0].hosts[0]", "localhost", "server.envs[0].hosts[1]", "127.0.0.1")) .build(); @@ -322,7 +322,7 @@ interface App { @Test void mappingCollectionsSet() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerCollectionsSet.class, "server") + .withMapping(ServerCollectionsSet.class) .withSources(config( "server.environments[0].name", "dev", "server.environments[0].apps[0].name", "rest", @@ -375,7 +375,7 @@ interface App { @Test void mappingOptionalGroupWithCollection() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerOptionalGroup.class, "server") + .withMapping(ServerOptionalGroup.class) .withSources(config( "server.environment.services[0]", "rest", "server.environment.services[1]", "batch", @@ -389,7 +389,7 @@ void mappingOptionalGroupWithCollection() { assertEquals("a", server.environment().get().apps().get(0).name()); config = new SmallRyeConfigBuilder() - .withMapping(ServerOptionalGroup.class, "server") + .withMapping(ServerOptionalGroup.class) .withSources(config( "server.environment.services", "rest,batch", "server.environment.apps[0].name", "a")) @@ -417,7 +417,7 @@ interface Server { @Test void mappingSingleCollection() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerSingleCollection.class, "server") + .withMapping(ServerSingleCollection.class) .withSources(config( "server[0].host", "localhost", "server[0].port", "8080", @@ -436,7 +436,7 @@ void mappingSingleCollection() { @Test void mappingCollectionProfile() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerSingleCollection.class, "server") + .withMapping(ServerSingleCollection.class) .withSources(config( "server[0].host", "localhost", "server[0].port", "8080", @@ -476,7 +476,7 @@ interface Server { @Test void mappingCollectionsMap() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerCollectionMap.class, "servers") + .withMapping(ServerCollectionMap.class) .withSources(config( "servers[0].localhost", "localhost", "servers[1].konoha", "konoha", @@ -659,7 +659,7 @@ interface MapIndexedAndPlain { @Test void mapIndexedAndPlain() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(MapIndexedAndPlain.class, "map") + .withMapping(MapIndexedAndPlain.class) .withSources(config( "map.one[0]", "one", "map.one[1]", "1", "map.two", "two,2")) @@ -675,7 +675,7 @@ void mapIndexedAndPlain() { @Test void simpleMap() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(SimpleMap.class, "map") + .withMapping(SimpleMap.class) .withSources(config("map.one", "value")) .withSources(config("map.key-converter.key", "value")) .withSources(config("map.value-converter.one", "something")) @@ -829,7 +829,7 @@ public String convert(final String value) throws IllegalArgumentException, NullP @Test void simpleMapList() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(SimpleMapList.class, "map") + .withMapping(SimpleMapList.class) .withSources(config("map.one[0]", "value")) .withSources(config("map.key-converter.key[0]", "value")) .withSources(config("map.value-converter.one[0]", "something")) diff --git a/implementation/src/test/java/io/smallrye/config/ConfigMappingDefaultsTest.java b/implementation/src/test/java/io/smallrye/config/ConfigMappingDefaultsTest.java index 33c5a5044..6a78c215c 100644 --- a/implementation/src/test/java/io/smallrye/config/ConfigMappingDefaultsTest.java +++ b/implementation/src/test/java/io/smallrye/config/ConfigMappingDefaultsTest.java @@ -2,6 +2,7 @@ import static io.smallrye.config.ConfigMappingDefaultsTest.S3BuildTimeConfig.AsyncHttpClientBuildTimeConfig.AsyncClientType.NETTY; import static io.smallrye.config.ConfigMappingDefaultsTest.S3BuildTimeConfig.SyncHttpClientBuildTimeConfig.SyncClientType.URL; +import static io.smallrye.config.ConfigMappings.ConfigClass.configClass; import static io.smallrye.config.KeyValuesConfigSource.config; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -122,7 +123,7 @@ void emptyPrefix() { .withSources(config( "list-nested[0].value", "value", "parent.list-nested[0].value", "value")) - .withMapping(Defaults.class, "") + .withMapping(configClass(Defaults.class, "")) .build(); Defaults mapping = config.getConfigMapping(Defaults.class, ""); diff --git a/implementation/src/test/java/io/smallrye/config/ConfigMappingInterfaceTest.java b/implementation/src/test/java/io/smallrye/config/ConfigMappingInterfaceTest.java index e4295a9de..92861cd2e 100644 --- a/implementation/src/test/java/io/smallrye/config/ConfigMappingInterfaceTest.java +++ b/implementation/src/test/java/io/smallrye/config/ConfigMappingInterfaceTest.java @@ -4,6 +4,7 @@ import static io.smallrye.config.ConfigMappingInterfaceTest.HyphenatedEnumMapping.HyphenatedEnum.VALUE_ONE; import static io.smallrye.config.ConfigMappingInterfaceTest.MapKeyEnum.ClientId.NAF; import static io.smallrye.config.ConfigMappingInterfaceTest.MapKeyEnum.ClientId.SOS_DAH; +import static io.smallrye.config.ConfigMappings.ConfigClass.configClass; import static io.smallrye.config.KeyValuesConfigSource.config; import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_MAPPING_VALIDATE_UNKNOWN; import static java.util.Collections.singletonList; @@ -46,7 +47,7 @@ class ConfigMappingInterfaceTest { @Test void configMapping() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(Server.class, "server") + .withMapping(configClass(Server.class, "server")) .withSources(config("server.host", "localhost", "server.port", "8080")).build(); Server configProperties = config.getConfigMapping(Server.class, "server"); assertEquals("localhost", configProperties.host()); @@ -95,13 +96,13 @@ void noPrefix() { @Test void unknownConfigElement() { assertThrows(ConfigValidationException.class, - () -> new SmallRyeConfigBuilder().withMapping(Server.class, "server").build()); + () -> new SmallRyeConfigBuilder().withMapping(configClass(Server.class, "server")).build()); } @Test void ignorePropertiesInUnregisteredRoots() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(Server.class, "server") + .withMapping(configClass(Server.class, "server")) .withSources(config("server.host", "localhost", "server.port", "8080", "client.name", "konoha")) .build(); Server configProperties = config.getConfigMapping(Server.class, "server"); @@ -112,8 +113,8 @@ void ignorePropertiesInUnregisteredRoots() { @Test void ignoreSomeProperties() { final SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(Server.class, "server") - .withMapping(Client.class, "client") + .withMapping(configClass(Server.class, "server")) + .withMapping(configClass(Client.class, "client")) .withMappingIgnore("client.**") .withSources(config("server.host", "localhost", "server.port", "8080", "client.host", "localhost", "client.port", "8080", "client.name", "konoha")) @@ -132,7 +133,7 @@ void ignoreSomeProperties() { void ignoreProperties() { SmallRyeConfig config = new SmallRyeConfigBuilder() .addDefaultSources() - .withMapping(Server.class, "server") + .withMapping(configClass(Server.class, "server")) .withSources(config("server.host", "localhost", "server.port", "8080")).build(); Server configProperties = config.getConfigMapping(Server.class, "server"); assertEquals("localhost", configProperties.host()); @@ -147,7 +148,7 @@ void validateUnknown() { SmallRyeConfig config = new SmallRyeConfigBuilder() .addDefaultSources() .withMapping(Server.class) - .withMapping(Server.class, "server") + .withMapping(configClass(Server.class, "server")) .withValidateUnknown(false) .withSources(config("server.host", "localhost", "server.port", "8080", "host", "localhost", "port", "8080")) .build(); @@ -161,8 +162,8 @@ void validateUnknown() { void splitRoots() { SmallRyeConfig config = new SmallRyeConfigBuilder() .withSources(config("server.host", "localhost", "server.port", "8080", "server.name", "konoha")) - .withMapping(SplitRootServerHostAndPort.class, "server") - .withMapping(SplitRootServerName.class, "server") + .withMapping(configClass(SplitRootServerHostAndPort.class, "server")) + .withMapping(configClass(SplitRootServerName.class, "server")) .build(); SplitRootServerHostAndPort server = config.getConfigMapping(SplitRootServerHostAndPort.class, "server"); @@ -178,8 +179,8 @@ void splitRootsInConfig() { SmallRyeConfig config = new SmallRyeConfigBuilder() .withSources(config("server.host", "localhost", "server.port", "8080", "server.name", "konoha")) - .withMapping(SplitRootServerHostAndPort.class, "server") - .withMapping(SplitRootServerName.class, "server") + .withMapping(configClass(SplitRootServerHostAndPort.class, "server")) + .withMapping(configClass(SplitRootServerName.class, "server")) .build(); SplitRootServerHostAndPort server = config.getConfigMapping(SplitRootServerHostAndPort.class, "server"); assertEquals("localhost", server.host()); @@ -191,7 +192,7 @@ void subGroups() { SmallRyeConfig config = new SmallRyeConfigBuilder() .withSources(config("server.host", "localhost", "server.port", "8080", "server.name", "konoha")) - .withMapping(ServerSub.class, "server") + .withMapping(configClass(ServerSub.class, "server")) .build(); ServerSub server = config.getConfigMapping(ServerSub.class, "server"); assertEquals("localhost", server.subHostAndPort().host()); @@ -308,7 +309,7 @@ void mapsEmptyPrefix() { "group.server.port", "8081", "server.host", "localhost", "server.port", "8082")) - .withMapping(Maps.class, "") + .withMapping(configClass(Maps.class, "")) .build(); Maps maps = config.getConfigMapping(Maps.class, ""); @@ -367,7 +368,7 @@ void mix() { @Test void noDynamicValues() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(Server.class, "server") + .withMapping(configClass(Server.class, "server")) .withSources(config("server.host", "localhost", "server.port", "8080")) .withSources(new MapBackedConfigSource("test", new HashMap<>(), Integer.MAX_VALUE) { private int counter = 1; @@ -387,7 +388,7 @@ public String getValue(String propertyName) { @Test void mapClass() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerClass.class, "server") + .withMapping(configClass(ServerClass.class, "server")) .withSources(config("server.host", "localhost", "server.port", "8080")).build(); ServerClass server = config.getConfigMapping(ServerClass.class, "server"); assertEquals("localhost", server.getHost()); @@ -410,8 +411,8 @@ int getPort() { @Test void configMappingAnnotation() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerAnnotated.class, "server") - .withMapping(ServerAnnotated.class, "cloud") + .withMapping(configClass(ServerAnnotated.class, "server")) + .withMapping(configClass(ServerAnnotated.class, "cloud")) .withSources( config("server.host", "localhost", "server.port", "8080", "cloud.host", "cloud", "cloud.port", "9090")) .build(); @@ -448,7 +449,7 @@ void prefixFromAnnotation() { @Test void superTypes() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerChild.class, "server") + .withMapping(configClass(ServerChild.class, "server")) .withSources(config("server.host", "localhost", "server.port", "8080")) .build(); @@ -461,7 +462,7 @@ void superTypes() { @Test void configValue() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerConfigValue.class, "server") + .withMapping(ServerConfigValue.class) .withSources(config("server.host", "localhost", "server.port", "8080")) .build(); @@ -474,7 +475,7 @@ void configValue() { @Test void empty() { try { - new SmallRyeConfigBuilder().withMapping(Empty.class, "empty").build(); + new SmallRyeConfigBuilder().withMapping(Empty.class).build(); } catch (Exception e) { Assertions.fail(e); } @@ -761,9 +762,9 @@ interface ServerNamePrefix { @Test void prefixPropertyInRoot() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerPrefix.class, "server") - .withMapping(ServerPrefix.class, "cloud.server") - .withMapping(ServerNamePrefix.class, "server") + .withMapping(configClass(ServerPrefix.class, "server")) + .withMapping(configClass(ServerPrefix.class, "cloud.server")) + .withMapping(configClass(ServerNamePrefix.class, "server")) .withSources(config("serverBoot", "server")) .withSources(config("server.host", "localhost", "server.port", "8080")) .withSources(config("cloud.serverBoot", "server")) @@ -788,7 +789,7 @@ void prefixPropertyInRoot() { @Test void prefixPropertyInRootUnknown() { SmallRyeConfigBuilder builder = new SmallRyeConfigBuilder() - .withMapping(ServerPrefix.class, "server") + .withMapping(ServerPrefix.class) .withSources(config("serverBoot", "server")) .withSources(config("server.host", "localhost", "server.port", "8080")) .withSources(config("server.name", "localhost")) @@ -799,9 +800,9 @@ void prefixPropertyInRootUnknown() { exception.getProblem(0).getMessage()); builder = new SmallRyeConfigBuilder() - .withMapping(ServerPrefix.class, "server") - .withMapping(ServerPrefix.class, "cloud.server") - .withMapping(ServerNamePrefix.class, "server") + .withMapping(configClass(ServerPrefix.class, "server")) + .withMapping(configClass(ServerPrefix.class, "cloud.server")) + .withMapping(configClass(ServerNamePrefix.class, "server")) .withSources(config("serverBoot", "server")) .withSources(config("server.host", "localhost", "server.port", "8080")) .withSources(config("cloud.serverBoot", "server")) @@ -900,7 +901,7 @@ interface Alias extends Named { @Test void hierarchy() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerHierarchy.class, "server") + .withMapping(ServerHierarchy.class) .withSources(config("server.host", "localhost", "server.port", "8080", "server.name", "server", "server.alias.name", "alias", "server.alias.alias", "alias")) .build(); @@ -926,7 +927,7 @@ interface ServerExpandDefaults { void expandDefaults() { SmallRyeConfig config = new SmallRyeConfigBuilder() .addDefaultInterceptors() - .withMapping(ServerExpandDefaults.class, "server") + .withMapping(ServerExpandDefaults.class) .withSources(config("server.url", "http://${server.host}")) .build(); @@ -982,7 +983,7 @@ interface ServerAlias { @Test void hierarchyOverrides() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerOverrides.class, "server") + .withMapping(ServerOverrides.class) .withSources(config("server.host", "localhost", "server.port", "8080")) .withSources(config("server.properties.host", "localhost", "server.properties.port", "8080")) .withSources(config("server.other-alias.other.name", "other")) @@ -1029,7 +1030,7 @@ interface Address { @Test void nestedGroupMaps() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(NestedGroupMaps.class, "maps") + .withMapping(NestedGroupMaps.class) .withSources(config("maps.users.naruto.age", "17", "maps.users.naruto.items.attack1", "rasengan", "maps.users.naruto.addresses.home.location", "Konoha", @@ -1055,7 +1056,7 @@ interface MappingPath { @Test void path() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(MappingPath.class, "path") + .withMapping(MappingPath.class) .withSources(config("path.path", "path")) .withConverter(Path.class, 100, value -> value.isEmpty() ? null : Paths.get(value)) .build(); @@ -1073,7 +1074,7 @@ interface DottedKeyInMap { @Test void properties() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(DottedKeyInMap.class, "map") + .withMapping(DottedKeyInMap.class) .withSources(config("map.key", "1234", "map.\"dotted.key\"", "5678")) .build(); @@ -1116,7 +1117,7 @@ interface EnabledProperties { @Test void mapWithMultipleGroupsAndSameMethodNames() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(BugsConfiguration.class, "clients") + .withMapping(BugsConfiguration.class) .withSources(config( "clients.naruto.medium.web", "true", "clients.naruto.medium.app", "true", @@ -1147,7 +1148,7 @@ default String host() { @Test void defaultMethods() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(DefaultMethods.class, "defaults") + .withMapping(DefaultMethods.class) .build(); DefaultMethods mapping = config.getConfigMapping(DefaultMethods.class); @@ -1194,7 +1195,7 @@ public static int anotherPort(DefaultKotlinMethods config) { @Test void defaultKotlinMethods() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(DefaultKotlinMethods.class, "defaults") + .withMapping(DefaultKotlinMethods.class) .build(); DefaultKotlinMethods mapping = config.getConfigMapping(DefaultKotlinMethods.class); @@ -1239,7 +1240,7 @@ interface MediumProperties { @Test void mapKeyEnum() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(MapKeyEnum.class, "clients") + .withMapping(MapKeyEnum.class) .withSources(config( "clients.SOS_DAH.web.createdByApplication", "RoadrunnerWeb", "clients.SOS_DAH.app.createdByApplication", "Roadrunner", diff --git a/implementation/src/test/java/io/smallrye/config/ConfigMappingNamingStrategyTest.java b/implementation/src/test/java/io/smallrye/config/ConfigMappingNamingStrategyTest.java index f85428155..79ad871d7 100644 --- a/implementation/src/test/java/io/smallrye/config/ConfigMappingNamingStrategyTest.java +++ b/implementation/src/test/java/io/smallrye/config/ConfigMappingNamingStrategyTest.java @@ -3,6 +3,7 @@ import static io.smallrye.config.ConfigMapping.NamingStrategy.KEBAB_CASE; import static io.smallrye.config.ConfigMapping.NamingStrategy.SNAKE_CASE; import static io.smallrye.config.ConfigMapping.NamingStrategy.VERBATIM; +import static io.smallrye.config.ConfigMappings.ConfigClass.configClass; import static io.smallrye.config.KeyValuesConfigSource.config; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -19,8 +20,8 @@ public class ConfigMappingNamingStrategyTest { @Test void namingStrategy() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerVerbatimNamingStrategy.class, "server") - .withMapping(ServerSnakeNamingStrategy.class, "server") + .withMapping(ServerVerbatimNamingStrategy.class) + .withMapping(ServerSnakeNamingStrategy.class) .withSources(config("server.theHost", "localhost", "server.thePort", "8080", "server.log.enabled", "true")) .withSources(config("server.the_host", "127.0.0.1", "server.the_port", "80", "server.log.enabled", "true")) .build(); @@ -67,9 +68,9 @@ interface Log { @Test void composedNamingStrategy() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ServerComposedSnakeNaming.class, "server") - .withMapping(ServerComposedVerbatimNaming.class, "server") - .withMapping(ServerComposedKebabNaming.class, "server") + .withMapping(ServerComposedSnakeNaming.class) + .withMapping(ServerComposedVerbatimNaming.class) + .withMapping(ServerComposedKebabNaming.class) .withSources(config("server.the_host", "localhost", "server.the_port", "8080")) .withSources(config("server.the_log.is_enabled", "true", "server.the_log.log_appenders[0].log_name", "log")) .withSources(config("server.theHost", "localhost", "server.thePort", "8080")) @@ -147,8 +148,8 @@ interface Appender { @Test void interfaceAndClass() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(ConfigMappingNamingKebab.class, "server") - .withMapping(ConfigPropertiesNamingVerbatim.class, "server") + .withMapping(ConfigMappingNamingKebab.class) + .withMapping(configClass(ConfigPropertiesNamingVerbatim.class, "server")) .withSources(config("server.theHost", "localhost")) .withSources(config("server.the-host", "localhost", "server.form.login-page", "login")) .build(); @@ -213,7 +214,7 @@ interface OverrideNamingStrategyProperties { @Test void namingStrategyVerbatimOptionalGroup() { SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(NamingStrategyVerbatimOptionalGroup.class, "bugs") + .withMapping(NamingStrategyVerbatimOptionalGroup.class) .withSources(config("bugs.KEY1.hereVerbatimWorks", "true", "bugs.KEY1.properties.feed", "100103", "bugs.KEY1.properties.customerId", "36936471", diff --git a/implementation/src/test/java/io/smallrye/config/ConfigMappingsTest.java b/implementation/src/test/java/io/smallrye/config/ConfigMappingsTest.java index f05841c9b..c50c6ecc6 100644 --- a/implementation/src/test/java/io/smallrye/config/ConfigMappingsTest.java +++ b/implementation/src/test/java/io/smallrye/config/ConfigMappingsTest.java @@ -2,7 +2,7 @@ import static io.smallrye.config.ConfigMappings.registerConfigMappings; import static io.smallrye.config.ConfigMappings.registerConfigProperties; -import static io.smallrye.config.ConfigMappings.ConfigClassWithPrefix.configClassWithPrefix; +import static io.smallrye.config.ConfigMappings.ConfigClass.configClass; import static io.smallrye.config.KeyValuesConfigSource.config; import static java.util.Collections.emptySet; import static java.util.Collections.singleton; @@ -35,7 +35,7 @@ void registerMapping() { .withConverter(Version.class, 100, new VersionConverter()) .build(); - registerConfigMappings(config, singleton(configClassWithPrefix(Server.class, "server"))); + registerConfigMappings(config, singleton(configClass(Server.class, "server"))); Server server = config.getConfigMapping(Server.class); assertEquals("localhost", server.host()); @@ -63,7 +63,7 @@ void registerProperties() { .withConverter(Version.class, 100, new VersionConverter()) .build(); - registerConfigProperties(config, singleton(configClassWithPrefix(ServerClass.class, "server"))); + registerConfigProperties(config, singleton(configClass(ServerClass.class, "server"))); ServerClass server = config.getConfigMapping(ServerClass.class); assertEquals("localhost", server.host); @@ -97,10 +97,10 @@ void validate() { .build(); assertThrows(ConfigValidationException.class, - () -> registerConfigMappings(config, singleton(configClassWithPrefix(Server.class, "server"))), + () -> registerConfigMappings(config, singleton(configClass(Server.class, "server"))), "server.unmapped does not map to any root"); - registerConfigProperties(config, singleton(configClassWithPrefix(ServerClass.class, "server"))); + registerConfigProperties(config, singleton(configClass(ServerClass.class, "server"))); ServerClass server = config.getConfigMapping(ServerClass.class); assertEquals("localhost", server.host); @@ -111,7 +111,7 @@ void validate() { void validateWithBuilderOrConfig() { SmallRyeConfig config = new SmallRyeConfigBuilder() .withSources(config("server.host", "localhost", "server.port", "8080", "server.unmapped", "unmapped")) - .withMapping(ServerClass.class, "server") + .withMapping(configClass(ServerClass.class, "server")) .withConverter(Version.class, 100, new VersionConverter()) .withValidateUnknown(true) .withDefaultValue(SmallRyeConfig.SMALLRYE_CONFIG_MAPPING_VALIDATE_UNKNOWN, "false") @@ -127,7 +127,7 @@ void validateWithBuilderOrConfig() { void validateDisableOnConfigProperties() { SmallRyeConfig config = new SmallRyeConfigBuilder() .withSources(config("server.host", "localhost", "server.port", "8080", "server.unmapped", "unmapped")) - .withMapping(ServerClass.class, "server") + .withMapping(configClass(ServerClass.class, "server")) .withConverter(Version.class, 100, new VersionConverter()) .build(); @@ -141,23 +141,23 @@ void validateDisableOnConfigProperties() { void validateAnnotations() { SmallRyeConfig config = new SmallRyeConfigBuilder().build(); IllegalStateException exception = assertThrows(IllegalStateException.class, - () -> registerConfigMappings(config, singleton(configClassWithPrefix(ServerMappingClass.class, "server")))); + () -> registerConfigMappings(config, singleton(configClass(ServerMappingClass.class, "server")))); assertTrue(exception.getMessage() .startsWith("SRCFG00043: The @ConfigMapping annotation can only be placed in interfaces")); exception = assertThrows(IllegalStateException.class, - () -> new SmallRyeConfigBuilder().withMapping(ServerMappingClass.class, "server").build()); + () -> new SmallRyeConfigBuilder().withMapping(ServerMappingClass.class).build()); assertTrue(exception.getMessage() .startsWith("SRCFG00043: The @ConfigMapping annotation can only be placed in interfaces")); exception = assertThrows(IllegalStateException.class, () -> registerConfigMappings(config, - singleton(configClassWithPrefix(ServerPropertiesInterface.class, "server")))); + singleton(configClass(ServerPropertiesInterface.class, "server")))); assertTrue(exception.getMessage() .startsWith("SRCFG00044: The @ConfigProperties annotation can only be placed in classes")); exception = assertThrows(IllegalStateException.class, - () -> new SmallRyeConfigBuilder().withMapping(ServerPropertiesInterface.class, "server").build()); + () -> new SmallRyeConfigBuilder().withMapping(ServerPropertiesInterface.class).build()); assertTrue(exception.getMessage() .startsWith("SRCFG00044: The @ConfigProperties annotation can only be placed in classes")); } @@ -319,7 +319,7 @@ interface Nested { @Test void properties() { - ConfigMappings.ConfigClassWithPrefix configClass = configClassWithPrefix(MappedProperties.class); + ConfigMappings.ConfigClass configClass = configClass(MappedProperties.class); Map properties = ConfigMappings.getProperties(configClass); assertEquals(3, properties.size()); assertTrue(properties.containsKey("mapped.nested.value")); @@ -329,19 +329,19 @@ void properties() { @Test void mappedProperties() { - Set mappedProperties = ConfigMappings.mappedProperties(configClassWithPrefix(MappedProperties.class), + Set mappedProperties = ConfigMappings.mappedProperties(configClass(MappedProperties.class), Set.of("mapped.value", "mapped.nested.value", "mapped.collection[0].value", "mapped.unknown")); assertEquals(3, mappedProperties.size()); assertTrue(mappedProperties.contains("mapped.value")); assertTrue(mappedProperties.contains("mapped.nested.value")); assertTrue(mappedProperties.contains("mapped.collection[0].value")); - assertTrue(ConfigMappings.mappedProperties(configClassWithPrefix(MappedProperties.class), emptySet()).isEmpty()); + assertTrue(ConfigMappings.mappedProperties(configClass(MappedProperties.class), emptySet()).isEmpty()); } @Test void invalidMappedProperties() { - assertTrue(ConfigMappings.mappedProperties(configClassWithPrefix(MappedProperties.class), + assertTrue(ConfigMappings.mappedProperties(configClass(MappedProperties.class), Set.of("foo.bar", "mapped", "mapped.something", "mapped.collection")).isEmpty()); } } diff --git a/implementation/src/test/java/io/smallrye/config/RelocateConfigSourceInterceptorTest.java b/implementation/src/test/java/io/smallrye/config/RelocateConfigSourceInterceptorTest.java index ef61b6cc7..2e0c95c4d 100644 --- a/implementation/src/test/java/io/smallrye/config/RelocateConfigSourceInterceptorTest.java +++ b/implementation/src/test/java/io/smallrye/config/RelocateConfigSourceInterceptorTest.java @@ -1,7 +1,7 @@ package io.smallrye.config; import static io.smallrye.config.ConfigMappings.mappedProperties; -import static io.smallrye.config.ConfigMappings.ConfigClassWithPrefix.configClassWithPrefix; +import static io.smallrye.config.ConfigMappings.ConfigClass.configClass; import static io.smallrye.config.KeyValuesConfigSource.config; import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE; import static java.util.Collections.singletonMap; @@ -215,7 +215,7 @@ public Iterator iterateNames(final ConfigSourceInterceptorContext contex hierarchyCandidates.add("child." + name.substring(7)); } } - names.addAll(mappedProperties(configClassWithPrefix(Child.class), hierarchyCandidates)); + names.addAll(mappedProperties(configClass(Child.class), hierarchyCandidates)); return names.iterator(); } }; @@ -326,7 +326,7 @@ void relocateMapping() { assertEquals("old", mapping.map().get("old")); Set properties = stream(config.getPropertyNames().spliterator(), false).collect(toSet()); - Set mappedProperties = mappedProperties(configClassWithPrefix(RelocateMapping.class), properties); + Set mappedProperties = mappedProperties(configClass(RelocateMapping.class), properties); properties.removeAll(mappedProperties); Set relocateProperties = new HashSet<>(); for (String property : properties) { @@ -362,7 +362,7 @@ void fallbackMapping() { assertEquals("old", mapping.map().get("old")); Set properties = stream(config.getPropertyNames().spliterator(), false).collect(toSet()); - Set mappedProperties = mappedProperties(configClassWithPrefix(FallbackMapping.class), properties); + Set mappedProperties = mappedProperties(configClass(FallbackMapping.class), properties); properties.removeAll(mappedProperties); Set fallbackProperties = new HashSet<>(); for (String property : properties) { diff --git a/sources/hocon/src/test/java/io/smallrye/config/source/hocon/HoconConfigSourceTest.java b/sources/hocon/src/test/java/io/smallrye/config/source/hocon/HoconConfigSourceTest.java index 68b2e685c..6bd21bee7 100644 --- a/sources/hocon/src/test/java/io/smallrye/config/source/hocon/HoconConfigSourceTest.java +++ b/sources/hocon/src/test/java/io/smallrye/config/source/hocon/HoconConfigSourceTest.java @@ -70,7 +70,7 @@ void expressions() throws Exception { void list() throws Exception { SmallRyeConfig config = new SmallRyeConfigBuilder() .withSources(new HoconConfigSource(HoconConfigSource.class.getResource("/list.conf"))) - .withMapping(Countries.class, "countries") + .withMapping(Countries.class) .build(); Countries mapping = config.getConfigMapping(Countries.class); diff --git a/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigMappingTest.java b/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigMappingTest.java index b1eb94a8e..261bfa2d9 100644 --- a/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigMappingTest.java +++ b/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigMappingTest.java @@ -88,7 +88,7 @@ void yamlConfigMapping() { " password: 'Test!1234'\n"; SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(Proxies.class, "proxies") + .withMapping(Proxies.class) .withSources(new YamlConfigSource("yaml", yaml)) .build(); @@ -251,7 +251,7 @@ void jsonConfigMapping() { "}"; SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(Proxies.class, "proxies") + .withMapping(Proxies.class) .withSources(new YamlConfigSource("json", json)) .build(); @@ -477,7 +477,7 @@ void yamlListMaps() { " qux: 3"; SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(MapConfig.class, "app") + .withMapping(MapConfig.class) .withSources(new YamlConfigSource("yaml", yaml)) .build(); @@ -516,7 +516,7 @@ void yamlMapGroupMap() { " anotherkeybad: anothervaluebad"; SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(Parent.class, "parent") + .withMapping(Parent.class) .withSources(new YamlConfigSource("yaml", yaml)) .build(); @@ -734,7 +734,7 @@ void yamlNestedMaps() { assertEquals("2", yamlConfigSource.getValue("eventStaff.coordinators.tim.contactInfo.phones.cell")); SmallRyeConfig config = new SmallRyeConfigBuilder() - .withMapping(EventStaff.class, "eventStaff") + .withMapping(EventStaff.class) .withSources(yamlConfigSource) .build(); diff --git a/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java b/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java index 41d7739ce..dfed0bce1 100644 --- a/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java +++ b/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java @@ -265,7 +265,7 @@ void mapping() { SmallRyeConfig config = new SmallRyeConfigBuilder() .withSources(new YamlConfigSource("yaml", yaml)) - .withMapping(UsersMapping.class, "admin") + .withMapping(UsersMapping.class) .build(); UsersMapping usersMapping = config.getConfigMapping(UsersMapping.class); @@ -295,7 +295,7 @@ void mappingCollections() { SmallRyeConfig config = new SmallRyeConfigBuilder() .withSources(new YamlConfigSource("yaml", yaml)) - .withMapping(Application.class, "application") + .withMapping(Application.class) .build(); Application application = config.getConfigMapping(Application.class); @@ -334,7 +334,7 @@ void optional() { SmallRyeConfig config = new SmallRyeConfigBuilder() .withSources(new YamlConfigSource("yaml", yaml)) - .withMapping(Server.class, "server") + .withMapping(Server.class) .withProfile("base") .build(); @@ -350,7 +350,7 @@ void optional() { config = new SmallRyeConfigBuilder() .withSources(new YamlConfigSource("yaml", yaml)) - .withMapping(Server.class, "server") + .withMapping(Server.class) .withProfile("empty") .build(); diff --git a/testsuite/extra/src/test/java/io/smallrye/config/test/mapping/KotlinDefaulltFunctionTest.kt b/testsuite/extra/src/test/java/io/smallrye/config/test/mapping/KotlinDefaulltFunctionTest.kt index 13b29c5c8..b0cdacbf5 100644 --- a/testsuite/extra/src/test/java/io/smallrye/config/test/mapping/KotlinDefaulltFunctionTest.kt +++ b/testsuite/extra/src/test/java/io/smallrye/config/test/mapping/KotlinDefaulltFunctionTest.kt @@ -8,7 +8,7 @@ class KotlinDefaulltFunctionTest { @Test fun kotlinDefaultMethod() { val config = SmallRyeConfigBuilder() - .withMapping(KotlinDefaultFunction::class.java, "server") + .withMapping(KotlinDefaultFunction::class.java) .withDefaultValue("server.host", "localhost") .build() diff --git a/testsuite/extra/src/test/java/io/smallrye/config/test/mapping/KotlinMappingGetter.kt b/testsuite/extra/src/test/java/io/smallrye/config/test/mapping/KotlinMappingGetter.kt index 8cc85f740..2fbbd67b6 100644 --- a/testsuite/extra/src/test/java/io/smallrye/config/test/mapping/KotlinMappingGetter.kt +++ b/testsuite/extra/src/test/java/io/smallrye/config/test/mapping/KotlinMappingGetter.kt @@ -10,7 +10,7 @@ class KotlinMappingGetter { @Test fun mappingGetterNames() { val config = SmallRyeConfigBuilder() - .withMapping(GraphOption::class.java, "graph") + .withMapping(GraphOption::class.java) .withDefaultValue("graph.get-tenant", "tenant") .withDefaultValue("graph.get-client-id", "id") .withDefaultValue("graph.get-client-secret", "secret") diff --git a/validator/src/test/java/io/smallrye/config/validator/ValidateConfigTest.java b/validator/src/test/java/io/smallrye/config/validator/ValidateConfigTest.java index 30b07ec5a..a9955035b 100644 --- a/validator/src/test/java/io/smallrye/config/validator/ValidateConfigTest.java +++ b/validator/src/test/java/io/smallrye/config/validator/ValidateConfigTest.java @@ -98,7 +98,7 @@ void validateConfigMapping() { "server.info.admins.root[1].username", "admin", "server.info.firewall.accepted[0]", "127.0.0.1", "server.info.firewall.accepted[1]", "8.8.8")) - .withMapping(Server.class, "server") + .withMapping(Server.class) .build(); ConfigValidationException validationException = assertThrows(ConfigValidationException.class, @@ -139,7 +139,7 @@ void validateNamingStrategy() { .withSources(config( "server.the_host", "localhost", "server.the_port", "8080")) - .withMapping(ServerNamingStrategy.class, "server") + .withMapping(ServerNamingStrategy.class) .build(); ConfigValidationException validationException = assertThrows(ConfigValidationException.class, @@ -156,11 +156,11 @@ void validateNamingStrategy() { void validateConfigProperties() { SmallRyeConfig config = new SmallRyeConfigBuilder() .withValidator(new BeanValidationConfigValidatorImpl()) - .withMapping(Client.class, "client") + .withMapping(Client.class) .build(); ConfigValidationException validationException = assertThrows(ConfigValidationException.class, - () -> config.getConfigMapping(Client.class, "client")); + () -> config.getConfigMapping(Client.class)); assertEquals(1, validationException.getProblemCount()); List validations = new ArrayList<>(); validations.add(validationException.getProblem(0).getMessage()); @@ -174,7 +174,7 @@ void validateParent() { .withSources(config( "server.host", "localhost", "server.port", "80")) - .withMapping(ServerParent.class, "server") + .withMapping(ServerParent.class) .build(); ConfigValidationException validationException = assertThrows(ConfigValidationException.class,