1 2 Previous Next 22 Replies Latest reply on Feb 15, 2008 7:51 AM by steve alex

    ANT

    steve alex Newbie

      hi

      what is JSFUnitWarTask about...and i also don't understand what is this code in the url http://anonsvn.jboss.org/repos/jsfunit/trunk/jboss-jsfunit-ant/src/main/java/org/jboss/jsfunit/ant/JSFUnitWarTask.java

      and can we write build script using ANT for JSFUnit ( for the automation of tests)

      or can you suggest me some way to automate my testcases.


      thanks

        • 1. Re: ANT
          Stan Silvert Master

          Yes, you definitely can and should automate your JSFUnit tests!

          JSFUnitWarTask takes an ordinary WAR and "JSFUnifies" it. It automatically adds the JSFUnit jars, your JSFUnit tests, and it updates your web.xml so that the WAR is ready for JSFUnit tests.

          So you can build your JSF WAR normally and then run JSFUnitWarTask against it. See http://wiki.jboss.org/wiki/JSFUnitWithAnt

          If you want to use Maven for your build see http://wiki.jboss.org/wiki/JSFUnitWithMaven

          JSFUnit uses Apache Cactus for kicking off the tests. So it is good to become familiar with Cactus. http://jakarta.apache.org/cactus/

          On the Cactus site, you will find a task called "Cactify". This is very similar to JSFUnitWarTask.

          So with Ant or Maven you are able to take your regular build for your WAR, create a new "JSFUnified" WAR and run your tests - all in one command. The JSFUnit build does this using Maven. We even have an automated build set up with Hudson that builds all of JSFUnit and its examples. Then it runs all the tests against a servlet container that is started and stopped as part of this build. See http://hudson.qa.jboss.com/hudson/job/JSFUnit/

          Using the examples on the Cactus site, you should be able to figure out how to do it with Ant as well.

          Regards,

          Stan

          • 2. Re: ANT
            steve alex Newbie

            Hi stan

            i have followed this link
            http://www.jboss.com/index.html?module=bb&op=viewtopic&t=115623

            and created three folders and then placed my application war in source all libs regarding my application in lib and when i try to run the sample script given my you..i can see the build successful but cannot see the testcases....failed or success..can you help me out

            Thanks

            • 3. Re: ANT
              Stan Silvert Master

              All I show in that example is creating the "JSFUnified" war. In other words, you end up with a war capable of running JSFUnit tests.

              Next, your ant script needs to:
              1) Start the servlet container
              2) Deploy the war
              3) Run your JUnit tests (they will automatically send requests to the Cactus ServletRedirector on your server. That's where the tests are actually run)
              4) Stop the servlet container

              There are several ways to do this in Ant. Cactus has instructions and helpful ant tasks here:
              http://jakarta.apache.org/cactus/integration/ant/index.html

              In Maven, we use Cargo for start/deploy/stop and we use Surefire for running the tests. Cargo also has Ant tasks.
              http://cargo.codehaus.org/Ant+support

              Once you get this all automated with Ant, I'd really appreciate if you updated this wiki page with whatever you learn:
              http://wiki.jboss.org/wiki/JSFUnitWithAnt

              Stan

              • 4. Re: ANT
                steve alex Newbie

                Hi

                jsfunified war is not created in the destination folder and it's giving this exception

                java.io.FileNotFoundException: C:\DOCUME~1\admin\LOCALS~1\Temp\jsfunitwartask63736\jsfunittest.war\WEB-INF\lib\xalan.jar <The system cannot find the path specified>
                


                but the build was successful
                and
                3) Run your JUnit tests (they will automatically send requests to the Cactus ServletRedirector on your server. That's where the tests are actually run)



                you mean to say JSFUnit tests right
                can you help me out

                • 5. Re: ANT
                  Matt Wringe Master

                   

                  "kingkon" wrote:
                  Hi

                  jsfunified war is not created in the destination folder and it's giving this exception

                  java.io.FileNotFoundException: C:\DOCUME~1\admin\LOCALS~1\Temp\jsfunitwartask63736\jsfunittest.war\WEB-INF\lib\xalan.jar <The system cannot find the path specified>
                  


                  but the build was successful


                  can you give some more information, that one line error doesn't says much. The build should have failed if the war is not being created.

                  • 6. Re: ANT
                    steve alex Newbie

                     

                    Buildfile: build.xml
                    Overriding previous definition of reference to jsfunit.classpath
                    
                    make.jsfunit.war:
                     [echo] D:\try\JSFUnitWarTask\sourcewar\jsfunittest.war
                    [jsfunitwar] java.io.FileNotFoundException: C:\DOCUME~1\admin\LOCALS~1\Temp\j
                    sfunitwartask63736\jsfunittest.war\WEB-INF\lib\xalan.jar (The system cannot find the pa
                    th specified)
                    [jsfunitwar] at java.io.FileOutputStream.open(Native Method)
                    [jsfunitwar] at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
                    [jsfunitwar] at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
                    [jsfunitwar] at org.jboss.jsfunit.ant.Utils.unzip(Utils.java:114)
                    [jsfunitwar] at org.jboss.jsfunit.ant.Utils.explodeArchive(Utils.java:262)
                    [jsfunitwar] at org.jboss.jsfunit.ant.JSFUnitWarTask.JSFUnitWar(JSFUnitWarTas
                    k.java:340)
                    [jsfunitwar] at org.jboss.jsfunit.ant.JSFUnitWarTask.execute(JSFUnitWarTask.j
                    ava:233)
                    [jsfunitwar] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.ja
                    va:275)
                    [jsfunitwar] at org.apache.tools.ant.Task.perform(Task.java:364)
                    [jsfunitwar] at org.apache.tools.ant.Target.execute(Target.java:341)
                    [jsfunitwar] at org.apache.tools.ant.Target.performTasks(Target.java:369)
                    [jsfunitwar] at org.apache.tools.ant.Project.executeSortedTargets(Project.jav
                    a:1216)
                    [jsfunitwar] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
                    
                    [jsfunitwar] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(De
                    faultExecutor.java:40)
                    [jsfunitwar] at org.apache.tools.ant.Project.executeTargets(Project.java:1068
                    )
                    [jsfunitwar] at org.apache.tools.ant.Main.runBuild(Main.java:668)
                    [jsfunitwar] at org.apache.tools.ant.Main.startAnt(Main.java:187)
                    [jsfunitwar] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
                    [jsfunitwar] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
                    
                    BUILD SUCCESSFUL


                    • 7. Re: ANT
                      Stan Silvert Master

                       

                      "kingkon" wrote:
                      Hi
                      you mean to say JSFUnit tests right
                      can you help me out


                      JSFUnit tests are JUnit/Cactus tests. What I meant was that once the WAR is deployed, you run the JSFUnit tests from your ant script in the same way that you would run JUnit. The idea is that because JSFUnit tests extend the Cactus ServletTestCase, it knows how to redirect the calls to Cactus' ServletRedirector inside your running container. See the Apache Cactus site for more details about how this works: http://jakarta.apache.org/cactus/how_it_works.html

                      As for your problem with the ant task, I'll ping Matt again and see if he can help you. He's the one who wrote the code for it.

                      Thanks,

                      Stan

                      • 8. Re: ANT
                        Matt Wringe Master

                         


                        [echo] D:\try\JSFUnitWarTask\sourcewar\jsfunittest.war
                        [jsfunitwar] java.io.FileNotFoundException: C:\DOCUME~1\admin\LOCALS~1\Temp\j
                        sfunitwartask63736\jsfunittest.war\WEB-INF\lib\xalan.jar (The system cannot find the pa
                        th specified)


                        What should be happening is that the war is exploded, every jar entry in the war is copied from the war into a temporary directoty. But something strange is happening in this case.
                        What is happening here is that it sees that /WEB-INF/lib/xalan.jar exists as an entry in the jar, it then tells the program to copy the jar entry to the temp directory. But it can't seem to find the location of where to copy the file.

                        A couple of questions:

                        1) what is contained in the temp directory after the failure?
                        2) what does 'jar -tf jsfunittest.war' output? (note I am only interested to see if WEB-INF/ WEB-INF/lib and WEB-INF/lib/xalan.jar are present, so no need to paste the whole content here).


                        • 9. Re: ANT
                          steve alex Newbie

                          here i am sending my script

                          <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}/unit.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"/>
                          
                           <property name="build.dir" location="${basedir}/classes/test"/>
                          
                           <!-- Libraries required for jsfunitwar ant task -->
                          
                           <property name="jsfunit.ant.jar" location="${lib.dir}/jboss-jsfunit-ant-1.0-beta-1.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-beta-1.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"/>
                           <property name="jsfunitclass" location="${build.dir}"/>
                          
                          
                           <path id="jsfunit.classpath">
                          
                           <fileset dir="${lib.dir}">
                           <include name="*.jar"/>
                           </fileset>
                           <!--<fileset dir="${lib.dir}">
                           <include name="aspectjrt-1.2.1.jar"/>
                           </fileset>-->
                           </path>
                          
                           <taskdef name="jsfunitwar"
                           classname="org.jboss.jsfunit.ant.JSFUnitWarTask"
                           classpathref="jsfunit.classpath"/>
                          
                           <taskdef name="jsfunit"
                           classname="com.foo.JSFUnitTest"
                           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.testwar" >
                           <echo> ${src.war}</echo>
                           <echo>${lib.dir}</echo>
                           <jsfunitwar srcfile="${src.war}"
                           destfile="${dest.war}">
                           <classes dir="${build.dir}" includes="JSFUnitTest.class"/>
                           <lib dir="{lib.dir}"/>
                           <TestRunner/>
                          
                           </jsfunitwar>
                          
                           <jsfunit warfile="${dest.war}" printsummary="yes"
                           failureproperty="tests.failed" showoutput="yes">
                          
                           <containerset>
                          
                           <tomcat6x dir="C:\Program Files\Apache Software Foundation\Tomcat 6.0"
                           port="8080"/>
                           </containerset>
                           <test name="JSFUnitTest">
                           <formatter type="plain"/>
                           </test>
                          </jsfunit>
                           </target>
                          
                          </project>
                          




                          and when i run ant

                          right now i am getting this error

                          Buildfile: build.xml
                          No public execute() in class com.foo.JSFUnitTest
                          
                          BUILD FAILED
                          D:\try\JSFUnitWarTask\build.xml:56: No public execute() in class com.foo.JSFUnit
                          Test



                          and tell me how to run the test cases in this jsfunitwar tag..becoz itz not supporting the batchtest attribute

                          Thanks


                          • 10. Re: ANT
                            Matt Wringe Master

                            so the classnotfoundexception is now gone?


                            Buildfile: build.xml
                            No public execute() in class com.foo.JSFUnitTest

                            BUILD FAILED
                            D:\try\JSFUnitWarTask\build.xml:56: No public execute() in class com.foo.JSFUnit
                            Test


                            this means something is wrong with your com.foo.JSFUnitTest, are you sure this should be an ant task?



                            • 11. Re: ANT
                              kumar kumar Newbie

                              Hi

                              have you seen my script ....is that the way we need to automate the testcases...JSFUnitTest contains my testcases

                              public class JSFUnitTest extends ServletTestCase {
                              
                               public static Test suite(){
                              
                               return new TestSuite(JSFUnitTest.class);
                              
                               }
                              ublic void testInitialPage() throws IOException,SAXException
                               {
                              
                               //sends HTTP request for initial page
                               JSFClientSession client = new JSFClientSession("/index.faces");
                              
                               //gives you access to JSF state
                               JSFServerSession server = new JSFServerSession(client);
                              
                              
                               //Tests navigation to initial viewID
                               assertEquals("/index.jsp",server.getCurrentViewID());
                              
                               //asserts that prompt is in component tree and rendered
                               UIComponent prompt = server.findComponent("prompt");
                              
                               assertTrue(prompt.isRendered());
                              
                               }
                              
                              public void testJSFPerformance() throws IOException,SAXException
                               {
                               JSFClientSession client = new JSFClientSession("/index.faces");
                               client.setParameter("input_foo_text","dsafjdjk dsfafdajf");
                               client.submit("submit_button");
                               JSFTimer timer = JSFTimer.getTimer();
                               assertTrue(timer.getTotalTime()<100);
                               }
                              }



                              my class look like this...can you help me out

                              Thanks

                              • 12. Re: ANT
                                steve alex Newbie




                                A couple of questions:
                                
                                1) what is contained in the temp directory after the failure?
                                2) what does 'jar -tf jsfunittest.war' output? (note I am only interested to see if WEB-INF/ WEB-INF/lib and WEB-INF/lib/xalan.jar are present, so no need to paste the whole content here).



                                Answers


                                1.
                                the folder is empty


                                2.
                                java.io.FileNotFoundException: unit.war (The system cannot find the file specifi
                                ed)
                                 at java.io.FileInputStream.open(Native Method)
                                 at java.io.FileInputStream.<init>(FileInputStream.java:106)
                                 at java.io.FileInputStream.<init>(FileInputStream.java:66)
                                 at sun.tools.jar.Main.run(Main.java:205)
                                 at sun.tools.jar.Main.main(Main.java:1022)




                                This is the script i am running
                                <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}/unit.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"/>
                                
                                 <property name="build.dir" location="${basedir}/classes/test"/>
                                
                                 <!-- Libraries required for jsfunitwar ant task -->
                                
                                 <property name="jsfunit.ant.jar" location="${lib.dir}/jboss-jsfunit-ant-1.0-beta-1.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-beta-1.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"/>
                                 <property name="jsfunitclass" location="${build.dir}"/>
                                
                                
                                 <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}"/>
                                 <pathelement location="${jsfunitclass}"/>
                                
                                 <fileset dir="${lib.dir}">
                                 <include name="*.jar"/>
                                 </fileset>
                                </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">
                                 <echo> ${src.war}</echo>
                                 <echo>${lib.dir}</echo>
                                 <war destfile="${dest.war}"
                                 webxml="D:\Backup\jsfunit\WebContent\WEB-INF\web.xml">
                                 <classes dir="${build.dir}"/>
                                 <lib dir="${lib.dir}"/>
                                 </war>
                                 <jsfunitwar srcfile="${src.war}"
                                 destfile="${dest.war}">
                                
                                 <classes dir="${build.dir}" includes="com.foo.JSFUnitTest"/>
                                 <lib dir="{lib.dir}"/>
                                 <TestRunner mapping="/ServletTestRunner" servletClass="com.foo.JSFUnitTest" />
                                 </jsfunitwar>
                                
                                 </target>
                                </project>



                                Help me out..

                                • 13. Re: ANT
                                  Matt Wringe Master

                                   

                                  "pa1_9" wrote:

                                  have you seen my script ....is that the way we need to automate the testcases...JSFUnitTest contains my testcases
                                  ....
                                  [


                                  Buildfile: build.xml
                                  No public execute() in class com.foo.JSFUnitTest
                                  
                                  BUILD FAILED
                                  D:\try\JSFUnitWarTask\build.xml:56: No public execute() in class com.foo.JSFUnit
                                  Test


                                  This error is because you have not setup the com.foo.JSFUnitTest to be a proper ant tasks, as ant task needs to have a public execute() method.
                                  Please read the ant manual to determine how to write a proper ant task http://ant.apache.org/manual/index.html there is a tutorial there on how to write ant tasks

                                  • 14. Re: ANT
                                    Matt Wringe Master

                                     

                                    "kingkon" wrote:


                                    1. the folder is empty


                                    hmm, that is not good, does your user have write access to that directory?


                                    2.
                                    java.io.FileNotFoundException: unit.war (The system cannot find the file specifi
                                    ed)
                                     at java.io.FileInputStream.open(Native Method)
                                     at java.io.FileInputStream.<init>(FileInputStream.java:106)
                                     at java.io.FileInputStream.<init>(FileInputStream.java:66)
                                     at sun.tools.jar.Main.run(Main.java:205)
                                     at sun.tools.jar.Main.main(Main.java:1022)


                                    obviously this means you are not passing the proper location to the jar command, reply back with the results after you pass the proper location


                                    This is the script i am running
                                    <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}/unit.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"/>
                                    
                                     <property name="build.dir" location="${basedir}/classes/test"/>
                                    
                                     <!-- Libraries required for jsfunitwar ant task -->
                                    
                                     <property name="jsfunit.ant.jar" location="${lib.dir}/jboss-jsfunit-ant-1.0-beta-1.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-beta-1.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"/>
                                     <property name="jsfunitclass" location="${build.dir}"/>
                                    
                                    
                                     <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}"/>
                                     <pathelement location="${jsfunitclass}"/>
                                    
                                     <fileset dir="${lib.dir}">
                                     <include name="*.jar"/>
                                     </fileset>
                                    </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">
                                     <echo> ${src.war}</echo>
                                     <echo>${lib.dir}</echo>
                                     <war destfile="${dest.war}"
                                     webxml="D:\Backup\jsfunit\WebContent\WEB-INF\web.xml">
                                     <classes dir="${build.dir}"/>
                                     <lib dir="${lib.dir}"/>
                                     </war>
                                     <jsfunitwar srcfile="${src.war}"
                                     destfile="${dest.war}">
                                    
                                     <classes dir="${build.dir}" includes="com.foo.JSFUnitTest"/>
                                     <lib dir="{lib.dir}"/>
                                     <TestRunner mapping="/ServletTestRunner" servletClass="com.foo.JSFUnitTest" />
                                     </jsfunitwar>
                                    
                                     </target>
                                    </project>



                                    Help me out..

                                    I will look into this once the other 2 questions are answered

                                    1 2 Previous Next