From 7c07796bd08cc1791bddba700528ec3bdd666ea1 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno <emmanuel.bruno@univ-tln.fr> Date: Tue, 14 Dec 2021 09:31:26 +0100 Subject: [PATCH] adds payara arquillian tests. --- docker/post-boot-commands.asadmin | 1 - entites/pom.xml | 5 +- jee/business/pom.xml | 20 +- .../resources}/META-INF/beans.xml | 0 .../bruno/samples/jee91/ejb/HelloTest.java | 3 +- .../src/test/resources/log4j.properties | 17 ++ jee/dao/pom.xml | 16 +- .../samples/jee91/dao/it/PersonTest.java | 59 ++++++ jee/dao/src/test/resources/META-INF/beans.xml | 5 + .../test/resources/META-INF/persistence.xml | 14 ++ jee/dao/src/test/resources/arquillian.xml | 21 ++ jee/dao/src/test/resources/insert.sql | 4 + jee/dao/src/test/resources/log4j.properties | 17 ++ jee/dao/src/test/resources/web.xml | 11 + jee/ear/pom.xml | 20 ++ jee/ear/src/main/docker/Dockerfile | 0 .../bruno/jee91/jsf/ViewPersonBean.java | 2 +- jee/jsf/src/main/webapp/index.xhtml | 2 +- jee/pom.xml | 192 ++++++++++++++++++ jee/restApp/pom.xml | 25 +++ .../bruno/samples/SampleResourceTest.java | 71 ++++++- pom.xml | 138 ++++++++++++- 22 files changed, 598 insertions(+), 45 deletions(-) rename jee/business/src/{test/java => main/resources}/META-INF/beans.xml (100%) create mode 100644 jee/business/src/test/resources/log4j.properties create mode 100644 jee/dao/src/test/java/fr/univtln/bruno/samples/jee91/dao/it/PersonTest.java create mode 100644 jee/dao/src/test/resources/META-INF/beans.xml create mode 100644 jee/dao/src/test/resources/META-INF/persistence.xml create mode 100644 jee/dao/src/test/resources/arquillian.xml create mode 100644 jee/dao/src/test/resources/insert.sql create mode 100644 jee/dao/src/test/resources/log4j.properties create mode 100644 jee/dao/src/test/resources/web.xml create mode 100644 jee/ear/src/main/docker/Dockerfile diff --git a/docker/post-boot-commands.asadmin b/docker/post-boot-commands.asadmin index 24fe032..a934ecd 100755 --- a/docker/post-boot-commands.asadmin +++ b/docker/post-boot-commands.asadmin @@ -2,7 +2,6 @@ set-hazelcast-configuration --enabled=true --dynamic=true add-library /tmp/h2.jar create-jdbc-connection-pool --datasourceclassname org.h2.jdbcx.JdbcDataSource --restype javax.sql.ConnectionPoolDataSource --property password=password:user=user:url="jdbc:h2:tcp://db:9092/payara;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE" My-H2-pool -#create-jdbc-connection-pool --datasourceclassname org.h2.jdbcx.JdbcDataSource --restype javax.sql.ConnectionPoolDataSource --property password=password:user=user:url="jdbc:h2:tcp://db:9092/payara;MODE=PostgreSQL" My-H2-pool create-jdbc-resource --connectionpoolid My-H2-pool jdbc/my-h2-pool # set configs.config.server-config.network-config.protocols.protocol.http-listener-2.ssl.cert-nickname=mycert diff --git a/entites/pom.xml b/entites/pom.xml index 3f77f5d..731da06 100644 --- a/entites/pom.xml +++ b/entites/pom.xml @@ -22,8 +22,9 @@ </dependency> <dependency> - <groupId>com.fasterxml.jackson.jakarta.rs</groupId> - <artifactId>jackson-jakarta-rs-json-provider</artifactId> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-annotations</artifactId> + <version>2.13.0</version> </dependency> </dependencies> diff --git a/jee/business/pom.xml b/jee/business/pom.xml index c3e9b80..7cd76d4 100644 --- a/jee/business/pom.xml +++ b/jee/business/pom.xml @@ -12,29 +12,11 @@ <packaging>ejb</packaging> <dependencies> - <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - </dependency> - <dependency> <groupId>jakarta.platform</groupId> <artifactId>jakarta.jakartaee-api</artifactId> </dependency> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter</artifactId> - </dependency> - <dependency> - <groupId>org.jboss.arquillian.junit5</groupId> - <artifactId>arquillian-junit5-container</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.jboss.arquillian.protocol</groupId> - <artifactId>arquillian-protocol-servlet-jakarta</artifactId> - <scope>test</scope> - </dependency> + <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-weld-embedded</artifactId> diff --git a/jee/business/src/test/java/META-INF/beans.xml b/jee/business/src/main/resources/META-INF/beans.xml similarity index 100% rename from jee/business/src/test/java/META-INF/beans.xml rename to jee/business/src/main/resources/META-INF/beans.xml diff --git a/jee/business/src/test/java/fr/univtln/bruno/samples/jee91/ejb/HelloTest.java b/jee/business/src/test/java/fr/univtln/bruno/samples/jee91/ejb/HelloTest.java index a0ef3db..71c15de 100644 --- a/jee/business/src/test/java/fr/univtln/bruno/samples/jee91/ejb/HelloTest.java +++ b/jee/business/src/test/java/fr/univtln/bruno/samples/jee91/ejb/HelloTest.java @@ -24,12 +24,13 @@ class HelloTest { @SpokenLanguage(SpokenLanguage.Language.ENGLISH) Hello hello2; + @SuppressWarnings("unused") @Deployment public static JavaArchive createDeployment() { return ShrinkWrap.create(JavaArchive.class) .addClass(HelloBean1.class) .addClass(HelloBean2.class) - .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); + .addAsManifestResource(EmptyAsset.INSTANCE, "META-INF/beans.xml"); } @Test diff --git a/jee/business/src/test/resources/log4j.properties b/jee/business/src/test/resources/log4j.properties new file mode 100644 index 0000000..1ec13a3 --- /dev/null +++ b/jee/business/src/test/resources/log4j.properties @@ -0,0 +1,17 @@ +log4j.rootLogger=info, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=test-jee.business.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n \ No newline at end of file diff --git a/jee/dao/pom.xml b/jee/dao/pom.xml index 1066036..69b3ba6 100644 --- a/jee/dao/pom.xml +++ b/jee/dao/pom.xml @@ -11,15 +11,23 @@ <artifactId>dao</artifactId> <dependencies> - <dependency> - <groupId>jakarta.platform</groupId> - <artifactId>jakarta.jakartaee-api</artifactId> - </dependency> <dependency> <groupId>fr.univtln.bruno.samples.jee91</groupId> <artifactId>entites</artifactId> <version>1.0-SNAPSHOT</version> </dependency> + + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>1.4.200</version> + <scope>test</scope> + </dependency> </dependencies> + + + + + </project> \ No newline at end of file diff --git a/jee/dao/src/test/java/fr/univtln/bruno/samples/jee91/dao/it/PersonTest.java b/jee/dao/src/test/java/fr/univtln/bruno/samples/jee91/dao/it/PersonTest.java new file mode 100644 index 0000000..968edc3 --- /dev/null +++ b/jee/dao/src/test/java/fr/univtln/bruno/samples/jee91/dao/it/PersonTest.java @@ -0,0 +1,59 @@ +package fr.univtln.bruno.samples.jee91.dao.it; + +import fr.univtln.bruno.samples.jee91.dao.PersonDAO; +import jakarta.inject.Inject; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; +import jakarta.transaction.UserTransaction; +import lombok.extern.slf4j.Slf4j; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.Maven; +import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(ArquillianExtension.class) +@Slf4j +class PersonTest { + + @Inject + PersonDAO personDAO; + + @Inject + UserTransaction utx; + @PersistenceContext(unitName = "myappPU") + private EntityManager em; + + @Deployment + public static WebArchive createDeployment() { + PomEquippedResolveStage pomFile = Maven.resolver().loadPomFromFile("pom.xml"); + + /*File[] libs = Maven.configureResolver().loadPomFromFile("pom.xml") + .importRuntimeAndTestDependencies().resolve() + .withTransitivity().asFile();*/ + + return ShrinkWrap.create(WebArchive.class, "arquilian-dao-test.war") + .addPackage(PersonDAO.class.getPackage()) + .addPackage(fr.univtln.bruno.samples.jee91.dao.entitymanagersproducers.H2Database.class.getPackage()) + .addAsLibraries(pomFile.resolve("org.slf4j:slf4j-log4j12:1.7.32").withTransitivity().asFile()) + .addAsLibraries(pomFile.resolve("com.fasterxml.jackson.core:jackson-databind:2.13.0").withTransitivity().asFile()) + .addAsWebInfResource("web.xml") + .addAsResource("insert.sql") + .addAsResource("META-INF/beans.xml", "META-INF/beans.xml") + .addAsResource("META-INF/persistence.xml", "META-INF/persistence.xml"); +// .addAsLibraries(libs); + + + } + + @Test + @DisplayName("Testing Person findall") + public void shouldInjectHelloBean1() { + log.info(personDAO.findAll().toString()); + } + +} \ No newline at end of file diff --git a/jee/dao/src/test/resources/META-INF/beans.xml b/jee/dao/src/test/resources/META-INF/beans.xml new file mode 100644 index 0000000..efd69bc --- /dev/null +++ b/jee/dao/src/test/resources/META-INF/beans.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd" + bean-discovery-mode="all"> +</beans> \ No newline at end of file diff --git a/jee/dao/src/test/resources/META-INF/persistence.xml b/jee/dao/src/test/resources/META-INF/persistence.xml new file mode 100644 index 0000000..5b486ba --- /dev/null +++ b/jee/dao/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<persistence xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd" + version="3.0"> + <persistence-unit name="myappPU" transaction-type="JTA"> + <jta-data-source>java:global/datasource</jta-data-source> + + <!--class>fr.univtln.bruno.samples.jee91.dao.Person</class--> + <properties> + <property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create" /> + <property name="jakarta.persistence.sql-load-script-source" value="insert.sql" /> + </properties> + </persistence-unit> +</persistence> \ No newline at end of file diff --git a/jee/dao/src/test/resources/arquillian.xml b/jee/dao/src/test/resources/arquillian.xml new file mode 100644 index 0000000..36421e4 --- /dev/null +++ b/jee/dao/src/test/resources/arquillian.xml @@ -0,0 +1,21 @@ +<arquillian + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns="http://jboss.org/schema/arquillian" + xsi:schemaLocation="http://jboss.org/schema/arquillian https://jboss.org/schema/arquillian/arquillian_1_0.xsd"> + <!-- <defaultProtocol type="Servlet 5.0"/>--> + + <!--engine> + <property name="deploymentExportPath">target/</property> + </engine--> + + <container qualifier="payara-managed"> + <configuration> + <property name="allowConnectingToRunningServer">false</property> + <property name="adminHost">localhost</property> + <property name="adminPort">4848</property> + <property name="enableH2">${enableH2:false}</property> + <property name="outputToConsole">true</property> + </configuration> + </container> + +</arquillian> \ No newline at end of file diff --git a/jee/dao/src/test/resources/insert.sql b/jee/dao/src/test/resources/insert.sql new file mode 100644 index 0000000..bc26cbe --- /dev/null +++ b/jee/dao/src/test/resources/insert.sql @@ -0,0 +1,4 @@ +INSERT INTO "public"."person" ("name", "uuid") VALUES ('Yves', 'ACED00057372000E6A6176612E7574696C2E55554944BC9903F7986D852F0200024A000C6C65617374536967426974734A000B6D6F7374536967426974737870B25A000916801FE374FCFAC5DCF94C11'); +INSERT INTO "public"."person" ("name", "uuid") VALUES ('Pierre', 'ACED00057372000E6A6176612E7574696C2E55554944BC9903F7986D852F0200024A000C6C65617374536967426974734A000B6D6F7374536967426974737870B8F28F7D3945291756DAC7325DF44938'); +INSERT INTO "public"."person" ("name", "uuid") VALUES ('Marie', 'ACED00057372000E6A6176612E7574696C2E55554944BC9903F7986D852F0200024A000C6C65617374536967426974734A000B6D6F73745369674269747378709AA3211A9B897403843C82366C6B450E'); +INSERT INTO "public"."person" ("name", "uuid") VALUES ('Jeanne', 'ACED00057372000E6A6176612E7574696C2E55554944BC9903F7986D852F0200024A000C6C65617374536967426974734A000B6D6F7374536967426974737870BC1580AEB48C0F0C0B3C82E884AA4C3C'); diff --git a/jee/dao/src/test/resources/log4j.properties b/jee/dao/src/test/resources/log4j.properties new file mode 100644 index 0000000..e804f1e --- /dev/null +++ b/jee/dao/src/test/resources/log4j.properties @@ -0,0 +1,17 @@ +log4j.rootLogger=info, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=test-jee.dao.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n \ No newline at end of file diff --git a/jee/dao/src/test/resources/web.xml b/jee/dao/src/test/resources/web.xml new file mode 100644 index 0000000..067e09a --- /dev/null +++ b/jee/dao/src/test/resources/web.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd" + version="5.0"> + <data-source> + <name>java:global/datasource</name> + <class-name>org.h2.jdbcx.JdbcDataSource</class-name> + <url>jdbc:h2:mem:test;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE</url> + <!--url>jdbc:h2:mem:test;MODE=PostgreSQL</url--> + </data-source> +</web-app> \ No newline at end of file diff --git a/jee/ear/pom.xml b/jee/ear/pom.xml index 942e568..e028630 100644 --- a/jee/ear/pom.xml +++ b/jee/ear/pom.xml @@ -53,6 +53,17 @@ <version>1.0-SNAPSHOT</version> </dependency> + <dependency> + <groupId>fish.payara.arquillian</groupId> + <artifactId>arquillian-payara-server-embedded</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>fish.payara.extras</groupId> + <artifactId>payara-embedded-all</artifactId> + <scope>test</scope> + </dependency> + </dependencies> <build> @@ -98,6 +109,15 @@ </modules> </configuration> </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + + </configuration> + </plugin> + </plugins> </build> diff --git a/jee/ear/src/main/docker/Dockerfile b/jee/ear/src/main/docker/Dockerfile new file mode 100644 index 0000000..e69de29 diff --git a/jee/jsf/src/main/java/fr/univtln/bruno/jee91/jsf/ViewPersonBean.java b/jee/jsf/src/main/java/fr/univtln/bruno/jee91/jsf/ViewPersonBean.java index 75dab8e..763677c 100644 --- a/jee/jsf/src/main/java/fr/univtln/bruno/jee91/jsf/ViewPersonBean.java +++ b/jee/jsf/src/main/java/fr/univtln/bruno/jee91/jsf/ViewPersonBean.java @@ -15,7 +15,7 @@ public class ViewPersonBean { @Inject PersonDAO personDAO; - private final String message = "Hello"; + private final String message = "Hello 1"; public String getMessage() { return this.message; diff --git a/jee/jsf/src/main/webapp/index.xhtml b/jee/jsf/src/main/webapp/index.xhtml index 7d18846..976c5f5 100644 --- a/jee/jsf/src/main/webapp/index.xhtml +++ b/jee/jsf/src/main/webapp/index.xhtml @@ -6,7 +6,7 @@ xml:lang="en"> <h:head> - <title>Person list</title> + <title>A Person list</title> </h:head> <h:body> diff --git a/jee/pom.xml b/jee/pom.xml index dd29f03..ed66b55 100644 --- a/jee/pom.xml +++ b/jee/pom.xml @@ -31,6 +31,198 @@ <artifactId>jakarta.jakartaee-api</artifactId> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </dependency> + + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.junit5</groupId> + <artifactId>arquillian-junit5-container</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.protocol</groupId> + <artifactId>arquillian-protocol-servlet-jakarta</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.shrinkwrap.resolver</groupId> + <artifactId>shrinkwrap-resolver-depchain</artifactId> + <scope>test</scope> + <type>pom</type> + </dependency> + <dependency> + <groupId>fish.payara.arquillian</groupId> + <artifactId>payara-client-ee9</artifactId> + <version>${arquillian-payara.version}</version> + <scope>test</scope> + </dependency> + + </dependencies> + <profiles> + <profile> + <id>arq-payara-micro</id> + <dependencies> + <dependency> + <groupId>fish.payara.arquillian</groupId> + <artifactId>arquillian-payara-micro-managed</artifactId> + <version>${arquillian-payara.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>unpack</id> + <phase>pre-integration-test</phase> + <goals> + <goal>copy</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>fish.payara.extras</groupId> + <artifactId>payara-micro</artifactId> + <version>${payara.version}</version> + <type>jar</type> + <overWrite>false</overWrite> + <outputDirectory>${project.build.directory}</outputDirectory> + <destFileName>payara-micro.jar</destFileName> + </artifactItem> + </artifactItems> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <configuration> + <systemPropertyVariables> + <payara.microJar>${project.build.directory}/payara-micro.jar</payara.microJar> + </systemPropertyVariables> + + </configuration> + </plugin> + </plugins> + </build> + </profile> + + <profile> + + <activation> + <activeByDefault>true</activeByDefault> + </activation> + + <id>arq-payara-managed</id> + <dependencies> + <dependency> + <groupId>fish.payara.arquillian</groupId> + <artifactId>arquillian-payara-server-managed</artifactId> + <version>${arquillian-payara.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>3.1.2</version> + <executions> + <execution> + <id>unpack</id> + <phase>pre-integration-test</phase> + <goals> + <goal>unpack</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>fish.payara.distributions</groupId> + <artifactId>payara</artifactId> + <version>${payara.version}</version> + <type>zip</type> + <overWrite>false</overWrite> + <outputDirectory>${project.build.directory}</outputDirectory> + </artifactItem> + </artifactItems> + </configuration> + </execution> + <execution> + <id>copy-h2-1</id> + <phase>pre-integration-test</phase> + <goals> + <goal>copy</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>${h2.version}</version> + <type>jar</type> + <overWrite>true</overWrite> + <outputDirectory>${project.build.directory}/payara6/glassfish/h2db/bin/</outputDirectory> + <destFileName>h2.jar</destFileName> + </artifactItem> + </artifactItems> + </configuration> + </execution> + <execution> + <id>copy-h2-2</id> + <phase>pre-integration-test</phase> + <goals> + <goal>copy</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>${h2.version}</version> + <type>jar</type> + <overWrite>true</overWrite> + <outputDirectory>${project.build.directory}/payara6/h2db/bin/</outputDirectory> + <destFileName>h2.jar</destFileName> + </artifactItem> + </artifactItems> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <configuration> + <systemPropertyVariables> + <payara.home>${project.build.directory}/payara6</payara.home> + <arquillian.launch>payara-managed</arquillian.launch> + </systemPropertyVariables> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> + </project> \ No newline at end of file diff --git a/jee/restApp/pom.xml b/jee/restApp/pom.xml index a8195af..21b76f6 100644 --- a/jee/restApp/pom.xml +++ b/jee/restApp/pom.xml @@ -30,11 +30,36 @@ <groupId>jakarta.platform</groupId> <artifactId>jakarta.jakartaee-api</artifactId> </dependency> + <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.junit5</groupId> + <artifactId>arquillian-junit5-container</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.protocol</groupId> + <artifactId>arquillian-protocol-servlet-jakarta</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.glassfish.jersey.core</groupId> + <artifactId>jersey-client</artifactId> + <version>3.0.3</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.jakarta.rs</groupId> + <artifactId>jackson-jakarta-rs-json-provider</artifactId> + </dependency> </dependencies> <build> diff --git a/jee/restApp/src/test/java/fr/univtln/bruno/samples/SampleResourceTest.java b/jee/restApp/src/test/java/fr/univtln/bruno/samples/SampleResourceTest.java index a529149..8869d9d 100644 --- a/jee/restApp/src/test/java/fr/univtln/bruno/samples/SampleResourceTest.java +++ b/jee/restApp/src/test/java/fr/univtln/bruno/samples/SampleResourceTest.java @@ -1,14 +1,73 @@ package fr.univtln.bruno.samples; +import fr.univtln.bruno.samples.jee91.ejb.Hello; +import fr.univtln.bruno.samples.jee91.ejb.HelloBean1; +import fr.univtln.bruno.samples.jee91.ejb.HelloBean2; +import fr.univtln.bruno.samples.jee91.rs.JAXRSConfiguration; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import lombok.extern.java.Log; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit5.ArquillianExtension; +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.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -import static org.junit.jupiter.api.Assertions.assertEquals; +import java.net.MalformedURLException; +import java.net.URL; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +@ExtendWith(ArquillianExtension.class) +@Log public class SampleResourceTest { - @Test - public void simpleJUnit5Test() { - String result = "duke"; - assertEquals("duke", result); - } + private Client client; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class) + .addClass(Hello.class) + .addClasses(HelloBean1.class, HelloBean2.class) + .addClasses(SampleResourceTest.class, JAXRSConfiguration.class) + // Enable CDI + .addAsWebInfResource(EmptyAsset.INSTANCE, "META-INF/beans.xml"); + } + + @BeforeEach + public void setup() { + this.client = ClientBuilder.newClient(); + } + + @AfterEach + public void teardown() { + if (this.client != null) { + this.client.close(); + } + } + + @Test + @DisplayName("Check that SampleResource says 'hello'") + @RunAsClient + public void shouldSayHello(@ArquillianResource URL base) throws MalformedURLException { + final WebTarget sampleResourceTarget = client.target(new URL(base, "sample").toExternalForm()); + try (final Response sampleResourceGetResponse = sampleResourceTarget.request() + .accept(MediaType.APPLICATION_JSON) + .get()) { + assertThat(sampleResourceGetResponse.getStatus(), is(equalTo(200))); + assertThat(sampleResourceGetResponse.readEntity(String.class), equalTo("Hello")); + } + } } diff --git a/pom.xml b/pom.xml index b45f21f..a45662e 100644 --- a/pom.xml +++ b/pom.xml @@ -16,15 +16,35 @@ <properties> - <maven.compiler.source>11</maven.compiler.source> - <maven.compiler.target>11</maven.compiler.target> - - <jakarta.jakartaee-api.version>9.0.0</jakarta.jakartaee-api.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <maven.compiler.release>11</maven.compiler.release> + + <!-- The default value is changed to `false` since maven-war-plugin 3.0.0 --> + <failOnMissingWebXml>false</failOnMissingWebXml> + + <!-- Cargo maven plugin to deploy apps to Glassfish/Payara servers --> + <cargo-maven3-plugin.version>1.9.8</cargo-maven3-plugin.version> + + <!-- Jakarta EE API 9.1.0 with Java 11 --> + <jakarta.jakartaee-api.version>9.1.0</jakarta.jakartaee-api.version> + + <h2.version>1.4.200</h2.version> + + <!-- Arquillian 1.7.0 adds Jakarta EE 9 and JUnit 5 support--> + <arquillian-bom.version>1.7.0.Alpha10</arquillian-bom.version> <junit-jupiter.version>5.8.2</junit-jupiter.version> - <arquillian-weld-embedded.version>3.0.0.Final</arquillian-weld-embedded.version> + <!-- Tests --> + <mockito.version>4.1.0</mockito.version> + <hamcrest.version>2.2</hamcrest.version> + + <!-- Payara server --> + <payara.version>6.2021.1.Alpha1</payara.version> + <arquillian-payara.version>3.0.alpha2</arquillian-payara.version> + + <!-- Weld for embedded CDI --> + <arquillian-weld-embedded.version>3.0.2.Final</arquillian-weld-embedded.version> <weld.version>4.0.2.Final</weld.version> </properties> @@ -72,6 +92,27 @@ <type>pom</type> <scope>import</scope> </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-library</artifactId> + <version>${hamcrest.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>${mockito.version}</version> + <scope>test</scope> + </dependency> + <!-- Override dependency resolver with latest version. + This must go *BEFORE* the Arquillian BOM. --> + <!--dependency> + <groupId>org.jboss.shrinkwrap.resolver</groupId> + <artifactId>shrinkwrap-resolver-bom</artifactId> + <version>3.1.4</version> + <scope>import</scope> + <type>pom</type> + </dependency--> <dependency> <groupId>org.jboss.arquillian</groupId> <artifactId>arquillian-bom</artifactId> @@ -79,10 +120,22 @@ <scope>import</scope> <type>pom</type> </dependency> - + <dependency> + <groupId>fish.payara.arquillian</groupId> + <artifactId>arquillian-payara-server-embedded</artifactId> + <version>2.4.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>fish.payara.extras</groupId> + <artifactId>payara-embedded-all</artifactId> + <version>${payara.version}</version> + <scope>test</scope> + </dependency> <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-weld-embedded</artifactId> + <version>weld.version</version> <exclusions> <exclusion> <groupId>jakarta.ejb</groupId> @@ -95,9 +148,21 @@ </exclusions> </dependency> + <dependency> + <groupId>org.jboss.logging</groupId> + <artifactId>jboss-logging</artifactId> + <version>3.4.2.Final</version> + <exclusions> + <exclusion> + <artifactId>log4j</artifactId> + <groupId>log4j</groupId> + </exclusion> + </exclusions> + </dependency> <dependency> <groupId>org.jboss.logging</groupId> <artifactId>jboss-logging-processor</artifactId> + <version>3.4.2.Final</version> <exclusions> <exclusion> <groupId>org.jboss.logging</groupId> @@ -133,9 +198,42 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> - <version>2.22.2</version> + <version>3.0.0-M4</version> + <executions> + <execution> + <id>default-test</id> + <phase>test</phase> + <goals> + <goal>test</goal> + </goals> + <configuration> + <excludes> + <exclude>**/it/**</exclude> + </excludes> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <version>3.0.0-M4</version> + <executions> + <execution> + <id>integration-test</id> + <phase>integration-test</phase> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + <configuration> + <includes> + <include>**/it/**</include> + </includes> + </configuration> + </execution> + </executions> </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> @@ -151,7 +249,7 @@ <requireMavenVersion> <version>3.8</version> </requireMavenVersion> - <dependencyConvergence/> + <!--dependencyConvergence /--> </rules> </configuration> </execution> @@ -180,4 +278,24 @@ </plugins> </pluginManagement> </build> -</project> \ No newline at end of file + + <repositories> + <repository> + <id>sonatype-nexus-staging</id> + <name>Sonatype Nexus Staging</name> + <url>https://jakarta.oss.sonatype.org/content/repositories/staging/</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + </repository> + <repository> + <id>payara-nexus</id> + <name>Payara Nexus Artifacts</name> + <url>https://nexus.payara.fish/repository/payara-artifacts/</url> + </repository> + </repositories> + +</project> -- GitLab