This is an automated email from the ASF dual-hosted git repository.

jlmonteiro pushed a commit to branch javax-to-jakarta-on-deploy
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 06b7428a7742dede926f6ef47fc1bf8308ad7844
Author: Jean-Louis Monteiro <[email protected]>
AuthorDate: Thu Oct 20 17:18:45 2022 +0200

    Small sample showing how to use arquillian and Jakarta APIs to test javax 
applications deployed in TomEE
---
 examples/javax-to-jakarta-namespace/pom.xml        | 113 +++++++++++++++++++++
 .../src/main/java/org/superbiz/movie/Api.java      |  24 +++++
 .../src/main/java/org/superbiz/movie/Movie.java    |  77 ++++++++++++++
 .../main/java/org/superbiz/movie/MovieService.java |  60 +++++++++++
 .../java/org/superbiz/movie/MovieServiceTest.java  |  79 ++++++++++++++
 .../src/test/resources/arquillian.xml              |  33 ++++++
 6 files changed, 386 insertions(+)

diff --git a/examples/javax-to-jakarta-namespace/pom.xml 
b/examples/javax-to-jakarta-namespace/pom.xml
new file mode 100644
index 0000000000..b6c116c6f9
--- /dev/null
+++ b/examples/javax-to-jakarta-namespace/pom.xml
@@ -0,0 +1,113 @@
+<?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/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.superbiz</groupId>
+  <artifactId>serverless-javax-tomee-plume</artifactId>
+  <version>9.0.0-M9-SNAPSHOT</version>
+
+  <name>TomEE :: Examples :: javax to jakarta namespace</name>
+  
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <version.tomee>9.0.0-M9-SNAPSHOT</version.tomee>
+    <version.shrinkwrap.resolver>2.0.0</version.shrinkwrap.resolver>
+  </properties>
+  <dependencyManagement>
+    <dependencies>
+      <!-- Override dependency resolver with test version. This must go 
*BEFORE*
+        the Arquillian BOM. -->
+      <dependency>
+        <groupId>org.jboss.shrinkwrap.resolver</groupId>
+        <artifactId>shrinkwrap-resolver-bom</artifactId>
+        <version>${version.shrinkwrap.resolver}</version>
+        <scope>import</scope>
+        <type>pom</type>
+      </dependency>
+      <!-- Now pull in our server-based unit testing framework -->
+      <dependency>
+        <groupId>org.jboss.arquillian</groupId>
+        <artifactId>arquillian-bom</artifactId>
+        <version>1.7.0.Alpha10</version>
+        <scope>import</scope>
+        <type>pom</type>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.tomee</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>8.0-6</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.tomee.bom</groupId>
+      <artifactId>tomee-plume-api</artifactId>
+      <version>${version.tomee}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.arquillian.junit</groupId>
+      <artifactId>arquillian-junit-container</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomee</groupId>
+      <artifactId>arquillian-tomee-remote</artifactId>
+      <version>${version.tomee}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.13.2</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.5.1</version>
+        <configuration>
+          <source>1.8</source>
+          <target>1.8</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <!--
+  This section allows you to configure where to publish libraries for sharing.
+  It is not required and may be deleted.  For more information see:
+  http://maven.apache.org/plugins/maven-deploy-plugin/
+  -->
+  <distributionManagement>
+    <repository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/repo/</url>
+    </repository>
+    <snapshotRepository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/snapshot-repo/</url>
+    </snapshotRepository>
+  </distributionManagement>
+</project>
diff --git 
a/examples/javax-to-jakarta-namespace/src/main/java/org/superbiz/movie/Api.java 
b/examples/javax-to-jakarta-namespace/src/main/java/org/superbiz/movie/Api.java
new file mode 100644
index 0000000000..a7c43d3166
--- /dev/null
+++ 
b/examples/javax-to-jakarta-namespace/src/main/java/org/superbiz/movie/Api.java
@@ -0,0 +1,24 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.movie;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+@ApplicationPath("/api")
+public class Api extends Application {
+}
diff --git 
a/examples/javax-to-jakarta-namespace/src/main/java/org/superbiz/movie/Movie.java
 
