Fix #1802 - Allow use of filters and mappers when converting MP to Helidon config (#1803)

This commit is contained in:
Ryan Lubke
2020-05-15 01:46:52 -07:00
committed by GitHub
parent 378d5d5a88
commit 9be1f1c57f
3 changed files with 79 additions and 3 deletions

View File

@@ -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()

View File

@@ -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<String> 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<Class<?>, Function<io.helidon.config.Config, ?>> mappers() {
return null;
}
@Override
public Map<GenericType<?>, BiFunction<io.helidon.config.Config, ConfigMapper, ?>> genericTypeMappers() {
return null;
}
@Override
public <T> Optional<Function<io.helidon.config.Config, T>> mapper(final Class<T> type) {
return Optional.empty();
}
@Override
public <T> Optional<BiFunction<io.helidon.config.Config, ConfigMapper, T>> mapper(final GenericType<T> type) {
return Optional.empty();
}
public static int getCreationCount() {
return counter.get();
}
public static void reset() {
counter.set(0);
}
}
}

View File

@@ -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