diff --git a/config/config-mp/src/main/java/io/helidon/config/mp/MpConfig.java b/config/config-mp/src/main/java/io/helidon/config/mp/MpConfig.java index 8b6fb7f9d..dd5ed279d 100644 --- a/config/config-mp/src/main/java/io/helidon/config/mp/MpConfig.java +++ b/config/config-mp/src/main/java/io/helidon/config/mp/MpConfig.java @@ -52,10 +52,8 @@ public final class MpConfig { io.helidon.config.Config.Builder builder = io.helidon.config.Config.builder() .disableEnvironmentVariablesSource() .disableSystemPropertiesSource() - .disableMapperServices() .disableCaching() - .disableParserServices() - .disableFilterServices(); + .disableParserServices(); if (mpConfig instanceof MpConfigImpl) { ((MpConfigImpl) mpConfig).converters() diff --git a/config/config-mp/src/test/java/io/helidon/config/mp/MpConfigTest.java b/config/config-mp/src/test/java/io/helidon/config/mp/MpConfigTest.java index 00ccb2280..9763a80d6 100644 --- a/config/config-mp/src/test/java/io/helidon/config/mp/MpConfigTest.java +++ b/config/config-mp/src/test/java/io/helidon/config/mp/MpConfigTest.java @@ -20,8 +20,14 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import java.util.function.BiFunction; +import java.util.function.Function; +import io.helidon.common.GenericType; +import io.helidon.config.spi.ConfigMapper; +import io.helidon.config.spi.ConfigMapperProvider; import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.spi.ConfigProviderResolver; import org.eclipse.microprofile.config.spi.ConfigSource; @@ -147,6 +153,25 @@ public class MpConfigTest { })); } + /** + * Ensure mapping services are still enabled when converting configuration from MP to SE. + * + * @see "https://github.com/oracle/helidon/issues/1802" + */ + @Test + public void testMpToHelidonConfigMappingServicesNotDisabled() { + var mutable = new MutableConfigSource(); + + Config config = ConfigProviderResolver.instance().getBuilder() + .withSources(mutable) + .build(); + + TestMapperProvider.reset(); // reset count so we can properly assert the converted config creates the mappers + + MpConfig.toHelidonConfig(config); + assertThat(TestMapperProvider.getCreationCount(), is(1)); + } + private static class MutableConfigSource implements ConfigSource { private final AtomicReference value = new AtomicReference<>("initial"); @@ -207,5 +232,41 @@ public class MpConfigTest { return Objects.hash(flavor, size); } } + + public static final class TestMapperProvider implements ConfigMapperProvider { + private static final AtomicInteger counter = new AtomicInteger(); + + public TestMapperProvider() { + counter.incrementAndGet(); + } + + @Override + public Map, Function> mappers() { + return null; + } + + @Override + public Map, BiFunction> genericTypeMappers() { + return null; + } + + @Override + public Optional> mapper(final Class type) { + return Optional.empty(); + } + + @Override + public Optional> mapper(final GenericType type) { + return Optional.empty(); + } + + public static int getCreationCount() { + return counter.get(); + } + + public static void reset() { + counter.set(0); + } + } } diff --git a/config/config-mp/src/test/resources/META-INF/services/io.helidon.config.spi.ConfigMapperProvider b/config/config-mp/src/test/resources/META-INF/services/io.helidon.config.spi.ConfigMapperProvider new file mode 100644 index 000000000..b0e3f06d4 --- /dev/null +++ b/config/config-mp/src/test/resources/META-INF/services/io.helidon.config.spi.ConfigMapperProvider @@ -0,0 +1,17 @@ +# +# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +io.helidon.config.mp.MpConfigTest$TestMapperProvider