Integration Testing w/ Maven, Cargo, & JBoss EAP 5

This configuration has been optimized for a multi-module project where the integration tests are in a separate project from the application artifact.

Prerequisites:

  • The integration test class names will be suffixed with ‘IT’.
  • The integration tests will be executed against a JBoss Enterprise Application Platform 5.1.2 server that has been started and is available via localhost.

Step 1 – Profile Service Configuration

Update the JBoss EAP 5 profile service (deploy/profileservice-jboss-beans.xml) to disable authentication. If authentication is enabled, Arquillian will be unable to deploy the archive.

Comment out the following beans nested within the ProfileServiceProxyFactory bean as shown below:

<!-- comment this list to disable auth checks for the profileservice -->
<!--
   <bean>
      <constructor>
         <parameter>
            <value-factory bean="JNDIBasedSecurityManagement"
               method="getAuthenticationManager" parameter="jmx-console"/>
         </parameter>
      </constructor>
   </bean>
   <bean>
      <constructor>
         <parameter>
            <value-factory bean="JNDIBasedSecurityManagement"
               method="getAuthenticationManager" parameter="jmx-console"/>
         </parameter>
         <parameter>
            <value-factory bean="JNDIBasedSecurityManagement"
               method="getAuthenticationManager" parameter="jmx-console"/>
         </parameter>
      </constructor>
   </bean>
-->

Step 2 – JUnit Dependency

Add the JUnit dependency to either the parent POM or the project POM.

<dependencies>
   <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.8.1</version>
      <scope>test</scope>
   </dependency>
</dependencies>

Step 3 – Surefire Plugin Configuration 1/2

The Surefire plugin should be configured in either the parent or the project POM to exclude integration tests from the test phase.

<build>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
         <version>2.11</version>
         <configuration>
            <excludes>
               <exclude>**/*IT.java</exclude>
            </excludes>
         </configuration>
      </plugin>
   </plugins>
</build

Step 4 – Profile

Create a profile in the project POM for executing the integration tests.

<profiles>
   <profile>
      <id>localhost-remote</id>
   </profile>
</profiles>

Step 5 – Application Archive Dependency

Add the application archive dependency (EAR/WAR).

<profiles>
   <profile>
      <id>localhost-remote</id>
      <dependencies>
         <dependency>
            <groupId>com.company.app</groupId>
            <artifactId>app</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>provided</scope>
            <type>ear</type>
         </dependency>
      </dependencies>
   </profile>
</profiles>

Step 6 – Surefire Configuration 2/2

Configure the Surefire plugin in the profile to execute the integration tests.

<profiles>
   <profile>
      <id>localhost-remote</id>
      <dependencies>
         <dependency>
            <groupId>com.company.app</groupId>
            <artifactId>app</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>provided</scope>
            <type>ear</type>
         </dependency>
      </dependencies>
      <build>
         <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-surefire-plugin</artifactId>
               <version>2.11</version>
               <executions>
                  <execution>
                     <id>integration-test</id>
                     <phase>integration-test</phase>
                     <goals>
                        <goal>test</goal>
                     </goals>
                     <configuration>
                        <excludes>
                           <exclude>none</exclude>
                        </excludes>
                        <includes>
                           <include>**/*IT.java</include>
                        </includes>
                     </configuration>
                  </execution>
               </executions>
            </plugin>
         </plugins>
      </build>
   </profile>
</profiles

Step 7 – Copy Application Archive

Configure the Dependency plugin to copy the application archive dependency to the target/dependency directory and rename it.

The application archive name includes the version by default. As a result, the application archive name is dynamic. A session bean binds to a JNDI name that is prefixed with the name of the EAR file (documentation). As a result, the JNDI name of a session bean is dynamic.

If the application archive name is static, the JNDI name of a session bean is static.

<profiles>
   <profile>
      <id>localhost-remote</id>
      <dependencies>
         <dependency>
            <groupId>com.company.app</groupId>
            <artifactId>app</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>provided</scope>
            <type>ear</type>
         </dependency>
      </dependencies>
      <build>
         <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-dependency-plugin</artifactId>
               <version>2.4</version>
               <executions>
                  <execution>
                     <id>copy</id>
                     <phase>package</phase>
                     <goals>
                        <goal>copy</goal>
                     </goals>
                     <configuration>
                        <artifactItems>
                           <artifactItem>
                              <groupId>com.company.app</groupId>
                              <artifactId>app</artifactId>
                              <version>0.0.1-SNAPSHOT</version>
                              <type>ear</type>
                              <destFileName>app.ear</destFileName>
                           </artifactItem>
                        </artifactItems>
                     </configuration>
                  </execution>
               </executions>
            </plugin>
         </plugins>
      </build>
   </profile>
</profiles>

Step 8 – Cargo Configuration

Configure the Cargo plugin to a) deploy the application archive during the pre-integration-test phase to a JBoss EAP 5.1.2 server that has been started and is available via localhost and b) undeploy the application archive during the post-integration-test phase from a JBoss EAP 5.1.2 server that has been started and is available via localhost.

