Skip to content

Commit

Permalink
Apply comments
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Aleksandrov <dmitry.aleksandrov@oracle.com>
  • Loading branch information
dalexandrov committed Dec 5, 2023
1 parent a1d4cc7 commit c82f046
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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");

Expand Down
1 change: 0 additions & 1 deletion microprofile/testing/junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-weld2-se</artifactId>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
3 changes: 2 additions & 1 deletion microprofile/testing/junit5/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion microprofile/testing/testng/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<groupId>org.glassfish.jersey.ext.cdi</groupId>
<artifactId>jersey-weld2-se</artifactId>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.helidon.jersey</groupId>
Expand Down
2 changes: 1 addition & 1 deletion microprofile/testing/testng/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// JAX-RS Request scope
@AddJaxRs
@AddBean(TestReqScopeDisabledDiscovery.MyController.class)
class TestReqScopeDisabledDiscovery {
public class TestReqScopeDisabledDiscovery {

@Inject
private WebTarget target;
Expand Down

0 comments on commit c82f046

Please sign in to comment.