Jakarta EE Components
Integration Testing with Arquillian
Integration and UI tests against real Payara or GlassFish servers, with no deployment method, no server code and no configuration to write.
Flow Logix removes most of the setup from Arquillian and ShrinkWrap tests.
Deployments are created from your Maven POM, and ShrinkWrapManipulator adjusts test archives when a test needs something different.
|
Tip
|
The integration-test dependency chain brings in Arquillian, Testcontainers and everything else these tests need.
|
Automatic deployments
If a test class (or the @ArquillianSuiteDeployment class) has no @Deployment method,
Flow Logix creates the deployment automatically from the Maven POM file.
One deployment is created for each @OperateOnDeployment name that has no matching @Deployment method,
or a single default one if there are none.
The archive type comes from the POM’s <packaging>: war, jar, ejb, ear or rar.
Package SLF4J
To package SLF4J in automatically created WAR deployments, opt in through arquillian.xml:
<extension qualifier="flowlogix">
<property name="packageSlf4j">true</property>
</extension>
This defaults to false, and leaves explicit @Deployment archives unchanged.
Enabling it calls ShrinkWrapManipulator.packageSlf4j(), which packages the SLF4J APIs.
The provider implementation and its dependencies must be available in the deployment,
which is the default with the Flow Logix Base POM and dependency chains.
Customize a deployment
Write a @Deployment method only when the deployment needs to be customized.
It can still start from the Maven POM:
@Deployment
static WebArchive deployMaven() {
return ShrinkWrapManipulator.logArchiveContents(ShrinkWrapManipulator.<WebArchive>createDeployment(),
contents -> log.info("Archive Contents: {}", contents));
}
prod suffix@Deployment
static WebArchive deployMavenSuffix() {
WebArchive archive = ShrinkWrapManipulator.createDeployment(name -> name + "-prod");
return ShrinkWrapManipulator.logArchiveContents(archive,
contents -> log.info("Archive Contents: {}", contents));
}
The createDeployment(Class) variants specify the archive type explicitly.
Change web.xml
webXmlXPath() takes a List<Action> and changes the archive’s web.xml to get the test configuration you need.
For example, to run an archive in Jakarta Faces production mode, change its context-param:
@Deployment
static WebArchive deployProductionMode() {
var archive = ShrinkWrapManipulator.createDeployment(WebArchive.class);
// add classes to the archive here
var productionList = List.of(new Action(getContextParamValue(
jakartify("javax.faces.PROJECT_STAGE")),
node -> node.setTextContent("Production")));
new ShrinkWrapManipulator().webXmlXPath(archive, productionList);
return archive;
}
getContextParamValue() is a shorthand for the XPath of a web.xml context parameter (<context-param>):
//web-app/context-param[param-name = 'jakarta.faces.PROJECT_STAGE']/param-value
The second parameter is a Consumer of the DOM Node, so you can change the element directly.
The example also uses jakartify() to work with both Jakarta EE 8 and 9.
Change persistence.xml
Maven filtering can resolve a versioned entities JAR in persistence.xml, but ShrinkWrap doesn’t apply it,
because it builds the archive with its own mechanism:
<persistence>
<persistence-unit>
<jar-file>entities-${project.version}.jar</jar-file>
</persistence-unit>
</persistence>
Instead, make the substitution in the deployment method:
persistence.xmlpublic static WebArchive deployPersistence() {
var archive = ShrinkWrapManipulator.createDeployment(WebArchive.class);
// add classes to the archive here
String version = System.getProperty("project.version");
new ShrinkWrapManipulator().persistenceXmlXPath(archive,
List.of(new Action("//persistence/persistence-unit/jar-file",
node -> node.setTextContent(String.format("lib/entities-%s.jar", version)))));
return archive;
}
Change any XML file
webXmlXPath() and persistenceXmlXPath() are built on manipulateXml(),
which you can use to transform any XML file in the archive.
See the complete ShrinkWrapDemo.java.
Test over HTTPS
Arquillian uses plain HTTP by default, but some tests need TLS.
toHttpsURL(url) converts a URL to its HTTPS equivalent, using the port in the httpsPort system property, or 8181 by default.
If that property and port don’t suit you, toHttpURL(url, sslPortPropertyName, defaultPort) lets you choose both.
For example, with this command, toHttpsURL("http://host/index.html") returns https://host:8282/index.html:
mvn verify -DhttpsPort=8282