Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1802 - Allow use of filters and mappers when converting MP to He… #1803

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ public static io.helidon.config.Config toHelidonConfig(Config 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
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;
Expand Down Expand Up @@ -147,6 +153,25 @@ void arrayTest() {
}));
}

/**
* 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");

Expand Down Expand Up @@ -207,5 +232,41 @@ public int hashCode() {
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);
}
}
}

Original file line number Diff line number Diff line change
@@ -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