Monday, December 17, 2012

Tutorial EJB3 Integration Test with Arquillian part2 - JBoss 7 remote container


Document  Version 1.0

When you have followed the part1 of this serial "Tutorial Integration test with Arquillian" with success, your system would have been correctly set up to run further Arquillian test, - with some samll adaptions depending upon the container you are planning to use.

In this part2 of the serial we will continue with part1, to test stateless session bean in a JBoss 7 remote container. Instead of reusing the  "testarq_jb7_managed" Eclipse project we created in part1, we will create a new Eclipse project "testarq_jb7_remote", reuse the EJB classes and the test class.

1. Create a simple Maven project in Eclipse

Follow the section 1 of "EJB3 Integration Test with Arquillian part1-JBoss 7 managed container" to create a new Eclipse project ""testarq_jb7_remote". Be sure in step2, to name the ArtifactId as ""testarq_jb7_remote".

2. Create project's pom.xml file.

Replace the content of pom.xml file with the following content:


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testarg</groupId>
<artifactId>testarq_jb7_remote</artifactId>
<version>0.0.1</version>
<description>test arrquillian</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.0.3.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>arquillian-jbossas-remote_7</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-remote</artifactId>
<version>7.1.1.Final</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>

3. Implement source code and test code

Follow the section 3 of "EJB3 Integration Test with Arquillian part1-JBoss 7 managed container" to create the 2 classes for Hallo EJB and test class:

    HalloEjbLocal.java
    HalloEjb.java
    TestHalloEJB.java

4. Start JBossjboss-as-7.1.1.Final

Again here make sure you have system property PATH including "bin" folder of you jdk7 location,  and JAVA_HOME pointing to jkd7 installation location.

Unlike doing Arquillian test with managed container, where Arquillian takes care of start and stop of remote server. When running with Arquillian with remote server, before starting test, the remote server must be already started and up.

Start JBoss7 in standalone mode:


he@linux-7s1k:~/jboss-as-7.1.1.Final/bin> ./standalone.sh

======================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: /home/he/jboss-as-7.1.1.Final

  JAVA: /var/jdk7/bin/java

  JAVA_OPTS:  -server -XX:+TieredCompilation -Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -Djboss.server.default.config=standalone.xml

======================================================================


5. arquillian.xml

In case of remote JBoss container, Arquillian needs 2 extra parameters: managementAddress managementPort.
Arquillian use default "127.0.0.1:9999",  if no configuration is found.
If your server is running on different management host/port, then the 2 parameters should be configured in arquillian.xml



<container qualifier="jboss7" default="true">
    <configuration>
      <property name="managementAddress">127.0.0.1</property>
      <property name="managementPort">9999</property>
    </configuration>
  </container>



6. Run Arquillian test

Create a Ecliipse Run configuration for Maven as shown in the following image:


An Click Run button.

When you have correctly followed the section 1-6, you would see in you console a screen likes:


When you take a look at the JBoss 7 log file, you would see the "halloEjb.jar" is deployed at the beginning of the test, and undeployed from JBoss when the test is finished:



...
20:25:04,190 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "halloEjb.jar"
...
20:25:04,338 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named HalloEjb in deployment unit deployment "halloEjb.jar" are as follows:
        java:global/halloEjb/HalloEjb!test.ejb.HalloEjbLocal
        java:app/halloEjb/HalloEjb!test.ejb.HalloEjbLocal
        java:module/HalloEjb!test.ejb.HalloEjbLocal
        java:global/halloEjb/HalloEjb
        java:app/halloEjb/HalloEjb
        java:module/HalloEjb
...
20:25:05,142 INFO  [org.jboss.as.server] (management-handler-thread - 2) JBAS018559: Deployed "halloEjb.jar"
20:25:06,750 INFO  [org.jboss.weld.deployer] (MSC service thread 1-1) JBAS016009: Stopping weld service for deployment halloEjb.jar
....
20:25:07,152 INFO  [org.jboss.as.server] (management-handler-thread - 1) JBAS018558: Undeployed "arquillian-service"
...


7. Troubleshooting

7.1 When you see test failure like:



...
Tests in error:
  test.ejb.TestHalloEJB: Could not create a new instance of class org.jboss.arquillian.test.impl.EventTestRunnerAdaptor
....
Caused by: java.lang.NoClassDefFoundError: org/jboss/arquillian/test/spi/enricher/resource/ResourceProvider
...
Caused by: java.lang.RuntimeException: Could not create a new instance of class org.jboss.arquillian.core.impl.ManagerImpl see cause.
...


This is most possibly because the "aqruillian.bom" version is not compatible with the "jboss-as-arquillian-container-remote" version. Please make sure you used the version shown in the pom.xml of this tutorial.

7.2  When you see test failure like:



...
org.jboss.shrinkwrap.api.exporter.ArchiveExportException: Failed to write asset to output: /junit/extensions/TestDecorator.class
...
Caused by: java.io.IOException: Pipe closed
...
Possible deadlock scenario: Got exception on closing the ZIP out stream: Pipe closed
...
Failed to write asset to output: /test/ejb/TestHalloEJB.class
...

Tests in error:
  test.ejb.TestHalloEJB: Could not deploy to container: JBAS012144: Could not connect to remote://127.0.0.1:9999. The connection timed out
...



This normally indicates that the JBoss server is not running, or it runs with different "managementAddress" or "managementPort" than default. Please check your configuration against the section 5 of this tutorial.


Tutorial EJB3 Integration Test with Arquillian part3 - JBoss 5 managed container






1 comment: