You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ra...@apache.org on 2018/12/17 22:24:08 UTC

[3/5] tomee git commit: TOMEE-2297 fixed build issues, cleaned code and added content for readme

TOMEE-2297 fixed build issues, cleaned code and added content for readme


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

Branch: refs/heads/master
Commit: 66f94f2c0f47f0c0807887997cbdfd0430360890
Parents: f0e2109
Author: CesarHernandezGt <cf...@gmail.com>
Authored: Fri Dec 14 22:28:06 2018 -0600
Committer: Roberto Cortez <ra...@yahoo.com>
Committed: Mon Dec 17 22:22:19 2018 +0000

----------------------------------------------------------------------
 examples/mp-rest-client/README.md               | 137 +++++++++++++++++++
 examples/mp-rest-client/pom.xml                 |  70 +++++++---
 .../src/test/resources/arquillian.xml           |   1 -
 3 files changed, 190 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/66f94f2c/examples/mp-rest-client/README.md
----------------------------------------------------------------------
diff --git a/examples/mp-rest-client/README.md b/examples/mp-rest-client/README.md
index cedeb35..0f0fcc5 100755
--- a/examples/mp-rest-client/README.md
+++ b/examples/mp-rest-client/README.md
@@ -1 +1,138 @@
 # Microprofile Rest client
+This is a basic example on how to configure and use MicroProfile Rest Client in TomEE.
+
+## Run the tests for different scenarios related with JWT validation
+
+    mvn clean test 
+
+## Requirementes and configuration
+
+To use MicroProfile Rest Client you need 3 changes in your project:
+
+1) Add the to the `pom.xml` the dependency:
+
+        <dependency>
+            <groupId>org.eclipse.microprofile.rest.client</groupId>
+            <artifactId>microprofile-rest-client-api</artifactId>
+            <version>${microprofile.rest-client.version}</version>
+            <scope>provided</scope>
+        </dependency>
+
+2) Provide configuration files: `microprofile-config.properties`
+
+        org.superbiz.rest.BookResourceClient/mp-rest/url=http://localhost:4444
+
+3) Provide an interface that you can build from the JAX-RS resource you want to consume: `BookResourceClient.java`
+    
+        package org.superbiz.rest;
+        
+        import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
+        import javax.enterprise.context.Dependent;
+        import javax.ws.rs.*;
+        import javax.ws.rs.core.MediaType;
+        import java.util.List;
+        
+        @Dependent
+        @RegisterRestClient
+        @Path("/test/api/library")
+        @Produces(MediaType.APPLICATION_JSON)
+        @Consumes(MediaType.APPLICATION_JSON)
+        public interface BookResourceClient {
+        
+            @GET
+            String status();
+        
+            @POST
+            @Path("/books")
+            void addBook(Book newBook);
+        
+            @DELETE
+            @Path("/books/{id}")
+            void deleteBook(@PathParam("id") int id);
+        
+            @PUT
+            @Path("/books")
+            void updateBook(Book updatedBook);
+        
+            @GET
+            @Path("/books/{id}")
+            Book getBook(@PathParam("id") int id);
+        
+            @GET
+            @Path("/books")
+            List<Book> getListOfBooks();
+        
+        }
+
+
+## Use of MicroProfile Rest Client in TomEE
+
+The class `BookResourceTest.java` shows how easy is to use the type-safe approach provided by MicroProfile Rest Client to consume an existing JAX-RS resource. 
+
+    package org.superbiz.rest;
+    
+    import org.eclipse.microprofile.rest.client.inject.RestClient;
+    import org.jboss.arquillian.container.test.api.Deployment;
+    import org.jboss.arquillian.junit.Arquillian;
+    import org.jboss.shrinkwrap.api.ShrinkWrap;
+    import org.jboss.shrinkwrap.api.asset.StringAsset;
+    import org.jboss.shrinkwrap.api.spec.WebArchive;
+    import org.junit.Test;
+    import org.junit.runner.RunWith;
+    
+    import javax.inject.Inject;
+    
+    import static org.junit.Assert.assertTrue;
+    
+    @RunWith(Arquillian.class)
+    public class BookResourceTest {
+    
+        @Deployment()
+        public static WebArchive createDeployment() {
+            final WebArchive webArchive = ShrinkWrap.create(WebArchive.class, "test.war")
+                    .addClass(BookResource.class)
+                    .addClass(Book.class)
+                    .addClass(BookBean.class)
+                    .addClass(BookResourceClient.class)
+                    .addClass(ApplicationConfig.class)
+                    .addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml")
+                    .addAsResource("META-INF/microprofile-config.properties");
+            return webArchive;
+        }
+    
+    
+        @Inject
+        @RestClient
+        private BookResourceClient bookResourceClient;
+    
+        @Test()
+        public void testServerStatus(){
+            bookResourceClient.addBook(new Book(1,"TomEE Book"));
+        }
+    
+        @Test
+        public void testBookResource(){
+            bookResourceClient.addBook(new Book(1, "TomEE and MicroProfile Adventures"));
+            bookResourceClient.addBook(new Book(2, "Top 10 Tomee Configuraiton Tips"));
+    
+    
+            assertTrue(bookResourceClient.getListOfBooks().size() == 2);
+            assertTrue(bookResourceClient.getBook(1).getName().equalsIgnoreCase("TomEE and MicroProfile Adventures"));
+    
+            bookResourceClient.deleteBook(1);
+            assertTrue(bookResourceClient.getListOfBooks().size() == 1);
+            assertTrue(bookResourceClient.getBook(2).getName().equalsIgnoreCase("Top 10 Tomee Configuraiton Tips"));
+    
+            bookResourceClient.updateBook(new Book(2, "Top 3 Tomee Configuraiton Tips"));
+            assertTrue(bookResourceClient.getListOfBooks().size() == 1);
+            assertTrue(bookResourceClient.getBook(2).getName().equalsIgnoreCase("Top 3 Tomee Configuraiton Tips"));
+        }
+    
+    }
+
+## About the Test architecture
+
+The test cases from this project are built using Arquillian and TomEE Remote. 
+The arquillian configuration can be found in
+`src/test/resources/arquillian.xml`
+

