dev@javaserverfaces.java.net

[Review] Get unit tests running with Glassfish.

From: Jayashri Visvanathan <Jayashri.Visvanathan_at_Sun.COM>
Date: Mon, 12 Sep 2005 18:07:25 -0700

Get unit tests running with Glassfish.
- Due to recent class loader changes, JSF jars have to be shared chain,
due to which the unit tests from web app class loader can no longer
access package private variables declared in jsf-impl classes. I've
attached a fix to this problem but I hope we can come up with a better
solution.. If not, and we find this solution too slow, then we would
have to rewrite the tests to not access package private variables.

M build-tests.xml
M systest/build.xml
  Modify test.appserver target to
  1. stop the server
  2. copy the required files to Appserver.home/lib
  3. start the server again.





Index: build-tests.xml
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/build-tests.xml,v
retrieving revision 1.221
diff -u -r1.221 build-tests.xml
--- build-tests.xml 22 Aug 2005 22:10:01 -0000 1.221
+++ build-tests.xml 13 Sep 2005 00:43:34 -0000
@@ -440,6 +440,22 @@
       <antcall target="run.cactus.test"/>
     </target>
     
+ <!-- This target stops the Appserver, copies jsf-api.jar, jsf-impl.jar and
+ systest.jar into Appserver/lib and starts the Appserver. -->
+ <target description="Copy required jar files" name="copyJars" >
+ <antcall target="stop-appserver" />
+
+ <jar jarfile="${basedir}/build/jsf-test.jar" basedir="${out.test.dir}/WEB-INF/classes"/>
+ <copy file="${jsf-api.jar}" todir="${tomcat.home}/lib"/>
+ <copy file="${basedir}/build/lib/jsf-impl.jar" todir="${tomcat.home}/lib"/>
+ <copy file="${cactus.jar}" todir="${tomcat.home}/lib"/>
+ <copy file="${aspectjrt.jar}" todir="${tomcat.home}/lib"/>
+ <copy file="${junit.jar}" todir="${tomcat.home}/lib"/>
+ <copy file="${basedir}/build/jsf-test.jar" todir="${tomcat.home}/lib"/>
+
+ <antcall target="start-appserver" />
+ </target>
+
     <target name="-check-os">
       <condition property="exec.name" value="cmd.exe">
         <os family="windows"/>
@@ -477,9 +493,26 @@
     </target>
 
 
- <target description="Deploy web applications" name="deploy">
+ <target description="Deploy web applications" name="deploy" depends="copyJars">
        <copy file="${basedir}/${build.home}/test.war"
            todir="${tomcat.home}/domains/${appserver.domain}/autodeploy"/>
         <sleep seconds="60"/>
+ </target>
+
+ <target name="start-appserver" depends="-check-os" >
+ <exec executable="${exec.name}" spawn="true">
+ <arg line="${exec.arg.1}"/>
+ <arg line="start-domain"/>
+ </exec>
+ <waitfor>
+ <http url="http://${host}:${port}"/>
+ </waitfor>
+ </target>
+
+ <target name="stop-appserver" depends="-check-os" >
+ <exec executable="${exec.name}" failonerror="true">
+ <arg line="${exec.arg.1}"/>
+ <arg line="stop-domain"/>
+ </exec>
   </target>
 </project>
Index: systest/build.xml
===================================================================
RCS file: /cvs/javaserverfaces-sources/jsf-ri/systest/build.xml,v
retrieving revision 1.32
diff -u -r1.32 build.xml
--- systest/build.xml 22 Aug 2005 22:10:31 -0000 1.32
+++ systest/build.xml 13 Sep 2005 00:43:35 -0000
@@ -80,6 +80,9 @@
   <property name="username" value="tomcat"/>
   <property name="password" value="tomcat"/>
 
+ <property name="host" value="localhost"/>
+ <property name="port" value="8080"/>
+
 <!-- ************ Dependencies **** *************************************** -->
 
   <!-- The locations of necessary jar files -->
@@ -229,7 +232,7 @@
     <copy file="${commons-digester.jar}" todir="${build.home}/WEB-INF/lib"/>
     <copy file="${commons-logging.jar}" todir="${build.home}/WEB-INF/lib"/>
     <copy file="${jstl.jar}" todir="${build.home}/WEB-INF/lib"/>
- <copy file="${standard.jar}" todir="${build.home}/WEB-INF/lib"/>
+ <copy file="${standard.jar}" todir="${build.home}/WEB-INF/lib"/>
     <copy file="${jsf-api.jar}" todir="${build.home}/WEB-INF/lib"/>
     <copy file="${jsf-impl.jar}" todir="${build.home}/WEB-INF/lib"/>
   </target>
@@ -251,7 +254,7 @@
     </copy>
     <copy todir="${build.home}/WEB-INF/classes">
         <fileset dir="${source.home}" includes="**/*.xml"/>
- </copy>
+ </copy>
   </target>
 
 
@@ -274,9 +277,9 @@
 
   </target>
   
- <target name="test.appserver" depends="compile, undeploy, deploy,test"
+ <target name="test.appserver" depends="init, compile, undeploy, deploy,test"
    description="Execute all tests against installed /jsf-systest application" />
-
+
   <target name="build.war">
   
       <!-- edburns: remove this deletion when the glassfish regression is fixed
@@ -293,7 +296,20 @@
         <ant antfile="build-tests.xml" target="test"/>
   </target>
   
- <target name="deploy" depends="-check-os,build.war" >
+ <!-- This target stops the Appserver, copies jsf-api.jar, jsf-impl.jar and
+ systest.jar into Appserver/lib and starts the Appserver. -->
+ <target description="Copy required jar files" name="copyJars" >
+ <antcall target="stop-appserver" />
+
+ <jar jarfile="${build.home}/systest.jar" basedir="${build.home}/WEB-INF/classes"/>
+ <copy file="${jsf-api.jar}" todir="${tomcat.home}/lib"/>
+ <copy file="${jsf-impl.jar}" todir="${tomcat.home}/lib"/>
+ <copy file="${build.home}/systest.jar" todir="${tomcat.home}/lib"/>
+
+ <antcall target="start-appserver" />
+ </target>
+
+ <target name="deploy" depends="copyJars, -check-os, build.war" >
         <exec executable="${exec.name}" failonerror="true">
             <arg line="${exec.arg.1}"/>
             <arg line="deploy"/>
@@ -306,6 +322,7 @@
       
     </target>
     
+ <!-- This target undeploys the jsf-systest app -->
     <target name="undeploy" depends="-check-os">
         <exec executable="${exec.name}">
             <arg line="${exec.arg.1}"/>
@@ -318,6 +335,23 @@
         </exec>
        
     </target>
+
+ <target name="start-appserver" depends="-check-os" >
+ <exec executable="${exec.name}" spawn="true">
+ <arg line="${exec.arg.1}"/>
+ <arg line="start-domain"/>
+ </exec>
+ <waitfor>
+ <http url="http://${host}:${port}"/>
+ </waitfor>
+ </target>
+
+ <target name="stop-appserver" depends="-check-os" >
+ <exec executable="${exec.name}" failonerror="true">
+ <arg line="${exec.arg.1}"/>
+ <arg line="stop-domain"/>
+ </exec>
+ </target>
    
     <target name="-check-os">
       <condition property="exec.name" value="cmd.exe">