Repository: tomee
Updated Branches:
  refs/heads/master a1b8f66ec -> 004ad5118


TOMEE-2292 - Config Microprofile Example. Closes #220.


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/0febf055
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/0febf055
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/0febf055

Branch: refs/heads/master
Commit: 0febf05566100f31d92577f221c96bca57dc0bb1
Parents: a1b8f66
Author: Daniel Cunha (soro) <daniels...@apache.org>
Authored: Mon Nov 26 11:45:15 2018 -0300
Committer: Roberto Cortez <radcor...@yahoo.com>
Committed: Tue Dec 11 00:31:52 2018 +0000

----------------------------------------------------------------------
 examples/mp-config-example/README.md            |  0
 examples/mp-config-example/pom.xml              | 58 +++++++++++++++++++
 .../org/superbiz/config/PropertiesRest.java     | 59 ++++++++++++++++++++
 .../src/main/resources/META-INF/beans.xml       |  0
 .../META-INF/microprofile-config.properties     |  3 +
 .../org/superbiz/config/PropertiesRestTest.java | 53 ++++++++++++++++++
 .../src/test/resources/arquillian.xml           | 30 ++++++++++
 examples/pom.xml                                |  1 +
 8 files changed, 204 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/0febf055/examples/mp-config-example/README.md