http://git-wip-us.apache.org/repos/asf/tomee/blob/66f94f2c/examples/mp-rest-client/pom.xml
----------------------------------------------------------------------
diff --git a/examples/mp-rest-client/pom.xml b/examples/mp-rest-client/pom.xml
index 887f1f3..bd4b2bc 100755
--- a/examples/mp-rest-client/pom.xml
+++ b/examples/mp-rest-client/pom.xml
@@ -1,31 +1,66 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+-->
+
 <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>
 
+    <groupId>org.superbiz</groupId>
     <artifactId>mp-rest-client</artifactId>
+    <version>8.0.0-SNAPSHOT</version>
     <packaging>war</packaging>
+    <name>OpenEJB :: Examples :: mp-rest-client</name>
+
+
+    <properties>
+        <microprofile.rest-client.version>1.1</microprofile.rest-client.version>
+        <version.javaee-api>8.0</version.javaee-api>
+        <version.arquillian.bom>1.1.13.Final</version.arquillian.bom>
+        <tomee.version>${project.version}</tomee.version>
+        <junit.version>4.12</junit.version>
+    </properties>
+
 
     <dependencies>
         <dependency>
             <groupId>org.apache.tomee</groupId>
             <artifactId>javaee-api</artifactId>
-            <version>8.0</version>
+            <version>${version.javaee-api}</version>
             <scope>provided</scope>
         </dependency>
+
         <dependency>
-            <groupId>org.eclipse.microprofile</groupId>
-            <artifactId>microprofile</artifactId>
-            <version>1.3</version>
-            <type>pom</type>
+            <groupId>org.eclipse.microprofile.rest.client</groupId>
+            <artifactId>microprofile-rest-client-api</artifactId>
+            <version>${microprofile.rest-client.version}</version>
             <scope>provided</scope>
         </dependency>
+
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.tomee</groupId>
             <artifactId>openejb-cxf-rs</artifactId>
@@ -35,13 +70,14 @@
         <dependency>
             <groupId>org.jboss.arquillian.junit</groupId>
             <artifactId>arquillian-junit-container</artifactId>
-            <version>1.0.3.Final</version>
+            <version>${version.arquillian.bom}</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>
@@ -58,19 +94,19 @@
             <plugin>
                 <groupId>org.apache.tomee.maven</groupId>
                 <artifactId>tomee-maven-plugin</artifactId>
-                <version>${tomee.version}</version>
+                <version>${project.version}</version>
                 <configuration>
                     <tomeeClassifier>microprofile</tomeeClassifier>
-                    <context>${artifactId}</context>
+                    <context>${project.artifactId}</context>
                 </configuration>
             </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-surefire-plugin</artifactId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.7.0</version>
                 <configuration>
-                    <reuseForks>false</reuseForks>
-                    <!-- need it in order to see complete logs on terminal during: mvn clean test-->
-                    <forkCount>0</forkCount>
+                    <source>1.8</source>
+                    <target>1.8</target>
                 </configuration>
             </plugin>
         </plugins>

http://git-wip-us.apache.org/repos/asf/tomee/blob/66f94f2c/examples/mp-rest-client/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/examples/mp-rest-client/src/test/resources/arquillian.xml b/examples/mp-rest-client/src/test/resources/arquillian.xml
index 5fd386b..534eb1c 100755
--- a/examples/mp-rest-client/src/test/resources/arquillian.xml
+++ b/examples/mp-rest-client/src/test/resources/arquillian.xml
@@ -31,7 +31,6 @@
       <property name="classifier">microprofile</property>
       <property name="simpleLog">true</property>
       <property name="cleanOnStartUp">true</property>
-      <property name="additionalLibs">mvn:com.github.javafaker:javafaker:0.15</property>
       <property name="dir">target/server</property>
       <property name="appWorkingDir">target/arquillian</property>
     </configuration>