Skip to main content

Testing with a specific JSF version on Glassfish using HtmlUnit and Maven

Posted by mriem on January 5, 2012 at 10:04 PM PST

 In the previous article we described how to do testing with multiple containers. But since joining
the Glassfish team I have wondered how can I test applications against different versions of JSF on Glassfish?

As it turns out it is actually quite straightforward. This blog entry shows you how to do it. It will
allow you to test using a 2.1.2 version and up. All by using properties passed in on the command line.

Download the attachment at the end of the article and follow along. We are going the use the
maven-dependency-plugin to copy the javax.faces.jar into the Glassfish installation we are using
for testing.

  <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>${jsf.groupId}</groupid>
      <artifactid>${jsf.artifactId</artifactId>
              <version>${jsf.version}</version>
              <type>jar</type>
              <overwrite>true</overwrite>                                    
              <outputdirectory>${integration.container.installDir}/glassfish-${glassfish.version}/glassfish3/glassfish/modules</outputdirectory>
              <destfilename>javax.faces.jar</destfilename>
            </artificatitem>
          </artificatitems>
          <overwritereleases>true</overwritereleases>
          <overwritesnapshots>true</overwritesnapshots>
        </configuration>
      </execution>
     <executions>
   </plugin>

The above mentioned plugin copies the javax.faces.jar file into the Glassfish modules directory during the package phase. This is well before the integration phase so we are sure we have the JSF runtime we want to use.

By using -Djsf.version=2.1.6 on the commandline you would test against Mojarra version 2.1.6. Note that the POM file also requires you to pass in the Glassfish version you are using. This is a little quirk in how Cargo installs the container. So a complete command line could look very similar to the one below.

  mvn -Dintegration.skip=false -Dintegration.container.skip=false 
  -Dintegration.container.downloadUrl=http://dlc.sun.com.edgesuite.net/glassfish/3.1.2/promoted/glassfish-3.1.2-b15.zip
  -Dintegration.container.installDir=/tmp/cargo/install/glassfish3.1.2
  -Dintegration.container.runtimeDir=/tmp/cargo/runtime/glassfish3.1.2
  -Dintegration.container.type=existing -Dglassfish.version=3.1.2-b15
  -Djsf.version=2.1.6 clean verify

I hope you liked this article! Let me know what you think, or if you have any suggestions about other content, or if you just want to drop me a note, feel free to do so :)

AttachmentSize
htmlunit5.zip16.62 KB
Related Topics >>