b/examples/javax-to-jakarta-namespace/src/main/java/org/superbiz/movie/Movie.java
new file mode 100644
index 0000000000..450959b698
--- /dev/null
+++ 
b/examples/javax-to-jakarta-namespace/src/main/java/org/superbiz/movie/Movie.java
@@ -0,0 +1,77 @@
+/*
+ * 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.movie;
+
+public class Movie {
+
+    private String title;
+    private String director;
+    private String genre;
+    private int id;
+    private int year;
+
+    public Movie() {
+    }
+
+    public Movie(final String title, final String director, final String 
genre, final int id, final int year) {
+        this.title = title;
+        this.director = director;
+        this.genre = genre;
+        this.id = id;
+        this.year = year;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(final String title) {
+        this.title = title;
+    }
+
+    public String getDirector() {
+        return director;
+    }
+
+    public void setDirector(final String director) {
+        this.director = director;
+    }
+
+    public String getGenre() {
+        return genre;
+    }
+
+    public void setGenre(final String genre) {
+        this.genre = genre;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(final int id) {
+        this.id = id;
+    }
+
+    public int getYear() {
+        return year;
+    }
+
+    public void setYear(final int year) {
+        this.year = year;
+    }
+}
diff --git 
a/examples/javax-to-jakarta-namespace/src/main/java/org/superbiz/movie/MovieService.java
 
b/examples/javax-to-jakarta-namespace/src/main/java/org/superbiz/movie/MovieService.java
new file mode 100644
index 0000000000..b8acbc28b3
--- /dev/null
+++ 
b/examples/javax-to-jakarta-namespace/src/main/java/org/superbiz/movie/MovieService.java
@@ -0,0 +1,60 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.movie;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.RequestScoped;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+@Path("/movies")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+@RequestScoped
+public class MovieService {
+
+    private Map<Integer, Movie> store = new ConcurrentHashMap<>();
+
+    @PostConstruct
+    public void construct(){
+        this.addMovie(new Movie("Wedding Crashers", "David Dobkin", "Comedy", 
1, 2005));
+        this.addMovie(new Movie("Starsky & Hutch", "Todd Phillips", "Action", 
2, 2004));
+        this.addMovie(new Movie("Shanghai Knights", "David Dobkin", "Action", 
3, 2003));
+        this.addMovie(new Movie("I-Spy", "Betty Thomas", "Adventure", 4, 
2002));
+        this.addMovie(new Movie("The Royal Tenenbaums", "Wes Anderson", 
"Comedy", 5, 2001));
+        this.addMovie(new Movie("Zoolander", "Ben Stiller", "Comedy", 6, 
2001));
+    }
+    @GET
+    public List<Movie> getAllMovies() {
+        return new ArrayList<>(store.values());
+    }
+
+    @POST
+    public Movie addMovie(final Movie newMovie) {
+        store.put(newMovie.getId(), newMovie);
+        return newMovie;
+    }
+
+}
diff --git 
a/examples/javax-to-jakarta-namespace/src/test/java/org/superbiz/movie/MovieServiceTest.java
 
b/examples/javax-to-jakarta-namespace/src/test/java/org/superbiz/movie/MovieServiceTest.java
new file mode 100644
index 0000000000..1f4d96948c
--- /dev/null
+++ 
b/examples/javax-to-jakarta-namespace/src/test/java/org/superbiz/movie/MovieServiceTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.movie;
+
+import jakarta.ws.rs.client.ClientBuilder;
+import jakarta.ws.rs.client.WebTarget;
+import jakarta.ws.rs.core.MediaType;
+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.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.net.URL;
+
+import static jakarta.ws.rs.client.Entity.entity;
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Arquillian.class)
+public class MovieServiceTest {
+
+    @Deployment
+    public static WebArchive createDeployment() {
+        return ShrinkWrap.create(WebArchive.class, "test.war")
+                         .addClasses(Movie.class, Api.class, Movie.class, 
MovieService.class);
+    }
+
+    @ArquillianResource
+    private URL baseSercerUrl;
+
+    @Test
+    public void getAllMovies() {
+        final WebTarget target = 
ClientBuilder.newClient().target(baseSercerUrl.toExternalForm());
+
+        final Movie[] movies = 
target.path("/api/movies").request().get(Movie[].class);
+
+        assertEquals(6, movies.length);
+
+        final Movie movie = movies[1];
+        assertEquals("Todd Phillips", movie.getDirector());
+        assertEquals("Starsky & Hutch", movie.getTitle());
+        assertEquals("Action", movie.getGenre());
+        assertEquals(2004, movie.getYear());
+        assertEquals(2, movie.getId());
+    }
+
+    @Test
+    public void addMovie() {
+        final WebTarget target = 
ClientBuilder.newClient().target(baseSercerUrl.toExternalForm());
+
+        final Movie movie = new Movie("Shanghai Noon", "Tom Dey", "Comedy", 7, 
2000);
+
+        final Movie posted = target.path("/api/movies").request()
+                .post(entity(movie, MediaType.APPLICATION_JSON))
+                .readEntity(Movie.class);
+
+        assertEquals("Tom Dey", posted.getDirector());
+        assertEquals("Shanghai Noon", posted.getTitle());
+        assertEquals("Comedy", posted.getGenre());
+        assertEquals(2000, posted.getYear());
+        assertEquals(7, posted.getId());
+    }
+}
diff --git 
a/examples/javax-to-jakarta-namespace/src/test/resources/arquillian.xml 
b/examples/javax-to-jakarta-namespace/src/test/resources/arquillian.xml
new file mode 100644
index 0000000000..208fd68569
--- /dev/null
+++ b/examples/javax-to-jakarta-namespace/src/test/resources/arquillian.xml
@@ -0,0 +1,33 @@
+<?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="debug">false</property>
+      <property name="convertFromJavax">true</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

Reply via email to