Testing the Maven project

Ok, you can test your project using the browser by pointing at the home page (home.xhtml)
http://localhost:8080/as7example/index.jsf
jboss maven tutorial
This will display a Welcome page with the user and password text fields. In the lower part of the GUI, you can access to the RESTful service address where you can query for the list of all members: http://localhost:8080/as7example/rest/members or of a single member http://localhost:8080/as7example/rest/members/0
In our example, it will deliver:
<collection>
            <member>
                    <email>This email address is being protected from spambots. You need JavaScript enabled to view it.</email>
                    <id>0</id>
                    <name>John Smith</name>
                    <phoneNumber>2125551212</phoneNumber>
            </member>
</collection>

Testing with Arquillian

The Member project ships also with a set of Arquillian test cases which can be used to test your application either on a local application server, or on a remotely running JBoss AS. Before running your Arquillian Test case we need to fix the Arquillian Container dependencies which need to point to the 1.0.0.CR7 release. So open up your pom.xml and fix it:

<dependency>
  <groupId>org.jboss.arquillian.junit</groupId>
  <artifactId>arquillian-junit-container</artifactId>
  <version>1.0.0.CR7</version>
<scope>test</scope>
</dependency>

Then in in your Arquillan configuration file (arquillian.xml) set up the JBoss Home which is needed if you plan to run the test on a remote JBoss AS 7 installation:
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://jboss.org/schema/arquillian
        http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

   <!-- Example configuration for a remote JBoss AS 7 instance -->
   <container qualifier="jboss" default="true">
      <protocol type="jmx-as7">
         <property name="executionType">REMOTE</property>
      </protocol>
      <configuration>
         <property name="jbossHome">C:\\jboss-as-7.1.1.Final</property>
      </configuration>
   </container>

</arquillian> 

That's all. The following Maven goal will test your project on a local AS 7
mvn -e clean test -Parq-jbossas-managed

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 14.58 sec

Results :

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

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.463s
[INFO] Finished at: Sun Apr 15 14:27:55 CEST 2012
[INFO] Final Memory: 18M/44M
[INFO] ------------------------------------------------------------------------
On the other hand, if you want to test on a remote AS 7 server, use the -Parq-jbossas-remote flag:
mvn -e clean test -Parq-jbossas-remote

 

So with this tutorial we have showed how to create a vanilla Java EE 6 project with Maven and how to import the Maven project into Eclipse. Maven allows a project to build using its project object model (POM) and a set of plugins that are shared by all projects using Maven, providing a uniform build system. Once you familiarize yourself with how one Maven project builds you automatically know how all Maven projects build saving you immense amounts of time when trying to navigate many projects.

0
0
0
s2sdefault

Related articles available on mastertheboss.com