-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Microprofile Config support for Java SE Bootstrap API
Signed-off-by: Markus KARG <markus@headcrashing.eu>
- Loading branch information
Showing
6 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
48 changes: 48 additions & 0 deletions
48
...vase/src/main/java/org/glassfish/jersey/server/microprofile/MicroprofileConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...-javase/src/main/resources/META-INF/services/org.glassfish.jersey.server.spi.Configurator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.glassfish.jersey.server.microprofile.MicroprofileConfigurator |
62 changes: 62 additions & 0 deletions
62
.../src/test/java/org/glassfish/jersey/server/microprofile/MicroprofileConfiguratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters