Arquillian testing framework helps considerably doing a simple Wildfly/EAP test.
Reasons to be very easy:
1. It is pretty simple to write a test, as any unit test should be and it allows to package the application in one function pretty smothly:
@Deployment
public static WebArchive createDeployment()
{
System.out.println("create Deployment");
WebArchive archive = ShrinkWrap.create(WebArchive.class, "sample.war")
.addPackage("com.example")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsResource("validation.xml", "META-INF/validation.xml");
System.out.println(archive.toString(true));
archive.as(ZipExporter.class).exportTo(new File("/tmp/" + archive.getName()), true);
return archive;
}
2. Using arquilllian.xml enables to select a certain specific container to be deployed, as little as the lines below to select the container:
</container>
<container qualifier="arquillian-wildfly-managed">
<configuration>
<property name="chameleonTarget">${chameleon.target}</property>
<property name="serverConfig">standalone-full.xml</property>
</configuration>
</container>
3. Testing is pretty straightforward
@Test
public void Test1() throws Exception
{
System.out.println("Calling URI: " + serviceUri.toString()); //to show the url being called
final String targetUrl = serviceUri.toString() + "hello";
log.info("The target URL is: {}", targetUrl);
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(targetUrl);
ValidatedJaxRsInterface validatedJaxRs = target.proxy(ValidateJaxRsInt.class);
try
{
log.info("Testing");
log.info("Validated call responded with: {}", validation.Hello());
}
catch (Exception exception)
{
log.error("Got an error when calling the validated endpoint: {}", exception.getMessage(),exception);
if (exception instanceof BadRequestException)
{
BadRequestException exp = (BadRequestException) exception;
log.error("The response was bad request :/ {}", exp.getMessage());
}
}
log.info("Calling validation.Hello");
}
4. One can use chameleon or wildfly arquillian straight on the pom to get the container, like below:
<configuration>
<forkCount>1</forkCount>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
<systemPropertyVariables>
<arquillian.launch>arquillian-wildfly-${container.type}</arquillian.launch>
<chameleon.target>jboss eap:${jboss.version}:${container.type}</chameleon.target>
</systemPropertyVariables>
</configuration>
Depending on the EAP version one should use the wildfly arquillian container image instead, see difference below:
<!-- Arquillian Chameleon -->
<dependency>
<groupId>org.arquillian.universe</groupId>
<artifactId>arquillian-chameleon</artifactId>
<type>pom</type>
<scope>test</scope>
</dependency>
<!--- wildfly-arquillian-container-managed -->
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
5. Adding validation becomes almost trivial with the validation.xml file:
<executable-validation enabled="true">
<default-validated-executable-types>
<executable-type>CONSTRUCTORS</executable-type>
<executable-type>NON_GETTER_METHODS</executable-type>
</default-validated-executable-types>
</executable-validation>