From 0886b497ea4343dd5b238c21bcfb62fa9f55edc9 Mon Sep 17 00:00:00 2001 From: WolfgangHG Date: Sun, 27 Apr 2025 19:27:23 +0200 Subject: [PATCH 1/2] EAR: add a profile for provisioning the server --- .github/workflows/maven.yml | 7 + pom.xml | 12 ++ wildfly-jakartaee-ear-archetype/README.adoc | 14 +- wildfly-jakartaee-ear-archetype/pom.xml | 3 +- .../archetype-resources/pom.xml | 120 ++++++++++++++++++ .../META-INF/maven/archetype-metadata.xml | 13 ++ .../resources/archetype-resources/README.txt | 71 +++++++++-- .../integration-tests/pom.xml | 83 ++++++++++++ .../src/test/java/test/SampleIT.java | 20 +-- .../src/test/resources/arquillian.xml | 9 ++ .../testing/.gitignore | 2 + .../testing/runtest_managed.bat | 2 +- .../testing/runtest_managed.sh | 2 +- .../testing/runtest_provision.bat | 44 +++++++ .../testing/runtest_provision.sh | 45 +++++++ .../testing/runtest_provisioned.bat | 51 ++++++++ .../testing/runtest_provisioned.sh | 52 ++++++++ .../testing/runtest_remote.bat | 2 +- .../testing/runtest_remote.sh | 2 +- 19 files changed, 516 insertions(+), 38 deletions(-) create mode 100644 wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/integration-tests/pom.xml rename wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/{web => integration-tests}/src/test/java/test/SampleIT.java (58%) rename wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/{web => integration-tests}/src/test/resources/arquillian.xml (79%) create mode 100644 wildfly-jakartaee-ear-archetype/testing/runtest_provision.bat create mode 100755 wildfly-jakartaee-ear-archetype/testing/runtest_provision.sh create mode 100644 wildfly-jakartaee-ear-archetype/testing/runtest_provisioned.bat create mode 100755 wildfly-jakartaee-ear-archetype/testing/runtest_provisioned.sh diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 4bed7fba..01ff0300 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -64,9 +64,16 @@ jobs: echo "* Jakarta EE EAR Archetype" >> $GITHUB_STEP_SUMMARY cd wildfly-jakartaee-ear-archetype/testing + + ./runtest_provision.sh $ARCHETYPE_VERSION + echo " * :white_check_mark: Provisioned Server" >> $GITHUB_STEP_SUMMARY + ./runtest_managed.sh $ARCHETYPE_VERSION echo " * :white_check_mark: Managed Tests" >> $GITHUB_STEP_SUMMARY + ./runtest_provisioned.sh $ARCHETYPE_VERSION + echo " * :white_check_mark: Provisioned Tests" >> $GITHUB_STEP_SUMMARY + $JBOSS_HOME/bin/standalone.sh & until `$JBOSS_HOME/bin/jboss-cli.sh -c ":read-attribute(name=server-state)" 2> /dev/null | grep -q running`; do sleep 1 diff --git a/pom.xml b/pom.xml index 8fdd90bf..d8668e29 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,8 @@ 3.2.1 3.2.0 3.4.1 + 3.4.2 + 3.1.4 17 @@ -161,6 +163,16 @@ maven-antrun-plugin ${version.antrun.plugin} + + org.apache.maven.plugins + maven-jar-plugin + ${version.jar.plugin} + + + org.apache.maven.plugins + maven-install-plugin + ${version.install.plugin} + org.apache.maven.plugins diff --git a/wildfly-jakartaee-ear-archetype/README.adoc b/wildfly-jakartaee-ear-archetype/README.adoc index 52d175a7..313cff5f 100644 --- a/wildfly-jakartaee-ear-archetype/README.adoc +++ b/wildfly-jakartaee-ear-archetype/README.adoc @@ -6,6 +6,7 @@ WildFly archetype for blank EAR project This archetype creates a blank EAR project with EJB and Web module. It is prepared for running Arquillian unit tests. +Optionally, it can provision a WildFly server. More details can be found in the file "src/main/resources/archetype-resources/README.txt", which is end-user doc and added to the resulting project. [[newwildflyversion]] @@ -31,12 +32,19 @@ $ mvn archetype:generate -DgroupId=my.project.org -DartifactId=sample-jakartaee- [[testing]] ==== Test the archetype -After having built the archetype, check whether both profiles "arq-remote" and "arq-managed" work. This is done by using scripts found in the directory "testing". +After having built the archetype, check whether all four profiles "arq-remote", "arq-managed", "provision" and "arq-provisioned" work. This is done by using scripts found in the directory "testing". + +The four profiles are executed as part of the Github CI * Profile "arq-managed": set variable JBOSS_HOME, then execute "runtest_managed.bat/.sh " (replace "" with the current archetype version) * Profile "arq-remote": start WildFly server, then execute "runtest_remote.bat/.sh " (replace "" with the current archetype version) +* Profile "provision": execute "runtest_provision.bat/.sh " (replace "" with the current archetype version) +* Profile "arq-provisioned": execute "runtest_provisioned.bat/.sh " (replace "" with the current archetype version) -Both files create a project from the archetype (in "testing/arq-managed" or "testing/arq-remote"), copy an Arquillian unit test class and an EJB in this project, then build and deploy it to WildFly and execute -the test using the Arquillian profile "arq-managed" or "arq-remote"). +The three "arq-....bat/.sh" files create a project from the archetype (in "testing/arq-managed", "testing/arq-remote" or "testing/arq-provisioned"), +copy an Arquillian unit test class and an EJB into this project, then build and deploy it to WildFly and execute +the test using the Arquillian profile "arq-managed", "arq-remote" or "arq-provisioned"). After the test is executed, check the server log for error outputs. In case of success, the outputs "Test is invoked..." and "doTest is invoked..." will be printed in the server console. + +The "provison.bat/.sh" files just builds the project and provisions a server. \ No newline at end of file diff --git a/wildfly-jakartaee-ear-archetype/pom.xml b/wildfly-jakartaee-ear-archetype/pom.xml index eaeeb8bf..e97e7b60 100644 --- a/wildfly-jakartaee-ear-archetype/pom.xml +++ b/wildfly-jakartaee-ear-archetype/pom.xml @@ -20,7 +20,8 @@ maven-archetype WildFly Archetypes: Jakarta EE EAR Webapp - An archetype that generates a starter Jakarta EE project for JBoss WildFly. The project is an EAR, with an EJB-JAR and WAR. It is prepared for Arquillian driven unit tests. + An archetype that generates a starter Jakarta EE project for JBoss WildFly. The project is an EAR, with an EJB-JAR and WAR. It is prepared for Arquillian driven unit tests. + Optionally, a "ready to run your app" provisioned WildFly server can be created using WildFly Glow. diff --git a/wildfly-jakartaee-ear-archetype/src/main/resources-filtered/archetype-resources/pom.xml b/wildfly-jakartaee-ear-archetype/src/main/resources-filtered/archetype-resources/pom.xml index 698ec70b..9221e91a 100644 --- a/wildfly-jakartaee-ear-archetype/src/main/resources-filtered/archetype-resources/pom.xml +++ b/wildfly-jakartaee-ear-archetype/src/main/resources-filtered/archetype-resources/pom.xml @@ -14,6 +14,7 @@ ejb web ear + integration-tests @@ -38,6 +39,8 @@ ${version.ejb.plugin} ${version.failsafe.plugin} ${version.war.plugin} + ${version.jar.plugin} + ${version.install.plugin} ${maven.compiler.release} @@ -261,6 +264,123 @@ + + + + provision + + + + + org.wildfly.plugins + wildfly-maven-plugin + \${version.wildfly.maven.plugin} + + + \${version.wildfly.bom} + + + h2-database:default + + + + + + + + package + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + \${version.failsafe.plugin} + + + true + + + + + + + + + arq-provisioned + + + org.wildfly.arquillian + wildfly-arquillian-container-managed + test + + + + + + + org.wildfly.plugins + wildfly-maven-plugin + ${version.wildfly.maven.plugin} + + + \${version.wildfly.bom} + + + h2-database:default + + + + true + + server_arquillian + + + + + + package + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + \${version.failsafe.plugin} + + + + integration-test + verify + + + + + + + + provisioned + + + + + + + diff --git a/wildfly-jakartaee-ear-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/wildfly-jakartaee-ear-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml index f9c558e9..e742d602 100644 --- a/wildfly-jakartaee-ear-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/wildfly-jakartaee-ear-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -74,6 +74,19 @@ + + + + src/test/java + + + src/test/resources + + **/*.xml + + + + diff --git a/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/README.txt b/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/README.txt index d218b05f..065103e9 100644 --- a/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/README.txt +++ b/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/README.txt @@ -15,6 +15,9 @@ a persistence unit "${rootArtifactId}PersistenceUnit" which uses the JakartaEE d In production environment, you should define a database in WildFly config and point to this database in "persistence.xml". +If you change the datasource name and use provisioning (profile "provision" or "arq-provisioned", see below), +you have to update the provisioning config. + If you don't use entity beans, you can delete "persistence.xml". ========================== @@ -23,13 +26,50 @@ The web application is prepared for Jakarta Faces 4.0 by bundling an empty "face In case you don't want to use Jakarta Faces, simply delete this file and "src/main/webapp/beans.xml". ========================== +Provisioning: +The project defines two profiles "provision" and "arq-provisioned" that create a provisioned WildFly server (in "target/server" or "target/server_arquillian") +by auto discovering features necessary to run this application. + +The profile "provision" is meant to build a server that contains this enterprise application as deployment. +The profile "arq-provisioned" also builds a server, then runs the arquillian tests. This profile does not add the deployment, so that the arquillian +tests can deploy the app themselves enriched with additional test classes. + +As "persistence.xml" uses the datasource "java:comp/DefaultDataSource", Glow must be configured to create +the datasource in the WildFly server config. Currently, the default H2 datasource is configured: + + + h2-database:default + + +If you change the datasource name in "persistence.xml" or want to use a different datasource, you have to change the Glow configuration +so that it creates the necessary snippets in the WildFly config. + +When using a provisioned server, you would probably deploy the app as root application, as the server provides only one application - +no need to have a context path. +You could achieve this by changing the configuration of the "maven-ear-plugin" in "ear/pom.xml", see +https://maven.apache.org/plugins/maven-ear-plugin/examples/customizing-context-root.html +This will register the web application to the context root. +========================== + Testing: This sample is prepared for running JUnit5 unit tests with the Arquillian framework. The configuration can be found in "${rootArtifactId}/pom.xml": -Three profiles are defined: --"default": no integration tests are executed. +The test code is contained in a separate module "integration_tests". +There are two reasons to do so: +Reason 1: +The Arquillian tests pick the ear file, add additional server side test classes and deploy this modified ear. By +placing the tests in their own module, they are run after the ear project was built and thus +can grab the resulting ear file. +Reason 2: +When executing the profile "arq_provisioned", Arquillian deploys the test ear file to the provisioned server. +This server is created when the ear project is built, so the tests have to be run after the project was built. +It is not possible to place test code in the ear project. So they are placed in a separate module that is built +after the ear project build. + +Five profiles are defined: +-"default" and "provision": no integration tests are executed. -"arq-remote": you have to start a WildFly server on your machine. The tests are executed by deploying the application to this server. Here the "maven-failsafe-plugin" is enabled so that integration tests can be run. @@ -39,21 +79,24 @@ Three profiles are defined: Instead of using this environment variable, you can also define the path in "arquillian.xml". Here the "maven-failsafe-plugin" is enabled so that integration tests can be run. Run maven with these arguments: "clean verify -Parq-managed" + -"arq-provisioned": the tests are executed by deploying the application to the + server that is created during the provisioning step (in "target/server"). -The Arquillian test runner is configured with the file "src/test/resources/arquillian.xml" -(duplicated in EJB and WEB project, depending where your tests are placed). -The profile "arq-remote" uses the container qualifier "remote" in this file. -The profile "arq-managed" uses the container qualifier "managed" in this file. - +The Arquillian test runner is configured with the file "integration-tests/src/test/resources/arquillian.xml": +-The profile "arq-remote" uses the container qualifier "remote" in this file. +-The profile "arq-managed" uses the container qualifier "managed" in this file. +-The profile "arq-provisioned" uses the container qualifier "provisioned" in this file, which sets +JBOSS_HOME to "../ear/target/server_arquillian" (note the relative path, as we have to move from the "integration_tests" +project to the "ear" project, where the provisioned server is placed). -Unit tests can be added to EJB project and/or to Web project. +Unit tests can be added to the "integration-tests" module, the EJB project and/or to the Web project. -The web project contains an integration test "SampleIT" which shows how to create the deployable EAR file using the ShrinkWrap API. +The "integration-tests" project contains an integration test "SampleIT" which shows how to create the deployable EAR file using the ShrinkWrap API. You can delete this test file if no tests are necessary. Why integration tests instead of the "maven-surefire-plugin" testrunner? -The Arquillian test runner deploys the EAR file to the WildFly server and thus you have to build it yourself with the ShrinkWrap API. -The goal "verify" (which triggers the maven-surefire-plugin) is executed later in the maven build lifecyle than the "test" goal so that the target -artifacts ("${rootArtifactId}-ejb.jar" and "${rootArtifactId}-web.war") are already built. You can build -the final EAR by including those files. The "maven-surefire-plugin" is executed before the JAR/WAR files -are created, so those JAR/WAR files would have to be built in the "@Deployment" method, too. +Basically, you can run Arquillian tests using the "maven-surefire-plugin". But due to the structure of the project, +this does not work here. The project provides several profiles, each defines a different way for Arquillian to connect to a WildFly server and +deploy the test application. The "default" profile thus does not have any Arquillian configuration. +As it also does not attach the "maven-failsafe-plugin" to any goal, no integration tests are executed and Arquillian is not invoked. +The "maven-surefire-plugin" test execution is automatically activated, and those test would fail here as no server for Arquillian is configured. diff --git a/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/integration-tests/pom.xml b/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/integration-tests/pom.xml new file mode 100644 index 00000000..28d1b0c7 --- /dev/null +++ b/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/integration-tests/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + + + ${groupId} + ${rootArtifactId} + ${version} + + ${rootArtifactId}-integration-tests + jar + ${rootArtifactId} - integration-tests + This module contains the arquillian integration tests for the enterprise application. + + + + + + jakarta.enterprise + jakarta.enterprise.cdi-api + provided + + + + + org.junit.jupiter + junit-jupiter + test + + + + + + + jakarta.ejb + jakarta.ejb-api + provided + + + + + org.jboss.arquillian.junit5 + arquillian-junit5-container + test + + + + + ${project.groupId} + ${rootArtifactId}-ejb + ejb + provided + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + ${version.jar.plugin} + + true + + + + + + org.apache.maven.plugins + maven-install-plugin + ${version.install.plugin} + + true + + + + + diff --git a/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/web/src/test/java/test/SampleIT.java b/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/integration-tests/src/test/java/test/SampleIT.java similarity index 58% rename from wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/web/src/test/java/test/SampleIT.java rename to wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/integration-tests/src/test/java/test/SampleIT.java index d90a7b4a..c319b215 100644 --- a/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/web/src/test/java/test/SampleIT.java +++ b/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/integration-tests/src/test/java/test/SampleIT.java @@ -28,25 +28,13 @@ public class SampleIT { */ @Deployment public static Archive getEarArchive() { - // Create the EAR archive: - EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "${rootArtifactId}-ear.ear"); - // Current directory is the root of the "${rootArtifactId}-web" project. Go up one level - // and enter the "ejb" project. - // The ejb jar is found in the "target" directory: - File f = new File("../ejb/target/${rootArtifactId}-ejb.jar"); - JavaArchive ejbJar = ShrinkWrap.create(ZipImporter.class, "${rootArtifactId}-ejb.jar").importFrom(f).as(JavaArchive.class); - ear.addAsModule(ejbJar); + // Open the existing EAR archive: + File f = new File("../ear/target/${rootArtifactId}.ear"); + EnterpriseArchive ear = ShrinkWrap.create(ZipImporter.class, "${rootArtifactId}.ear").importFrom(f).as(EnterpriseArchive.class); // Now grab the web archive: - f = new File("./target/${rootArtifactId}-web.war"); - if (f.exists() == false) { - throw new RuntimeException("File " + f.getAbsolutePath() + " does not exist."); - } - WebArchive war = ShrinkWrap.create(ZipImporter.class, "${rootArtifactId}-web.war").importFrom(f).as(WebArchive.class); - ear.addAsModule(war); - - // The manifest file is auto created by the Maven EAR plugin - we don't have it here. + WebArchive war = ear.getAsType(WebArchive.class, "${rootArtifactId}-web.war"); // Add the package containing the test classes: war.addPackage("${package}.test"); diff --git a/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/web/src/test/resources/arquillian.xml b/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/integration-tests/src/test/resources/arquillian.xml similarity index 79% rename from wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/web/src/test/resources/arquillian.xml rename to wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/integration-tests/src/test/resources/arquillian.xml index 912cdaab..c6531f19 100644 --- a/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/web/src/test/resources/arquillian.xml +++ b/wildfly-jakartaee-ear-archetype/src/main/resources/archetype-resources/integration-tests/src/test/resources/arquillian.xml @@ -32,4 +32,13 @@ admin --> + + + + + ../ear/target/server_arquillian + + diff --git a/wildfly-jakartaee-ear-archetype/testing/.gitignore b/wildfly-jakartaee-ear-archetype/testing/.gitignore index 1d57bdc5..520e4fa7 100644 --- a/wildfly-jakartaee-ear-archetype/testing/.gitignore +++ b/wildfly-jakartaee-ear-archetype/testing/.gitignore @@ -1,2 +1,4 @@ /arq-managed /arq-remote +/arq-provisioned +/provision \ No newline at end of file diff --git a/wildfly-jakartaee-ear-archetype/testing/runtest_managed.bat b/wildfly-jakartaee-ear-archetype/testing/runtest_managed.bat index e880aaab..c06a91b9 100644 --- a/wildfly-jakartaee-ear-archetype/testing/runtest_managed.bat +++ b/wildfly-jakartaee-ear-archetype/testing/runtest_managed.bat @@ -38,7 +38,7 @@ if %ERRORLEVEL% NEQ 0 ( copy ..\additionalfiles\TestBean.java .\multi\ejb\src\main\java\foo\bar\multi\ copy ..\additionalfiles\TestLocal.java .\multi\ejb\src\main\java\foo\bar\multi\ copy ..\additionalfiles\TestRemote.java .\multi\ejb\src\main\java\foo\bar\multi\ -copy ..\additionalfiles\ArchetypeIT.java .\multi\web\src\test\java\foo\bar\multi\test\ +copy ..\additionalfiles\ArchetypeIT.java .\multi\integration-tests\src\test\java\foo\bar\multi\test\ cd multi @ECHO run test diff --git a/wildfly-jakartaee-ear-archetype/testing/runtest_managed.sh b/wildfly-jakartaee-ear-archetype/testing/runtest_managed.sh index 2250acc8..49b13706 100755 --- a/wildfly-jakartaee-ear-archetype/testing/runtest_managed.sh +++ b/wildfly-jakartaee-ear-archetype/testing/runtest_managed.sh @@ -42,7 +42,7 @@ echo "copy additional files required for test." cp ../additionalfiles/TestBean.java ./multi/ejb/src/main/java/foo/bar/multi/ cp ../additionalfiles/TestLocal.java ./multi/ejb/src/main/java/foo/bar/multi/ cp ../additionalfiles/TestRemote.java ./multi/ejb/src/main/java/foo/bar/multi/ -cp ../additionalfiles/ArchetypeIT.java ./multi/web/src/test/java/foo/bar/multi/test/ +cp ../additionalfiles/ArchetypeIT.java ./multi/integration-tests/src/test/java/foo/bar/multi/test/ cd multi echo "run test" diff --git a/wildfly-jakartaee-ear-archetype/testing/runtest_provision.bat b/wildfly-jakartaee-ear-archetype/testing/runtest_provision.bat new file mode 100644 index 00000000..9cd8147e --- /dev/null +++ b/wildfly-jakartaee-ear-archetype/testing/runtest_provision.bat @@ -0,0 +1,44 @@ +@REM Creates a project from the archetype and creates a provisioned server +@REM using the profile "provision". +@REM Prerequesites: none. +@REM The current archetype version must be the first argument to the batch file call. + +@echo off + +@if "%1" == "" ( + echo Archetype version must be first argument to the call to the batch file. + set /p archetypeVersion=Please enter archetype version: +) else ( + set archetypeVersion=%1 +) + +if exist provision ( + @ECHO delete old test project + rmdir /S /Q provision +) +@REM if directory still exists then fail +if exist provision ( + @echo [ERROR] directory 'provision' could not be deleted + goto :exit +) + +@ECHO creating test project directory +mkdir provision +cd provision + +@ECHO generate project from archetype. +call mvn archetype:generate -DarchetypeCatalog=local -DgroupId=foo.bar -DartifactId=multi -Dversion=0.1-SNAPSHOT -Dpackage=foo.bar.multi -DarchetypeGroupId=org.wildfly.archetype -DarchetypeArtifactId=wildfly-jakartaee-ear-archetype -DarchetypeVersion=%archetypeVersion% -DinteractiveMode=false +if %ERRORLEVEL% NEQ 0 ( + @echo [ERROR] Maven project creation failed. Errorlevel: %ERRORLEVEL% + cd.. + goto :exit +) + +cd multi +@ECHO run test +call mvn verify -Pprovision +cd ..\.. + + + +:exit \ No newline at end of file diff --git a/wildfly-jakartaee-ear-archetype/testing/runtest_provision.sh b/wildfly-jakartaee-ear-archetype/testing/runtest_provision.sh new file mode 100755 index 00000000..2da291f4 --- /dev/null +++ b/wildfly-jakartaee-ear-archetype/testing/runtest_provision.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# Creates a project from the archetype and creates a provisioned server +# using the profile "provision". +# Prerequesites: none. +# The current archetype version must be the first argument to the batch file call. + +if [ -z "$1" ] + then + echo Archetype version must be first argument to the call to the batch file. + read -p "Please enter archetype version: " archetypeVersion + else + archetypeVersion=$1 +fi + +if [ -d "provision" ]; then + echo "delete old test project" + rm -rf provision +fi + + +# if directory still exists then fail +if [ -d "provision" ]; then + echo "[ERROR] directory 'provision' could not be deleted" + exit 1 +fi + +echo "creating test project directory" +mkdir provision +cd provision + +echo "generate project from archetype." +mvn archetype:generate -DarchetypeCatalog=local -DgroupId=foo.bar -DartifactId=multi -Dversion=0.1-SNAPSHOT -Dpackage=foo.bar.multi -DarchetypeGroupId=org.wildfly.archetype -DarchetypeArtifactId=wildfly-jakartaee-ear-archetype -DarchetypeVersion=$archetypeVersion -DinteractiveMode=false +retVal=$? +if [ $retVal -ne 0 ]; then + echo "[ERROR] Maven project creation failed. Errorcode: $retVal" + cd .. + exit $retVal +fi + +cd multi +echo "run test" +mvn verify -Pprovision +retVal=$? +cd ../.. +exit $retVal \ No newline at end of file diff --git a/wildfly-jakartaee-ear-archetype/testing/runtest_provisioned.bat b/wildfly-jakartaee-ear-archetype/testing/runtest_provisioned.bat new file mode 100644 index 00000000..f2ce15f2 --- /dev/null +++ b/wildfly-jakartaee-ear-archetype/testing/runtest_provisioned.bat @@ -0,0 +1,51 @@ +@REM Creates a project from the archetype, copies some additional source files and runs an integration test +@REM using the profile "arq-provisioned". +@REM Prerequesites: none, the tests are run on a WildFly server that is created as part of the build process. +@REM The current archetype version must be the first argument to the batch file call. + +@echo off + +@if "%1" == "" ( + echo Archetype version must be first argument to the call to the batch file. + set /p archetypeVersion=Please enter archetype version: +) else ( + set archetypeVersion=%1 +) + +if exist arq-provisioned ( + @ECHO delete old test project + rmdir /S /Q arq-provisioned +) +@REM if directory still exists then fail +if exist arq-provisioned ( + @echo [ERROR] directory 'arq-provisioned' could not be deleted + goto :exit +) + +@ECHO creating test project directory +mkdir arq-provisioned +cd arq-provisioned + +@ECHO generate project from archetype. +call mvn archetype:generate -DarchetypeCatalog=local -DgroupId=foo.bar -DartifactId=multi -Dversion=0.1-SNAPSHOT -Dpackage=foo.bar.multi -DarchetypeGroupId=org.wildfly.archetype -DarchetypeArtifactId=wildfly-jakartaee-ear-archetype -DarchetypeVersion=%archetypeVersion% -DinteractiveMode=false +if %ERRORLEVEL% NEQ 0 ( + @echo [ERROR] Maven project creation failed. Errorlevel: %ERRORLEVEL% + cd.. + goto :exit +) + +@ECHO copy additional files required for test. +copy ..\additionalfiles\TestBean.java .\multi\ejb\src\main\java\foo\bar\multi\ +copy ..\additionalfiles\TestLocal.java .\multi\ejb\src\main\java\foo\bar\multi\ +copy ..\additionalfiles\TestRemote.java .\multi\ejb\src\main\java\foo\bar\multi\ +copy ..\additionalfiles\ArchetypeIT.java .\multi\integration-tests\src\test\java\foo\bar\multi\test\ + +cd multi +@ECHO run test +call mvn verify -Parq-provisioned + +cd ..\.. + + + +:exit \ No newline at end of file diff --git a/wildfly-jakartaee-ear-archetype/testing/runtest_provisioned.sh b/wildfly-jakartaee-ear-archetype/testing/runtest_provisioned.sh new file mode 100755 index 00000000..4f35cd8a --- /dev/null +++ b/wildfly-jakartaee-ear-archetype/testing/runtest_provisioned.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Creates a project from the archetype, copies some additional source files and runs an integration test +# using the profile "arq-managed". +# Prerequesites: the environment variable JBOSS_HOME must point to the WildFly server corresponding to the archetyp version. +# The current archetype version must be the first argument to the batch file call. + +if [ -z "$1" ] + then + echo Archetype version must be first argument to the call to the batch file. + read -p "Please enter archetype version: " archetypeVersion + else + archetypeVersion=$1 +fi + +if [ -d "arq-managed" ]; then + echo "delete old test project" + rm -rf arq-managed +fi + + +# if directory still exists then fail +if [ -d "arq-managed" ]; then + echo "[ERROR] directory 'arq-managed' could not be deleted" + exit 1 +fi + +echo "creating test project directory" +mkdir arq-managed +cd arq-managed + +echo "generate project from archetype." +mvn archetype:generate -DarchetypeCatalog=local -DgroupId=foo.bar -DartifactId=multi -Dversion=0.1-SNAPSHOT -Dpackage=foo.bar.multi -DarchetypeGroupId=org.wildfly.archetype -DarchetypeArtifactId=wildfly-jakartaee-ear-archetype -DarchetypeVersion=$archetypeVersion -DinteractiveMode=false +retVal=$? +if [ $retVal -ne 0 ]; then + echo "[ERROR] Maven project creation failed. Errorcode: $retVal" + cd .. + exit $retVal +fi + + +echo "copy additional files required for test." +cp ../additionalfiles/TestBean.java ./multi/ejb/src/main/java/foo/bar/multi/ +cp ../additionalfiles/TestLocal.java ./multi/ejb/src/main/java/foo/bar/multi/ +cp ../additionalfiles/TestRemote.java ./multi/ejb/src/main/java/foo/bar/multi/ +cp ../additionalfiles/ArchetypeIT.java ./multi/integration-tests/src/test/java/foo/bar/multi/test/ + +cd multi +echo "run test" +mvn verify -Parq-provisioned +retVal=$? +cd ../.. +exit $retVal diff --git a/wildfly-jakartaee-ear-archetype/testing/runtest_remote.bat b/wildfly-jakartaee-ear-archetype/testing/runtest_remote.bat index f752fd29..4ceb8397 100644 --- a/wildfly-jakartaee-ear-archetype/testing/runtest_remote.bat +++ b/wildfly-jakartaee-ear-archetype/testing/runtest_remote.bat @@ -38,7 +38,7 @@ if %ERRORLEVEL% NEQ 0 ( copy ..\additionalfiles\TestBean.java .\multi\ejb\src\main\java\foo\bar\multi\ copy ..\additionalfiles\TestLocal.java .\multi\ejb\src\main\java\foo\bar\multi\ copy ..\additionalfiles\TestRemote.java .\multi\ejb\src\main\java\foo\bar\multi\ -copy ..\additionalfiles\ArchetypeIT.java .\multi\web\src\test\java\foo\bar\multi\test\ +copy ..\additionalfiles\ArchetypeIT.java .\multi\integration-tests\src\test\java\foo\bar\multi\test\ cd multi @ECHO run test diff --git a/wildfly-jakartaee-ear-archetype/testing/runtest_remote.sh b/wildfly-jakartaee-ear-archetype/testing/runtest_remote.sh index d8c000c1..1d3b488a 100755 --- a/wildfly-jakartaee-ear-archetype/testing/runtest_remote.sh +++ b/wildfly-jakartaee-ear-archetype/testing/runtest_remote.sh @@ -42,7 +42,7 @@ echo "copy additional files required for test." cp ../additionalfiles/TestBean.java ./multi/ejb/src/main/java/foo/bar/multi/ cp ../additionalfiles/TestLocal.java ./multi/ejb/src/main/java/foo/bar/multi/ cp ../additionalfiles/TestRemote.java ./multi/ejb/src/main/java/foo/bar/multi/ -cp ../additionalfiles/ArchetypeIT.java ./multi/web/src/test/java/foo/bar/multi/test/ +cp ../additionalfiles/ArchetypeIT.java ./multi/integration-tests/src/test/java/foo/bar/multi/test/ cd multi echo "run test" From 72e7d56f1ba91b35b906265552a6ab5e573dc3bc Mon Sep 17 00:00:00 2001 From: WolfgangHG Date: Thu, 16 Oct 2025 21:10:42 +0200 Subject: [PATCH 2/2] EAR provisioning: avoid false warning when creating project from archetype for new integration test project --- .../src/main/resources/META-INF/maven/archetype-metadata.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wildfly-jakartaee-ear-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/wildfly-jakartaee-ear-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml index e742d602..a1027b8f 100644 --- a/wildfly-jakartaee-ear-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/wildfly-jakartaee-ear-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -78,6 +78,10 @@ src/test/java + + + **/*.java + src/test/resources