diff --git a/docker/post-boot-commands.asadmin b/docker/post-boot-commands.asadmin index 24fe032cbe721a38c1fad8f66bff3cefbce19a6d..a934ecdb706612e7f81d6f5d919463392636d0ff 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 3f77f5dd0b4c1c3234cb7800da73213d1b5a6669..731da06ef8c1901a6420c3597e8180ad6d279901 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 d0abff1d273ceb289b357595a067db18b9c07d71..7cd76d4c21c9918bdbafa79cca798fadfd484397 100644 --- a/jee/business/pom.xml +++ b/jee/business/pom.xml @@ -16,10 +16,20 @@ <groupId>jakarta.platform</groupId> <artifactId>jakarta.jakartaee-api</artifactId> </dependency> + + <dependency> + <groupId>org.jboss.arquillian.container</groupId> + <artifactId>arquillian-weld-embedded</artifactId> + <version>${arquillian-weld-embedded.version}</version> + <scope>test</scope> + </dependency> <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter</artifactId> + <groupId>org.jboss.weld</groupId> + <artifactId>weld-core-impl</artifactId> + <version>${weld.version}</version> + <scope>test</scope> </dependency> + </dependencies> 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 new file mode 100644 index 0000000000000000000000000000000000000000..71c15de2e13935fd6dde7416f3d29f8eddb2d64d --- /dev/null +++ b/jee/business/src/test/java/fr/univtln/bruno/samples/jee91/ejb/HelloTest.java @@ -0,0 +1,48 @@ +package fr.univtln.bruno.samples.jee91.ejb; + +import fr.univtln.bruno.samples.jee91.ejb.qualifiers.SpokenLanguage; +import jakarta.inject.Inject; +import lombok.extern.java.Log; +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.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +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; + +@ExtendWith(ArquillianExtension.class) +@Log +class HelloTest { + @Inject + Hello hello1; + + @Inject + @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, "META-INF/beans.xml"); + } + + @Test + @DisplayName("Testing Hello in French") + public void shouldInjectHelloBean1() { + assertEquals(hello1.sayHello(), "Salut"); + } + + @Test + @DisplayName("Testing Hello in English") + public void shouldInjectHelloBean2() { + assertEquals(hello2.sayHello(), "Hi"); + } + +} \ No newline at end of file diff --git a/jee/business/src/test/resources/log4j.properties b/jee/business/src/test/resources/log4j.properties new file mode 100644 index 0000000000000000000000000000000000000000..1ec13a326b368e1695dc8052303e50a6c8d400b4 --- /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 10660363196a9c42c2af858f62e564f841c12db4..69b3ba668e26b1468a5deaa16b3ab3e35b5c4cd1 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 0000000000000000000000000000000000000000..968edc384d73356686d1fd3e0f356ce1525b7855 --- /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 0000000000000000000000000000000000000000..efd69bc2d38663ae2f69879265843f8ff04aac04 --- /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 0000000000000000000000000000000000000000..5b486bafe59aae426de356c1c66f099520bf87ea --- /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 0000000000000000000000000000000000000000..36421e4fd8f9ade5a123d6083709c8955a22a7a9 --- /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 0000000000000000000000000000000000000000..bc26cbec1c9e96c7327eff7d24737becf81e1455 --- /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 0000000000000000000000000000000000000000..e804f1e1b573147de09372a76c3614a0cd2cd337 --- /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 0000000000000000000000000000000000000000..067e09a51804235145837c576d98b9f4af2b78d7 --- /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 942e5682adeefde1dfe60075e544bed3b447f415..e0286307feb29f423e025a5c447f628e4ff01f1f 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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 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 75dab8e96c45709abfd94b305504362bfcf67bc5..763677c79b7182ac2a6a7ba47c49b42855387a43 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 7d188464dc239fab1b7379cc19f73e55ebf4ac6f..976c5f51b9de80ca072519efe50477602d5b61b7 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 dd29f03ee2c3631cb3e96f0cb95f64f832b6f429..ed66b555262ca21b12c4bae33cc27cb72c0be7b0 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 a8195afc1b03a13f4234d2791eb157f79c69d729..21b76f6fe22c246aae7cf2129e4a357b738d888d 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 new file mode 100644 index 0000000000000000000000000000000000000000..8869d9d675f2799057a1f8e468de8977c648d408 --- /dev/null +++ b/jee/restApp/src/test/java/fr/univtln/bruno/samples/SampleResourceTest.java @@ -0,0 +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 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 { + + 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/jee/restApp/src/test/java/fr/univtln/bruno/samples/SampleTest.java b/jee/restApp/src/test/java/fr/univtln/bruno/samples/SampleTest.java deleted file mode 100644 index 8725af6410ad9f5a014ed580cb523061a26dc49a..0000000000000000000000000000000000000000 --- a/jee/restApp/src/test/java/fr/univtln/bruno/samples/SampleTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package fr.univtln.bruno.samples; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class SampleTest { - - @Test - public void simpleJUnit5Test() { - String result = "duke"; - assertEquals("duke", result); - } -} diff --git a/pom.xml b/pom.xml index 157cd7daa57632b261d777fad59a6bb8b41dba11..a45662e7e72ca8d276c1ae56a6cd799decb5da99 100644 --- a/pom.xml +++ b/pom.xml @@ -16,34 +16,56 @@ <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> + <!-- 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> <dependencyManagement> <dependencies> + <!-- JEE --> <dependency> <groupId>jakarta.platform</groupId> <artifactId>jakarta.jakartaee-api</artifactId> <version>${jakarta.jakartaee-api.version}</version> <scope>provided</scope> </dependency> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter</artifactId> - <version>${junit-jupiter.version}</version> - <scope>test</scope> - </dependency> + <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.22</version> <scope>compile</scope> </dependency> + <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> @@ -62,6 +84,103 @@ </exclusions> </dependency> + <!-- TEST --> + <dependency> + <groupId>org.junit</groupId> + <artifactId>junit-bom</artifactId> + <version>${junit-jupiter.version}</version> + <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> + <version>1.7.0.Alpha10</version> + <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> + <artifactId>jakarta.ejb-api</artifactId> + </exclusion> + <exclusion> + <groupId>jakarta.transaction</groupId> + <artifactId>jakarta.transaction-api</artifactId> + </exclusion> + </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> + <artifactId>jboss-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.jboss.logging</groupId> + <artifactId>jboss-logging-annotations</artifactId> + <exclusions> + <exclusion> + <groupId>org.jboss.logging</groupId> + <artifactId>jboss-logging</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> </dependencyManagement> @@ -79,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> @@ -97,7 +249,7 @@ <requireMavenVersion> <version>3.8</version> </requireMavenVersion> - <dependencyConvergence/> + <!--dependencyConvergence /--> </rules> </configuration> </execution> @@ -126,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>