4 Replies Latest reply on Aug 28, 2009 11:20 AM by ssilvert

    JSFUnitwar Ant Task

    mwringe

      I have committed an experimental JSFUnit ant task into the JSFUnit svn repository (org.jboss.jsfunit.ant.JSFUnitWarTask). I havn't done a lot of testing of all of its features yet, so its bounds to be a little bit buggy.

      The task acts a lot like the cactus cactifywar ant task, with a few more options:
      - it can handled exploded wars
      - it can automatically add the servlettestrunner filters to the war with the testrunner option.
      - option to automatically add required jars or not

      A couple of things that it doesn't do right now that cactus can do is adding roles and merging xml fragments. There is also no jsfunitear/jsfunitsar option yet.

      I am planning on writing a doc on how to use it and writing some tests for it soon.

      If anyone wants to get started with it right now, a sample use case is as follows:

       <jsfunitwar srcfile="${src.file}"
       destfile="${dest.file}">
       <TestRunner/>
       <lib ..../>
       <classes .../>
       </jsfunitwar>



        • 1. Re: JSFUnitwar Task
          ssilvert

          Cool. Can't wait to try it out.

          Stan

          • 2. Re: JSFUnitwar Ant Task
            ssilvert

            In case anybody wants a quick example, I created an ant script to try this out. I created this very simple directory structure:

            /sourcewar
            /destwar
            /lib

            I put jboss-jsfunit-examples-hellojsf-webapp.war in the /sourcwar directory.

            I put all the jars in the /lib directory.

            build.xml is in the root. Here is what it looks like:

            <?xml version="1.0" encoding="UTF-8"?>
            
            <project name="TestJSFUnitWar" default="default" basedir=".">
             <description>Tests the jsfunitwar ant task.</description>
            
             <property name="src.war.dir" location="${basedir}/sourcewar"/>
             <property name="src.war" location="${src.war.dir}/jboss-jsfunit-examples-hellojsf-webapp.war"/>
             <property name="dest.war.dir" location="${basedir}/destwar"/>
             <property name="dest.war" location="${dest.war.dir}/my-jsfunit-test.war"/>
            
             <property name="lib.dir" location="${basedir}/lib"/>
            
             <!-- Libraries required for jsfunitwar ant task -->
             <property name="jsfunit.ant.jar" location="${lib.dir}/jboss-jsfunit-ant-1.0-SNAPSHOT.jar"/>
             <property name="aspectjrt.jar" location="${lib.dir}/aspectjrt-1.2.1.jar"/>
             <property name="jsfunit.jar" location="${lib.dir}/jboss-jsfunit-core-1.0-SNAPSHOT.jar"/>
             <property name="cactus.jar" location="${lib.dir}/cactus-13-1.7.1.jar"/>
             <property name="cactus.ant.jar" location="${lib.dir}/cactus-ant-13-1.7.1.jar"/>
             <property name="httpunit.jar" location="${lib.dir}/httpunit-1.6.1.jar"/>
             <property name="junit.jar" location="${lib.dir}/junit-3.8.1.jar"/>
             <property name="jtidy.jar" location="${lib.dir}/jtidy-4aug2000r7-dev.jar"/>
             <property name="cargo.jar" location="${lib.dir}/cargo-0.5.jar"/>
            
            
             <path id="jsfunit.classpath">
             <pathelement location="${jsfunit.ant.jar}"/>
             <pathelement location="${aspectjrt.jar}"/>
             <pathelement location="${cactus.jar}"/>
             <pathelement location="${cactus.ant.jar}"/>
             <pathelement location="${jsfunit.jar}"/>
             <pathelement location="${junit.jar}"/>
             <pathelement location="${jtidy.jar}"/>
             <pathelement location="${cargo.jar}"/>
             <pathelement location="${httpunit.jar}"/>
             </path>
            
             <taskdef name="jsfunitwar"
             classname="org.jboss.jsfunit.ant.JSFUnitWarTask"
             classpathref="jsfunit.classpath"/>
            
             <target name="default" depends="make.jsfunit.war">
             </target>
            
             <target name="clean">
             <delete dir="${dest.war.dir}"/>
             <mkdir dir="${dest.war.dir}"/>
             </target>
            
             <target name="make.jsfunit.war" depends="clean">
             <jsfunitwar srcfile="${src.war}"
             destfile="${dest.war}">
             <TestRunner/>
             </jsfunitwar>
             </target>
            
            </project>
            


            Stan Silvert
            http://www.jsfunit.org

            • 3. Re: JSFUnitwar Ant Task
              slabside

              I wonder if anyone can help me....
              When I run my build.xml i get the error:

              jsfunit.war:
              [jsfunitwar] Automatically adding JSFunit required jars to the new war
              [jsfunitwar] Could not find the JSFUnit jar in the classpath. Cannot automatically add this jar to the war
              [jsfunitwar] Could not find the AspectJ jar in the classpath. Cannot automatically add this jar to the war
              [jsfunitwar] Could not find the Cactus jar in the classpath. Cannot automatically add this jar to the war
              [jsfunitwar] Could not find the HttpUnit jar in the classpath. Cannot automatically add this jar to the war
              [jsfunitwar] Could not find the JUnit jar in the classpath. Cannot automatically add this jar to the war
              [jsfunitwar] Could not find the NekoHTML jar in the classpath. Cannot automatically add this jar to the war
              [jsfunitwar] Could not find the JTidy jar in the classpath. Cannot automatically add this jar to the war

              The jars reside in a c:/jsfunit-jars dir and the script is loading them from there

              Oddly, I am also including pathelement location="${cargo.jar}" but the error does not mention this jar.

              I'm fairly inexpirienced with ant and brand new to JSF....

              Thanks for listening guys, any help greatly appreciated

              slabside

              the script looks like this:

              <project name="JSFUnit" default="jsfunit.war" basedir=".">
              <property name="work.files" value="${basedir}/workingfiles" />
              <property name="target.dir" value="${work.files}/CST/Applications/Desktop-Applications/cst-bankdetails-war/target"/>
              <property name="src.dir" value="${target.dir}" />
              <property name="lib.dir" value="${basedir}/jsfunit-jars" />
              <property name="cst.war" value="${target.dir}/cst-bankdetails-war" />
              <property name="jsf.cst.war" value="${work.files}/jsfunit-war" />
              <property name="jsf.test.classes" value="${src.dir}/classes/uk/co/slc/cst/jsfunit" />
              
              <property name="aspectjrt.jar" location="${lib.dir}/aspectjrt-1.2.1.jar"/>
              <property name="cactus.jar" location="${lib.dir}/cactus-13-1.7.1.jar"/>
              <property name="httpunit.jar" location="${lib.dir}/httpunit-1.6.1.jar"/>
              <property name="junit.jar" location="${lib.dir}/junit-3.8.1.jar"/>
              <property name="jtidy.jar" location="${lib.dir}/jtidy-4aug2000r7-dev.jar"/>
              <property name="cargo.jar" location="${lib.dir}/cargo-0.6.jar"/>
              <property name="jboss-jsfunit-core.jar" location="${lib.dir}/jboss-jsfunit-core-1.0.0.Beta2.jar"/>
              <property name="nekohtml.jar" location="${lib.dir}/nekohtml-0.9.1.jar"/>
              
              <target name="jsfunit.war">
              
               <path id="jsfunit.classpath">
               <pathelement location="${aspectjrt.jar}"/>
               <pathelement location="${cactus.jar}"/>
               <pathelement location="${httpunit.jar}"/>
               <pathelement location="${junit.jar}"/>
               <pathelement location="${jtidy.jar}"/>
               <pathelement location="${cargo.jar}"/>
               <pathelement location="${jboss-jsfunit-core.jar}"/>
               <pathelement location="${nekohtml.jar}"/>
               </path>
              
               <taskdef
               name="jsfunitwar"
               classname="org.jboss.jsfunit.ant.JSFUnitWarTask"
               classpathref="jsfunit.classpath"/>
              
               <jsfunitwar srcfile="${cst.war}" destfile="${jsf.cst.war}">
               <classes dir="${jsf.test.classes}"
               includes="**/*.class">
               </classes>
              
               <TestRunner/>
               </jsfunitwar>
              </target>
              </project>
              


              • 4. Re: JSFUnitwar Ant Task
                ssilvert

                You are probably using a new version of JSFUnit with old jars. For instance, I see that your script references old jars like jboss-jsfunit-core-1.0.0.Beta2.jar and nekohtml-0.9.1.jar. The JSFUnit 1.1 Ant task will be looking for the newer version of the jars.

                See http://labs.jboss.com/jsfunit/gettingstarted.html for a listing of the jar versions you need to use with JSFUnit 1.1.

                Stan