Hi,
Approach 1:
I am using Cactus framework to
unit test my
JSP. If I run these test case, using browser, it works well.
Approach 2:
but I want to run it using
ANT script, it does not work.
In running these cases using ANT, I followed the steps below.
1- Build a war file [successfully done]
2- Cactify the war file [successfully done]
3- placed cactus.properties, cactus-13-1.7.jar, aspectjrt-1.5.3.jar, commons-codec.jar, commons-httpclient-3.1.jar, commons-logging-1.1.jar, httpunit-1.6.jar, nekohtml-0.9.3.jar, junit-4.5.jar, xercesImpl.jar in %CATALINA_HOME%/shared/lib.
4- I tried to run test cases using "cactus" task on tomcat5x container and I also tried run these case using browser on the same cactified jar, but got following exception saying that "request" (in fact all implicit objects) of jspTestCase is(are) not accessible in the test class.
I used the same jar files in Approach 1 and Approach 2. So the only different step I took in approach 2 is "cactify" the war file.
Guys I need help to resolve the problem....
Thanks in advance,
Annie
<<<<<<<<<<<<<<<<<<<<<<<<<<<<Build.xml Approach 1 starts>>>>>>>>>>>>>>>>>>>>>
<?xml version="1.0" encoding="UTF-8"?>
<project name="jspANTCactusClover" default="webapp" basedir=".">
<property name="build" value="bin"/>
<property name="src" value="src" />
<property name="lib" value="lib" />
<property name="test" value="test" />
<property name="dist" value="dist"/>
<property name="jboss.deploy" value="C:\Apps\jboss-4.2.2.GA\server\default\deploy"/>
<property name="jboss.home" value="C:\Apps\ExtLoadBalancer\jboss-4.2.2.GA"/>
<property name="j2sdkee" value="C:\Program Files\Java\jdk1.5.0_15"/>
<property name="debug" value="true"/>
<property name="optimize" value="off"/>
<property name="deprecation" value="off"/>
<property name="targetwar" value="bean.war"/>
<property name="cactifiedtargetwar" value="test.war"/>
<property name="cargo-uberjar" value="${lib}/cargo-core-uberjar-0.9.jar"/>
<property name="cargo-antjar" value="${lib}/cargo-ant-0.9.jar"/>
<property name="tomcatconfig" value="tomcatconfig"/>
<property name="antlib" value="C:\apache-ant-1.7.1\lib"/>
<!-- Define the Cactus tasks -->
<path id="cactus.classpath">
<pathelement location="${lib}/cactus.core.framework.uberjar.javaEE.14-1.8.0.jar"/>
<pathelement location="${lib}/cactus.integration.shared.api-1.8.0.jar"/>
<pathelement location="${lib}/cactus.integration.ant-1.8.0.jar"/>
<pathelement location="${lib}/cargo-ant-0.9.jar"/>
<pathelement location="${lib}/cargo-core-uberjar-0.9.jar"/>
<pathelement location="${lib}/commons-httpclient-3.1.jar"/>
<pathelement location="${lib}/commons-logging-1.1.jar"/>
<pathelement location="${lib}/aspectjrt-1.5.3.jar"/>
<pathelement location="${lib}/log4j-1.2.5.jar"/>
</path>
<taskdef resource="cactus.tasks" classpathref="cactus.classpath"/>
<!-- Define the Cargo tasks -->
<path id="cargo.classpath">
<pathelement location="${lib}/cargo-ant-0.9.jar"/>
<pathelement location="${lib}/cargo-core-uberjar-0.9.jar"/>
</path>
<taskdef resource="cargo.tasks" classpathref="cargo.classpath"/>
<!-- Define the Classpath for project -->
<path id="project.classpath">
<pathelement location="${lib}/cactus.core.framework.uberjar.javaEE.14-1.8.0.jar"/>
<pathelement location="${lib}/junit-4.5.jar"/>
<pathelement location="${lib}/servlet-api-2.3.jar"/>
<pathelement location="${lib}/xercesImpl.jar"/>
<pathelement location="${lib}/httpunit-1.6.jar"/>
<pathelement location="${lib}/nekohtml-0.9.3.jar"/>
</path>
<target name="init">
<tstamp/>
<mkdir dir="${build}/my" />
</target>
<target name="project.clean">
<delete includeEmptyDirs="true">
<fileset dir="${build}" includes="**/*"/>
<fileset dir="${dist}" includes="**/*"/>
</delete>
</target>
<target name="compile.java" depends="init">
<javac srcdir="${src}" destdir="${build}"
debug="${debug}" optimize="${optimize}" deprecation="${deprecation}">
<include name="**/*.java" />
<classpath refid="project.classpath"/>
</javac>
</target>
<!-- Compiles the Cactus test sources -->
<target name="compile.cactus" depends="compile.java">
<mkdir dir="${build}/my"/>
<javac destdir="${build}" srcdir="${test}"
debug="${debug}" optimize="${optimize}" deprecation="${deprecation}">
<include name="**/*.java" />
<classpath>
<path refid="cactus.classpath"/>
<path refid="project.classpath"/>
<pathelement location="${build}/my"/>
</classpath>
</javac>
</target>
<target name="compile" depends="compile.cactus" />
<target name="webapp" depends="compile">
<war destfile="${dist}/${targetwar}" webxml="WEB-INF/web.xml">
<fileset dir="html"/>
<fileset dir="jsp" excludes="jspRedirector.jsp"/>
<lib dir="${lib}">
<exclude name="servlet-api.jar"/>
<exclude name="servlet-api-2.3.jar"/>
<exclude name="httpunit-1.6.jar"/>
<exclude name="nekohtml-0.9.3.jar"/>
<exclude name="xercesImpl.jar"/>
</lib>
<classes dir="${build}"/>
<zipfileset dir="images" prefix="images"/>
</war>
</target>
<!-- Cactify the web-app archive -->
<target name="test.prepare" depends="webapp">
<cactifywar srcfile="${dist}/${targetwar}" destfile="${dist}/${cactifiedtargetwar}">
<classes dir="${build}" includes="Test*"/>
<lib file="${lib}/httpunit-1.6.jar"/>
<lib file="${lib}/xercesImpl.jar"/>
</cactifywar>
</target>
<!-- target name="test" depends="test.prepare" description="Run the tests on the defined containers"-->
<target name="test" description="Run the tests on the defined containers">
<!--delete dir="${tomcatconfig}" /-->
<!--mkdir dir="${tomcatlog.dir}"/-->
<!--mkdir dir="${tomcatconfig}"/-->
<cactus timeout="36000" warfile="${dist}/${cactifiedtargetwar}" fork="yes" failureproperty="tests.failed">
<classpath>
<pathelement location="${lib}/cactus.core.framework.uberjar.javaEE.14-1.8.0.jar"/>
<pathelement location="${lib}/servlet-api-2.3.jar"/>
<pathelement location="${lib}/httpunit-1.6.jar"/>
<pathelement location="${lib}/nekohtml-0.9.3.jar"/>
<pathelement location="${lib}/aspectjrt-1.5.3.jar"/>
<pathelement location="${lib}/log4j-1.2.5.jar"/>
<pathelement location="${lib}/commons-logging-1.1.jar"/>
<pathelement location="${lib}/commons-httpclient-3.1.jar"/>
<pathelement location="${lib}/commons-codec.jar"/>
<pathelement location="${lib}/xercesImpl.jar"/>
<pathelement location="${build}"/>
</classpath>
<!-- Configure the cactus task for logging -->
<cactusproperty server="false" propertiesFile="${lib}/logging_client.properties"/>
<cactusproperty server="true" propertiesFile="${lib}/logging_server.properties"/>
<containerset timeout="360000">
<cargo containerId="tomcat5x" output="./output.log" log="./cargo.log" home="C:\Apps\apache-tomcat-5.5.27" action="start">
<configuration home="${tomcatconfig}">
<property name="cargo.servlet.port" value="8080"/>
<property name="cargo.logging" value="high"/>
<deployable type="war" file="C:\Workspace\jspANTCactusClover\dist\${cactifiedtargetwar}"/>
</configuration>
</cargo>
</containerset>
<!-- Additional jars that will be added to the classpath used to start the container
(in addition to the container jars themseleves which are automatically added by the
<cactus> task -->
<containerclasspath>
</containerclasspath>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<batchtest>
<fileset dir="${test}">
<include name="**/*Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
</cactus>
<!-- Generate the
JUnit reports -->
<junitreport todir="tomcat5x">
<fileset dir="tomcat5x" includes="TEST-*.xml"/>
<report todir="tomcat5x" format="frames"/>
</junitreport>
<fail if="tests.failed">At least one test failed!</fail>
</target>
</project>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<Build.xml Approach 1 ends >>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<Exception starts>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
test:
[cactus] -----------------------------------------------------------------
[cactus] Running tests against
Tomcat 5.5.27 @
http://localhost:8080 [cactus] -----------------------------------------------------------------
[cactus] Deploying [C:\Workspace\jspANTCactusClover\dist\test.war] to [tomcatconfig/webapps]...
[cactus] Tomcat 5.5.27 starting...
Server [Apache-Coyote/1.1] started
[cactus] Testsuite: my.TestJSPBean
[cactus] Tomcat 5.5.27 started on port [8080]
[cactus] Tests run: 2, Failures: 0, Errors: 2, Time elapsed: 3.109 sec
[cactus]
[cactus] Testcase: testJSPBean(my.TestJSPBean): Caused an ERROR
[cactus] request
[cactus] java.lang.NoSuchFieldError: request
[cactus] at my.TestJSPBean.testJSPBean(TestJSPBean.java:67)
[cactus] at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
[cactus] at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
[cactus] at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
[cactus] at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.ja
va:217)
[cactus] at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
[cactus] at org.apache.cactus.server.JspTestRedirector.doGet_aroundBody0(JspTestRedirector.java:70)
[cactus] at org.apache.cactus.server.JspTestRedirector.doGet_aroundBody1$advice(JspTestRedirector.java:217)
[cactus] at org.apache.cactus.server.JspTestRedirector.doGet(JspTestRedirector.java)
[cactus] at org.apache.jsp.jspRedirector_jsp._jspService(jspRedirector_jsp.java:70)
[cactus] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
[cactus] at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
[cactus] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
[cactus] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
[cactus] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
[cactus] at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
[cactus] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
[cactus] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
[cactus] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
[cactus] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
[cactus] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
[cactus] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
[cactus] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:548)
[cactus] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
[cactus] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
[cactus] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
[cactus] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
[cactus] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
[cactus] at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
[cactus] at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
[cactus] at java.lang.Thread.run(Thread.java:595)
[cactus]
[cactus]
[cactus] Testcase: testJSPBeanFailed(my.TestJSPBean): Caused an ERROR
[cactus] request
[cactus] java.lang.NoSuchFieldError: request
[cactus] at my.TestJSPBean.testJSPBeanFailed(TestJSPBean.java:129)
[cactus] at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
[cactus] at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
[cactus] at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
[cactus] at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.ja
va:217)
[cactus] at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
[cactus] at org.apache.cactus.server.JspTestRedirector.doGet_aroundBody0(JspTestRedirector.java:70)
[cactus] at org.apache.cactus.server.JspTestRedirector.doGet_aroundBody1$advice(JspTestRedirector.java:217)
[cactus] at org.apache.cactus.server.JspTestRedirector.doGet(JspTestRedirector.java)
[cactus] at org.apache.jsp.jspRedirector_jsp._jspService(jspRedirector_jsp.java:70)
[cactus] at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
[cactus] at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
[cactus] at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
[cactus] at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
[cactus] at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
[cactus] at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
[cactus] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
[cactus] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
[cactus] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
[cactus] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
[cactus] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
[cactus] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
[cactus] at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:548)
[cactus] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
[cactus] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
[cactus] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
[cactus] at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
[cactus] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
[cactus] at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
[cactus] at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
[cactus] at java.lang.Thread.run(Thread.java:595)
[cactus]
[cactus]
[cactus] Test my.TestJSPBean FAILED
[cactus] Tomcat 5.5.27 is stopping...
[cactus] Tomcat 5.5.27 is stopped
[junitreport] Processing C:\Workspace\jspANTCactusClover\tomcat5x\TESTS-TestSuites.xml to C:\DOCUME~1\gur10460\LOCALS~1\Temp\null387273057
[junitreport] Loading stylesheet jar:file:/C:/apache-ant-1.7.1/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-fra
mes.xsl
[junitreport] Transform time: 1094ms
[junitreport] Deleting: C:\DOCUME~1\gur10460\LOCALS~1\Temp\null387273057
BUILD FAILED
C:\Workspace\jspANTCactusClover\build.xml:305: At least one test failed!
<<<<<<<<<<<<<<<<<<<<<<<<<<<<Exception ends >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>