Red Hat
Nov 16, 2014
by arungupta

Tech Tip #34 explained how to create a testable Java EE 7 application. This is useful if you are starting a new application. But what if you already have an application and Arquillian-enable it ?

That’s where Forge and Forge-Arquillian add-on comes in handy. That’s how I added support for Arquillian in javaee7-simple-sample.

Lets see what was done!

  1. Download and install Forge. You can download ZIP and unzip in your favorite location, or just use the following command that does it for you:
    Downloads&gt; <strong>curl http://forge.jboss.org/sh | sh</strong>
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  2725    0  2725    0     0   4641      0 --:--:-- --:--:-- --:--:--  4642
    /usr/bin/java
    Downloading Forge
    ######################################################################## 100.0%
    Archive:  /Users/arungupta/.forge/forge_installer.zip
       creating: /Users/arungupta/forge/forge-distribution-2.12.2.Final/
       creating: /Users/arungupta/forge/forge-distribution-2.12.2.Final/img/
    
    . . .
    
    If you have not yet seen the Forge built-in commands, you may either press TAB to see a list of the currently available commands, or get a more descriptive list by typing:
    
    $ command-list
    
    Then to get started - see the docs at
    http://forge.jboss.org/documentation 
    Consider installing Git and Maven 3.1+ (both optional)
    
    Restart Terminal to use forge.
  2. Clone the simple-javaee7-sample repo
    git clone https://github.com/javaee-samples/javaee7-simple-sample.git
  3. Change the directory to javaee7-simple-sample and start Forge:
    javaee7-simple-sample&gt; <strong>~/tools/forge-distribution-2.12.2.Final/bin/forge</strong> 
    Using Forge at /Users/arungupta/tools/forge-distribution-2.12.2.Final
    
        _____                    
       |  ___|__  _ __ __ _  ___ 
       | |_ / _ \| `__/ _` |/ _ \  \\
       |  _| (_) | | | (_| |  __/  //
       |_|  \___/|_|  \__, |\___| 
                       |__/      
    
    JBoss Forge, version [ 2.12.2.Final ] - JBoss, by Red Hat, Inc. [ http://forge.jboss.org ]
  4. Install the Forge-Arquillian add-on:
    [javaee7-simple-sample]$ <strong>addon-install-from-git --url https://github.com/forge/addon-arquillian.git</strong>
    ***INFO*** Installing Addon from Git 	[0/4] ...
    ***INFO*** Installing Addon from Git:Cloning repository in /var/folders/3v/syxsk5zx3yqd_8g9m206py_h0000gn/T/1416131293813-0 	[0/4] ...
    ***INFO*** Installing Addon from Git:Installing project into local repository 	[1/4] ...
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Arquillian Forge Addon 1.0.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    
    . . .
    
    Downloading: http://repo1.maven.org/maven2/org/jboss/forge/addon/maven-impl-projects/2.12.2.Final/maven-impl-projects-2.12.2.Final.pom
    Downloaded: http://repo1.maven.org/maven2/org/jboss/forge/addon/maven-impl-projects/2.12.2.Final/maven-impl-projects-2.12.2.Final.pom (4 KB at 16.9 KB/sec)
    ***SUCCESS*** Addon org.arquillian.forge:arquillian-addon,1.0.0-SNAPSHOT was installed successfully.
  5. Configure Arquillian add-on and install WildFly adapter:
    [javaee7-simple-sample]$ arquillian-setup --testFramework junit --containerAdapter wildfly-remote 
    Downloading: http://repo1.maven.org/maven2/org/wildfly/wildfly-arquillian-container-remote/maven-metadata.xml
    Downloaded: http://repo1.maven.org/maven2/org/wildfly/wildfly-arquillian-container-remote/maven-metadata.xml (702 B at 4.2 KB/sec)
    ***SUCCESS*** Arquillian setup complete
    ***SUCCESS*** Installed Arquillian 1.1.5.Final
    ***SUCCESS*** Installed junit
    ***SUCCESS*** Installed Arquillian Container WildFly Remote 8.x
    ***SUCCESS*** Installed Arquillian Container WildFly Remote 8.x dependencies

    The list of adapters is diverse as shown:
    glassfish-embedded-3.1       jetty-embedded-6.1           tomee-remote                 
    glassfish-managed-3.1        jetty-embedded-7             was-embedded-8               
    glassfish-remote-3.1         openejb-embedded-3.1         was-remote-7                 
    jbossas-embedded-6           openejb-embedded-4           was-remote-8                 
    jbossas-managed-4.2          openshift-express            weld-ee-embedded-1.1         
    jbossas-managed-5.1          openwebbeans-embedded-1      weld-se-embedded-1           
    jbossas-managed-6            tomcat-embedded-6            weld-se-embedded-1.1         
    jbossas-managed-7            tomcat-embedded-7            wildfly-managed              
    jbossas-remote-4.2           tomcat-managed-5.5           wildfly-remote               
    jbossas-remote-5             tomcat-managed-6             wls-remote-10.3              
    jbossas-remote-5.1           tomcat-managed-7             
    jbossas-remote-6             tomcat-remote-6

    This allows you to configure the container of your choice.
  6. Until FORGE-2148 is fixed, you also need to add a JAX-RS implementation as well, and the corresponding JAXB provider. This test is using RESTEasy and so the following needs to be added:
    &lt;dependency&gt;
        &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
        &lt;artifactId&gt;resteasy-client&lt;/artifactId&gt;
        &lt;version&gt;3.0.5.Final&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
        &lt;dependency&gt;
        &lt;groupId&gt;org.jboss.resteasy&lt;/groupId&gt;
        &lt;artifactId&gt;resteasy-jaxb-provider&lt;/artifactId&gt;
        &lt;version&gt;3.0.5.Final&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;

And now you are ready to test!

Download WildFly 8.1 and unzip. Start the server as:

./bin/standalone.sh

Run the tests:

javaee7-simple-sample&gt; mvn test
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building helloworld 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ helloworld ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ helloworld ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ helloworld ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ helloworld ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.14.1:test (default-test) @ helloworld ---
[INFO] Surefire report directory: /Users/arungupta/workspaces/javaee7-simple-sample/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.javaee7.sample.PersonTest
Nov 16, 2014 1:53:57 PM org.xnio.Xnio 
INFO: XNIO version 3.2.0.Beta4
Nov 16, 2014 1:53:57 PM org.xnio.nio.NioXnio 
INFO: XNIO NIO Implementation Version 3.2.0.Beta4
Nov 16, 2014 1:53:57 PM org.jboss.remoting3.EndpointImpl 
INFO: JBoss Remoting version (unknown)
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.963 sec

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.403 s
[INFO] Finished at: 2014-11-16T13:53:59+02:00
[INFO] Final Memory: 17M/309M
[INFO] ------------------------------------------------------------------------

And now you’ve Arquillian-enabled your existing project!

File any issues here.

Enjoy!

Original Post