----------------------------------------------------------------------
diff --git a/examples/mp-config-example/README.md 
b/examples/mp-config-example/README.md
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/tomee/blob/0febf055/examples/mp-config-example/pom.xml
----------------------------------------------------------------------
diff --git a/examples/mp-config-example/pom.xml 
b/examples/mp-config-example/pom.xml
new file mode 100644
index 0000000..6865200
--- /dev/null
+++ b/examples/mp-config-example/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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";>
+    <parent>
+        <artifactId>examples</artifactId>
+        <groupId>org.apache.tomee</groupId>
+        <version>8.0.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>mp-config-example</artifactId>
+    <packaging>war</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.tomee</groupId>
+            <artifactId>javaee-api</artifactId>
+            <version>${version.javaee-api}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.microprofile.config</groupId>
+            <artifactId>microprofile-config-api</artifactId>
+            <version>${microprofile.config.version}</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.tomee</groupId>
+            <artifactId>openejb-cxf-rs</artifactId>
+            <version>${tomee.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian.junit</groupId>
+            <artifactId>arquillian-junit-container</artifactId>
+            <version>${version.arquillian}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tomee</groupId>
+            <artifactId>arquillian-tomee-remote</artifactId>
+            <version>${tomee.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tomee</groupId>
+            <artifactId>apache-tomee</artifactId>
+            <version>${tomee.version}</version>
+            <type>zip</type>
+            <classifier>microprofile</classifier>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tomee/blob/0febf055/examples/mp-config-example/src/main/java/org/superbiz/config/PropertiesRest.java
----------------------------------------------------------------------
diff --git 
a/examples/mp-config-example/src/main/java/org/superbiz/config/PropertiesRest.java
 
b/examples/mp-config-example/src/main/java/org/superbiz/config/PropertiesRest.java
new file mode 100644
index 0000000..fe98a37
--- /dev/null
+++ 
b/examples/mp-config-example/src/main/java/org/superbiz/config/PropertiesRest.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.superbiz.config;
+
+import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+@Path("/sample")
+@ApplicationScoped
+public class PropertiesRest {
+
+    @Inject
+    private Config config;
+
+    @Inject
+    @ConfigProperty(name = "defaultProperty", defaultValue = "ALOHA")
+    private String defaultProperty;
+
+    @Inject
+    @ConfigProperty(name = "java.runtime.version")
+    private String javaVersion;
+
+    @GET
+    @Path("defaultProperty")
+    public String getDefaultProperty() {
+        return defaultProperty;
+    }
+
+    @GET
+    @Path("javaVersion")
+    public String getJavaVersionPropertyFromSystemProperties() {
+        return config.getValue("java.runtime.version", String.class);
+    }
+
+    @GET
+    @Path("injectedJavaVersion")
+    public String getJavaVersionWithInjection() {
+        return javaVersion;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/0febf055/examples/mp-config-example/src/main/resources/META-INF/beans.xml
----------------------------------------------------------------------
diff --git a/examples/mp-config-example/src/main/resources/META-INF/beans.xml 
b/examples/mp-config-example/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/tomee/blob/0febf055/examples/mp-config-example/src/main/resources/META-INF/microprofile-config.properties
----------------------------------------------------------------------
diff --git 
a/examples/mp-config-example/src/main/resources/META-INF/microprofile-config.properties
 
b/examples/mp-config-example/src/main/resources/META-INF/microprofile-config.properties
new file mode 100644
index 0000000..2b67141
--- /dev/null
+++ 
b/examples/mp-config-example/src/main/resources/META-INF/microprofile-config.properties
@@ -0,0 +1,3 @@
+config_ordinal = 500
+sample.microprofile-config=ALOHA!!
+sample.microrpfile.name=DANIEL
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tomee/blob/0febf055/examples/mp-config-example/src/test/java/org/superbiz/config/PropertiesRestTest.java
----------------------------------------------------------------------
diff --git 
a/examples/mp-config-example/src/test/java/org/superbiz/config/PropertiesRestTest.java
 
b/examples/mp-config-example/src/test/java/org/superbiz/config/PropertiesRestTest.java
new file mode 100644
index 0000000..5f8a1c5
--- /dev/null
+++ 
b/examples/mp-config-example/src/test/java/org/superbiz/config/PropertiesRestTest.java
@@ -0,0 +1,53 @@
+package org.superbiz.config;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Arquillian.class)
+public class PropertiesRestTest {
+
+    @ArquillianResource
+    private URL base;
+
+    @Deployment
+    public static WebArchive createDeployment() {
+        return ShrinkWrap.create(WebArchive.class, "test.war")
+                .addClasses(PropertiesRest.class)
+                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+    }
+
+    @Test
+    public void testDefaultValue() {
+        final String message = WebClient.create(base.toExternalForm())
+                .path("/sample/defaultProperty")
+                .get(String.class);
+        assertEquals("ALOHA", message);
+    }
+
+    @Test
+    public void testGetJavaVersionFromConfig() {
+        final String message = WebClient.create(base.toExternalForm())
+                .path("/sample/javaVersion")
+                .get(String.class);
+        assertEquals(System.getProperty("java.runtime.version"), message);
+    }
+
+    @Test
+    public void testGetInjectedJavaVersion() {
+        final String message = WebClient.create(base.toExternalForm())
+                .path("/sample/injectedJavaVersion")
+                .get(String.class);
+        assertEquals(System.getProperty("java.runtime.version"), message);
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/0febf055/examples/mp-config-example/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/examples/mp-config-example/src/test/resources/arquillian.xml 
b/examples/mp-config-example/src/test/resources/arquillian.xml
new file mode 100644
index 0000000..3029d48
--- /dev/null
+++ b/examples/mp-config-example/src/test/resources/arquillian.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You 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.
+-->
+<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
+
+  <container qualifier="tomee" default="true">
+    <configuration>
+      <property name="httpPort">-1</property>
+      <property name="stopPort">-1</property>
+      <property name="classifier">microprofile</property>
+      <property name="dir">target/apache-tomee-remote</property>
+      <property 
name="appWorkingDir">target/arquillian-test-working-dir</property>
+    </configuration>
+  </container>
+</arquillian>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tomee/blob/0febf055/examples/pom.xml
----------------------------------------------------------------------
diff --git a/examples/pom.xml b/examples/pom.xml
index c0f47f9..3e9089c 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -177,6 +177,7 @@ BROKEN, see TOMEE-2140
     <module>concurrency-utils</module>
     <module>mvc-cxf</module>
     <module>mp-faulttolerance-retry</module>
+    <module>mp-config-example</module>
   </modules>
 
   <dependencies>

Reply via email to