diff --git a/microprofile/server/src/main/java/io/helidon/microprofile/server/JaxRsService.java b/microprofile/server/src/main/java/io/helidon/microprofile/server/JaxRsService.java index c4ab2833240..159bbf5b583 100644 --- a/microprofile/server/src/main/java/io/helidon/microprofile/server/JaxRsService.java +++ b/microprofile/server/src/main/java/io/helidon/microprofile/server/JaxRsService.java @@ -72,10 +72,7 @@ import static org.glassfish.jersey.CommonProperties.PROVIDER_DEFAULT_DISABLE; import static org.glassfish.jersey.server.ServerProperties.WADL_FEATURE_DISABLE; -/** - * JAX-RS Service. - */ -public class JaxRsService implements HttpService { +class JaxRsService implements HttpService { /** * If set to {@code "true"}, Jersey will ignore responses in exceptions. */ @@ -100,8 +97,7 @@ private JaxRsService(ResourceConfig resourceConfig, this.application = getApplication(resourceConfig); } - @SuppressWarnings("checkstyle:MissingJavadocMethod") - public static JaxRsService create(ResourceConfig resourceConfig, InjectionManager injectionManager) { + static JaxRsService create(ResourceConfig resourceConfig, InjectionManager injectionManager) { resourceConfig.property(PROVIDER_DEFAULT_DISABLE, "ALL"); resourceConfig.property(WADL_FEATURE_DISABLE, "true"); diff --git a/microprofile/testing/junit5/pom.xml b/microprofile/testing/junit5/pom.xml index ad4b10cb685..8015320178e 100644 --- a/microprofile/testing/junit5/pom.xml +++ b/microprofile/testing/junit5/pom.xml @@ -43,7 +43,6 @@ org.glassfish.jersey.ext.cdi jersey-weld2-se true - provided org.junit.jupiter diff --git a/microprofile/testing/junit5/src/main/java/module-info.java b/microprofile/testing/junit5/src/main/java/module-info.java index 5e1730bdec3..3439d26f82f 100644 --- a/microprofile/testing/junit5/src/main/java/module-info.java +++ b/microprofile/testing/junit5/src/main/java/module-info.java @@ -21,13 +21,14 @@ requires io.helidon.config.mp; requires io.helidon.config.yaml.mp; + requires io.helidon.microprofile.server; requires jakarta.inject; requires org.junit.jupiter.api; requires transitive jakarta.cdi; requires transitive jakarta.ws.rs; - requires static io.helidon.microprofile.server; + requires static jersey.cdi1x; requires static jersey.weld2.se; diff --git a/microprofile/testing/testng/pom.xml b/microprofile/testing/testng/pom.xml index 0105b52951d..f96e2061a89 100644 --- a/microprofile/testing/testng/pom.xml +++ b/microprofile/testing/testng/pom.xml @@ -43,7 +43,6 @@ org.glassfish.jersey.ext.cdi jersey-weld2-se true - provided io.helidon.jersey diff --git a/microprofile/testing/testng/src/main/java/module-info.java b/microprofile/testing/testng/src/main/java/module-info.java index 40aa0c9b47a..96d93c5c876 100644 --- a/microprofile/testing/testng/src/main/java/module-info.java +++ b/microprofile/testing/testng/src/main/java/module-info.java @@ -23,13 +23,13 @@ requires io.helidon.config.mp; requires io.helidon.config.yaml.mp; + requires io.helidon.microprofile.server; requires jakarta.cdi; requires jakarta.inject; requires jakarta.ws.rs; requires microprofile.config.api; requires org.testng; - requires static io.helidon.microprofile.server; requires static jersey.cdi1x; requires static jersey.weld2.se; diff --git a/microprofile/tests/config/src/test/java/io/helidon/microprofile/config/ConfigBeanDescriptorTest.java b/microprofile/tests/config/src/test/java/io/helidon/microprofile/config/ConfigBeanDescriptorTest.java new file mode 100644 index 00000000000..b946db51c0a --- /dev/null +++ b/microprofile/tests/config/src/test/java/io/helidon/microprofile/config/ConfigBeanDescriptorTest.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2022 Oracle and/or its affiliates. + * + * 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. + */ +package io.helidon.microprofile.config; + +import java.lang.reflect.Field; +import java.lang.reflect.Type; +import java.util.Map; + +import io.helidon.config.mp.MpConfigSources; +import io.helidon.microprofile.config.testsubjects.TestConfiguredBean; + +import jakarta.enterprise.inject.spi.AnnotatedType; +import jakarta.enterprise.inject.spi.InjectionPoint; +import org.eclipse.microprofile.config.Config; +import org.eclipse.microprofile.config.inject.ConfigProperties; +import org.eclipse.microprofile.config.spi.ConfigProviderResolver; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.collection.IsIterableContainingInOrder.contains; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Lower level testing for {@link io.helidon.microprofile.config.ConfigBeanDescriptor}. + */ +class ConfigBeanDescriptorTest { + + private static MutableMpTest.MutableSource source; + private static Config config; + private static io.helidon.config.Config emptyConfig; + + @BeforeAll + static void initClass() { + config = createTestConfiguredBeanConfig(); + + // we need to ensure empty config is initialized before running other tests, + // as this messes up the mapping service counter + emptyConfig = io.helidon.config.Config.empty(); + + source = new MutableMpTest.MutableSource("initial"); + + // register config + ConfigProviderResolver configProvider = ConfigProviderResolver.instance(); + configProvider.registerConfig(config, Thread.currentThread().getContextClassLoader()); + } + + @Test + @SuppressWarnings("unchecked") + void testProduceListFields() throws Exception { + // setup for the test + AnnotatedType annotatedType = mock(AnnotatedType.class); + when(annotatedType.getJavaClass()).thenReturn((Class) TestConfiguredBean.class); + + Field strListField = TestConfiguredBean.class.getField("strList"); + Type strListType = strListField.getGenericType(); + Field intListField = TestConfiguredBean.class.getField("intList"); + Type intListType = intListField.getGenericType(); + + ConfigProperties configProperties = TestConfiguredBean.class.getAnnotation(ConfigProperties.class); + ConfigBeanDescriptor descriptor = ConfigBeanDescriptor.create(annotatedType, configProperties); + + InjectionPoint strListInjectionPoint = mock(InjectionPoint.class); + when(strListInjectionPoint.getType()).thenReturn(strListType); + + InjectionPoint intListInjectionPoint = mock(InjectionPoint.class); + when(intListInjectionPoint.getType()).thenReturn(intListType); + + // the target of the test starts here: + Object instance = descriptor.produce(strListInjectionPoint, config); + assertThat(((TestConfiguredBean) instance).strList, contains("a", "b", "c")); + + instance = descriptor.produce(intListInjectionPoint, config); + assertThat(((TestConfiguredBean) instance).intList, contains(1, 2, 3)); + } + + @Test + @SuppressWarnings("unchecked") + void testProduceGenericTypesNotSupported() throws Exception { + AnnotatedType annotatedType = mock(AnnotatedType.class); + when(annotatedType.getJavaClass()).thenReturn((Class) TestConfiguredBean.Unsupported.class); + ConfigProperties configProperties = TestConfiguredBean.class.getAnnotation(ConfigProperties.class); + UnsupportedOperationException e = assertThrows(UnsupportedOperationException.class, + () -> ConfigBeanDescriptor.create(annotatedType, configProperties)); + assertThat(e.getMessage(), is("No idea how to handle ?")); + } + + static Config createTestConfiguredBeanConfig() { + return ConfigProviderResolver.instance() + .getBuilder() + .withSources(MpConfigSources.create(Map.of( + "strList", "a,b,c", + "intList", "1,2,3", + "untypedList", "a,b,c"))) + .build(); + } + +} \ No newline at end of file diff --git a/microprofile/config/src/test/java/io/helidon/microprofile/config/testsubjects/TestConfiguredBean.java b/microprofile/tests/config/src/test/java/io/helidon/microprofile/config/testsubjects/TestConfiguredBean.java similarity index 100% rename from microprofile/config/src/test/java/io/helidon/microprofile/config/testsubjects/TestConfiguredBean.java rename to microprofile/tests/config/src/test/java/io/helidon/microprofile/config/testsubjects/TestConfiguredBean.java diff --git a/microprofile/tests/server/src/test/java/io/helidon/microprofile/tests/server/JerseyPropertiesTest.java b/microprofile/tests/server/src/test/java/io/helidon/microprofile/server/JerseyPropertiesTest.java similarity index 97% rename from microprofile/tests/server/src/test/java/io/helidon/microprofile/tests/server/JerseyPropertiesTest.java rename to microprofile/tests/server/src/test/java/io/helidon/microprofile/server/JerseyPropertiesTest.java index da510b4d9c8..850bc363646 100644 --- a/microprofile/tests/server/src/test/java/io/helidon/microprofile/tests/server/JerseyPropertiesTest.java +++ b/microprofile/tests/server/src/test/java/io/helidon/microprofile/server/JerseyPropertiesTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.microprofile.tests.server; +package io.helidon.microprofile.server; import io.helidon.microprofile.config.ConfigCdiExtension; import io.helidon.microprofile.server.JaxRsCdiExtension; diff --git a/microprofile/tests/testing/testng/src/test/java/io/helidon/microprofile/tests/testing/testng/TestReqScopeDisabledDiscovery.java b/microprofile/tests/testing/testng/src/test/java/io/helidon/microprofile/tests/testing/testng/TestReqScopeDisabledDiscovery.java index 4d166c7429a..a80f587cd67 100644 --- a/microprofile/tests/testing/testng/src/test/java/io/helidon/microprofile/tests/testing/testng/TestReqScopeDisabledDiscovery.java +++ b/microprofile/tests/testing/testng/src/test/java/io/helidon/microprofile/tests/testing/testng/TestReqScopeDisabledDiscovery.java @@ -33,7 +33,7 @@ // JAX-RS Request scope @AddJaxRs @AddBean(TestReqScopeDisabledDiscovery.MyController.class) -class TestReqScopeDisabledDiscovery { +public class TestReqScopeDisabledDiscovery { @Inject private WebTarget target;