Skip to content

Commit

Permalink
Microprofile Config support for Java SE Bootstrap API
Browse files Browse the repository at this point in the history
Signed-off-by: Markus KARG <markus@headcrashing.eu>
  • Loading branch information
mkarg committed Oct 14, 2018
1 parent b50f923 commit eeb5e1a
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 0 deletions.
65 changes: 65 additions & 0 deletions ext/microprofile-config-javase/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2018 Markus KARG This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0 which
is available at http://www.eclipse.org/legal/epl-2.0. This Source Code may
also be made available under the following Secondary Licenses when the conditions
for such availability set forth in the Eclipse Public License v. 2.0 are
satisfied: GNU General Public License, version 2 with the GNU Classpath Exception,
which is available at https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 -->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>project</artifactId>
<version>2.28-SNAPSHOT</version>
</parent>

<artifactId>jersey-microprofile-config-javase</artifactId>
<name>jersey-microprofile-config-javase</name>

<description>
Jersey extension module providing support for Microprofile Config integration on Java SE platforms.
</description>

<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<version>${microprofile.config.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2018 Markus KARG. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.server.microprofile;

import javax.ws.rs.JAXRS.Configuration;
import javax.ws.rs.ProcessingException;

import org.eclipse.microprofile.config.Config;
import org.glassfish.jersey.server.spi.Configurator;

/**
* Configurator for Microprofile Config configurations.
*
* @author Markus KARG (markus@headcrashing.eu)
* @since 2.28
*/
public class MicroprofileConfigurator implements Configurator {

/**
* Configures the configuration builder according to the provided configuration. Just does nothing if the type of
* configuration is other than {@link Config}.
*
* @param configurationBuilder The configuration builder to configure.
* @param configuration The configuration to use for configuring the configuration builder.
*/
@Override
public void configure(final Configuration.Builder configurationBuilder, final Object configuration)
throws ProcessingException {
if (configuration instanceof Config) {
configurationBuilder.from(((Config) configuration)::getOptionalValue);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.glassfish.jersey.server.microprofile.MicroprofileConfigurator
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2018 Markus KARG. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.server.microprofile;

import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import java.util.Optional;
import java.util.function.BiFunction;

import javax.ws.rs.JAXRS;

import org.eclipse.microprofile.config.Config;
import org.glassfish.jersey.server.spi.Configurator;
import org.junit.Test;

/**
* Unit tests for {@link MicroprofileConfigurator}.
*
* @author Markus KARG (markus@headcrashing.eu)
* @since 2.28
*/
public class MicroprofileConfiguratorTest {

@Test
@SuppressWarnings("unchecked")
public final void shouldProvideGetOptionalValueAsPropertiesProviderToConfigurationBuilder() {
// given
final Configurator configurator = new MicroprofileConfigurator();
final Config config = mock(Config.class);
final JAXRS.Configuration.Builder configurationBuilder = mock(JAXRS.Configuration.Builder.class);
given(configurationBuilder.from(any(BiFunction.class))).willAnswer(invocation -> {
final BiFunction<String, Class<String>, Optional<?>> propertiesProvider =
invocation.getArgumentAt(0, BiFunction.class);
propertiesProvider.apply("NAME", String.class);
return invocation.getMock();
});

// when
configurator.configure(configurationBuilder, config);

// then
verify(config).getOptionalValue("NAME", String.class);
}

}
1 change: 1 addition & 0 deletions ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<module>servlet-portability</module>
<module>spring4</module>
<module>wadl-doclet</module>
<module>microprofile-config-javase</module>
</modules>

<dependencies>
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2010,5 +2010,6 @@
<xmlunit.version>1.6</xmlunit.version>
<yasson.version>1.0.1</yasson.version>
<skip.e2e>false</skip.e2e>
<microprofile.config.version>1.3</microprofile.config.version>
</properties>
</project>

0 comments on commit eeb5e1a

Please sign in to comment.