Enterprise Java Development@TOPIC@

Chapter 92. Build Commands

92.1. Example Source Tree
92.2. Unit Tests
92.2.1. Resources Plugin
92.2.2. Surefire Plugin
92.3. Integration (IT) Tests
92.3.1. Cargo Plugin
92.3.2. Failsafe Plugin
92.4. Summary

Plugin Page

  • Copies resource files from src tree to target tree

  • Can optionally "filter" variables and replace them with build time values (from environment's settings.xml)

  • Useful in customizing environment-specific properties

    • server URLs

    • server port#s


  • Source file uses variables to template source file


  • Concrete values are put in place for specific environment


  • Properties defined either within pom.xml, settings.xml, or -Dsystem-properties

  • includes/exclused aids in filtering wrong files

  • avoid filtering binary files -- corrupts them (Ant has same issue)

Plugin Page

  • Runs unit tests

  • Runs after tests compiled and before IT tests


  • Plugin always enabled by default. Declaration used only to customize

  • Configuration defines environment for JVM

  • Easy way to supply system properties (-Dsystem-property=value)

  • values can be hard-coded or use properties to allow easier overrides


  • Useful when turning off all unit tests to concentrate on IT tests

  • Can turn off problem test(s)


  • Just defining version here

Figure 92.8. Run Unit Tests

$ mvn clean test

...
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ ejb-basic-ejb ---
...
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ejb-basic-ejb ---
...
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ejb-basic-ejb ---
...
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ejb-basic-ejb ---
...
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ ejb-basic-ejb ---
...
[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ ejb-basic-ejb ---

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running info.ejava.examples.ejb.basic.pojo.GreeterTest
02:11:38,695 INFO  (GreeterTest.java:41) -*** dto ***
02:11:38,701 DEBUG (GreeterEJB.java:45) -sayHello(Name [firstName=thing, lastName=one])
02:11:38,707 INFO  (GreeterTest.java:27) -*** pojoGreeter ***
02:11:38,708 DEBUG (GreeterEJB.java:31) -sayHello(cat inhat)
02:11:38,711 INFO  (GreeterTest.java:35) -*** badName ***
02:11:38,713 DEBUG (GreeterEJB.java:31) -sayHello()
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.238 sec - in info.ejava.examples.ejb.basic.pojo.GreeterTest

Results :

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.871 s

  • Just defining version here

Plugin Page

  • Manages deployment of components to containers

  • Not specific to JBoss/Wildfly

  • Specializations for Maven and JBoss/Wildfly

  • Can run embedded within each IT module build or use remote instance

  • Typically configured within module with IT tests


  • Plugin declaration enacts parent-defined behavior

  • Module specifies artifacts to deploy

  • Module specification is not required if deployment is self (i.e., the primary EJB/WAR/EAR produced by this module)


  • Used to simply undeploy module from server

  • Requires artifact to be present

  • Profile keeps behavior from running under conditions that would fail build

Figure 92.11. Parent Definition


<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>${cargo-maven2-plugin.version}</version>
            <configuration>
                <container>
                    <containerId>${cargo.containerId}</containerId>
                    <type>remote</type>
                    <log>target/server.log</log>
                    <output>target/output.log</output>
                </container>
                <configuration>
                    <type>runtime</type>
                    <properties>
                        <cargo.hostname>${jboss.mgmt.host}</cargo.hostname>
                        <cargo.jboss.management.port>${jboss.mgmt.port}</cargo.jboss.management.port>
                    </properties>
                </configuration>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.wildfly</groupId>
                    <artifactId>wildfly-controller-client</artifactId>
                    <version>${wildfly.version}</version>
                </dependency>
            </dependencies>
            <executions>
               <execution>
                   <id>cargo-prep</id> 
                       <phase>pre-integration-test</phase>
                   <goals>
                        <goal>redeploy</goal>
                   </goals>
               </execution>
                <execution>
                    <id>cargo-post</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>undeploy</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</pluginManagement>

  • Parent defines boiler-plate portion

  • Child will provide module-specific information


  • Builds a new packaged, deployable artifact

  • Deploys and leaves on server

  • (optional)-DskipTests bypasses any unit tests

  • Notice that build completes immediately after deploy with no IT tests or undeploy


  • Undeploys atifact from server

  • Useful in automating cleanup

  • -Pundeploy activates latched profile

Plugin Page

  • Runs integration (IT) tests

  • Must be declared, not configured in by default

  • Runs after deployer completes and prior to undeployer


  • Plugin definition causes IT tests to run

  • Configuration defines environment for JVM


  • Can turn off problem or lengthy test(s)


  • Defines version# and wires plugin into build phases when declared by child module

Figure 92.17. Run IT Tests



$ mvn clean verify

$ mvn clean verify
...
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ ejb-basic-test ---
...
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ejb-basic-test ---
...
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ejb-basic-test ---
...
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ejb-basic-test ---
...
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ ejb-basic-test ---
...
[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ ejb-basic-test ---
...
[INFO] --- maven-jar-plugin:2.5:jar (default-jar) @ ejb-basic-test ---
...
[INFO] --- cargo-maven2-plugin:1.4.3:redeploy (cargo-prep) @ ejb-basic-test ---
Oct 01, 2014 2:28:02 AM org.xnio.Xnio <clinit>
INFO: XNIO version 3.2.2.Final
Oct 01, 2014 2:28:02 AM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.2.2.Final
Oct 01, 2014 2:28:02 AM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.3.Final
...
[INFO] --- maven-failsafe-plugin:2.17:integration-test (integration-tests) @ ejb-basic-test ---

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
...

Results :

Tests run: 12, Failures: 0, Errors: 0, Skipped: 0
...
[INFO] --- cargo-maven2-plugin:1.4.3:undeploy (cargo-post) @ ejb-basic-test ---
...
[INFO] --- maven-failsafe-plugin:2.17:verify (verify) @ ejb-basic-test ---
...
-------------------------------------------------------
[INFO] BUILD SUCCESS


  • Runs all phases and stops just prior to installing into local repository

  • Cannot bypass unit tests (unless includes/excludes used)