The container type is ‘remote’ because Cargo is going to deploy to and undeploy from “a container that is running and that has been started externally from Cargo” (documentation).

The username and password are empty because authentication has been disabled for the profile service.

Note that Cargo with JBoss EAP 5 requires the JBoss AS 5.1 client, but the JBoss AS  6.0 profile service client.

<profiles>
   <profile>
      <id>localhost-remote</id>
      <dependencies>
         <dependency>
            <groupId>com.company.app</groupId>
            <artifactId>app</artifactId>
            <version>0.0.1-SNAPSHOT</version>
            <scope>provided</scope>
            <type>ear</type>
         </dependency>
      </dependencies>
      <build>
         <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-surefire-plugin</artifactId>
               <version>2.11</version>
               <executions>
                  <execution>
                     <id>integration-test</id>
                     <phase>integration-test</phase>
                     <goals>
                        <goal>test</goal>
                     </goals>
                     <configuration>
                        <excludes>
                           <exclude>none</exclude>
                        </excludes>
                        <includes>
                           <include>**/*IT.java</include>
                        </includes>
                     </configuration>
                  </execution>
               </executions>
            </plugin>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-dependency-plugin</artifactId>
               <version>2.4</version>
               <executions>
                  <execution>
                     <id>copy</id>
                     <phase>package</phase>
                     <goals>
                        <goal>copy</goal>
                     </goals>
                     <configuration>
                        <artifactItems>
                           <artifactItem>
                              <groupId>com.company.app</groupId>
                              <artifactId>app</artifactId>
                              <version>0.0.1-SNAPSHOT</version>
                              <type>ear</type>
                              <destFileName>app.ear</destFileName>
                           </artifactItem>
                        </artifactItems>
                     </configuration>
                  </execution>
               </executions>
            </plugin>
            <plugin>
               <groupId>org.codehaus.cargo</groupId>
               <artifactId>cargo-maven2-plugin</artifactId>
               <version>1.1.4</version>
               <configuration>
                  <container>
                     <containerId>jboss51x</containerId>
                     <type>remote</type>
                  </container>
                  <configuration>
                     <type>runtime</type>
                     <properties>
                        <cargo.remote.username></cargo.remote.username>
                        <cargo.remote.password></cargo.remote.password>
                     </properties>
                  </configuration>
                  <deployer>
                     <deployables>
                        <deployable>
                           <type>ear</type>
                           <location>${project.build.directory}/dependency/app.ear</location>
                        </deployable>
                     </deployables>
                  </deployer>
               </configuration>
               <dependencies>
                  <dependency>
                     <groupId>org.jboss.jbossas</groupId>
                     <artifactId>jboss-as-client</artifactId>
                     <version>5.1.0.GA</version>
                     <type>pom</type>
                  </dependency>
                  <dependency>
                     <groupId>org.jboss.jbossas</groupId>
                     <artifactId>jboss-as-profileservice-client</artifactId>
                     <version>6.0.0.Final</version>
                     <type>pom</type>
                  </dependency>
               </dependencies>
               <executions>
                  <execution>
                     <id>pre-integration-test</id>
                     <phase>pre-integration-test</phase>
                     <goals>
                        <goal>deploy</goal>
                     </goals>
                  </execution>
                  <execution>
                     <id>post-integration-test</id>
                     <phase>post-integration-test</phase>
                     <goals>
                        <goal>undeploy</goal>
                     </goals>
                  </execution>
               </executions>
            </plugin>
         </plugins>
      </build>
   </profile>
</profiles>

Update: The parent of the jboss-as-client dependency (jboss-as-parent) includes repository configuration for the old JBoss Maven repository (http://repository.jboss.org/maven2). Therefore, a mirror has to be configured in the Maven settings.xml file so that this repository is replaced with the new JBoss Nexus (Deprecated) repository (https://repository.jboss.org/nexus).

<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
   <mirrors>
      <mirror>
         <mirrorOfLayouts/>
         <id>jboss-deprecated</id>
         <name>JBoss Deprecated Repository</name>
         <url>https://repository.jboss.org/nexus/content/repositories/deprecated/</url>
         <mirrorOf>repository.jboss.org</mirrorOf>
      </mirror>
   </mirrors>
</settings>

</post>

JBoss EAP 5 & Maven

  • JBoss Maven Java EE 5 Dependencies (link)
  • Configuring the Maven Ear Plugin for JBoss EAP 5 (link)
  • Integration Testing w/ Maven, Cargo, & JBoss EAP 5
  • Integration Testing w/ Maven, Arquillian, & JBoss EAP 5 (link)
  • JBoss EAP 5 Multi-Module Maven Project Structures (link)
  • JBoss Trading – Multi Module JBoss EAP 5 Project (link)
, ,

About Shane K Johnson

Technical Marketing Manager, Red Hat Inc.

View all posts by Shane K Johnson

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: