Hi Xuan,

Sorry but I'm having a hard time trying to visualize what you mean. Could
you please show an example using the XML tags?

What is option 2? Is it about wrapping the following in a task:

  <macrodef name="junit-container">
    <attribute name="containerKey"/>
    <sequential>
      <mkdir dir="${target.testreports.dir}"/>
      <mkdir dir="${target.testreports.dir}/@{containerKey}"/>
      <property prefix="cactus.log" 
          file="${target.dir.normalized}/logging_client.properties"/>
      <junit fork="yes" failureproperty="tests.failed" haltonerror="true">
        <sysproperty key="cactus.contextURL" 
 
value="http://localhost:${cactus.port}/${project.name.file}-cactified"/>
        <syspropertyset>
          <propertyref prefix="cactus.log"/>
          <mapper type="glob" from="cactus.log.*" to="*"/>
        </syspropertyset>
        <classpath>
          <path refid="project.classpath"/>
          <path refid="cactus.classpath"/>
          <@[EMAIL PROTECTED] location="${clover.jar}"/@clover.end@>
          <pathelement location="${httpunit.jar}"/>
          <pathelement location="${nekohtml.jar}"/>
          <pathelement location="${target.classes.java.dir}"/>
          <pathelement location="${target.classes.cactus.dir}"/>
          <pathelement location="${log4j.jar}"/>
        </classpath>
        <formatter type="brief" usefile="false"/>
        <formatter type="xml"/>
        <batchtest todir="${target.testreports.dir}/@{containerKey}">
          <fileset dir="${src.cactus.dir}">
            <!-- Due to some Cactus synchronization bug, the 'unit' tests
                 Need to run before the 'sample' tests -->
            <include name="**/servlet/unit/Test*.java"/>
            <exclude name="**/servlet/unit/Test*All.java"/>
          </fileset>
        </batchtest>
        <batchtest todir="${target.testreports.dir}/@{containerKey}">
          <fileset dir="${src.cactus.dir}">
            <include name="**/servlet/Test*.java"/>
            <exclude name="**/servlet/Test*All.java"/>
          </fileset>
        </batchtest>
      </junit>
    </sequential>
  </macrodef>

?

(this comes from the CARGO branch)

This is how a user would use the <junit> task directly to run Cactus tests.
I think the lightweight wrapping task could make it easier by:
- setting the sysproperty properties
- setting the classpath

The rest should be left to the user.

Are we on the same wavelength?

Thanks
-Vincent

> -----Original Message-----
> From: Xuan Thang Nguyen [mailto:[EMAIL PROTECTED]
> Sent: dimanche 10 juillet 2005 12:49
> To: 'Cactus Developers List'
> Subject: RE: Cactus & Cargo Integration
> 
> Hi Vincent,
> Since no one has had a comments so far. I assume it's safe to go further
> for
> option 2 in which  let's create a new attribute "performTest" similar to
> runservertests as an extension of junit. It will have the following tags:
> - testURL     To check the server has been started up
> - timeout     To stop listening if no response from the server after a
> period of time
> - testreportDir       To hold the generated reports
> - log         Cactus log file
> 
> Apparently there is nothing new, these are collected from Cactus &
> runservertests tasks.
> 
> If you are happy with this, I'll go ahead.

[snip]
<?xml version="1.0"?>

<!--
  =============================================================================
    Build file for the Cactus Servlet Sample subproject. It shows how to use
    Cactus for unit testing the Servlet API (Servlets, Filters and Taglibs).

    The following Ant tasks need to be available in your ant installation (i.e.
    the Ant task themselves and their dependent jars need to be put in
    ANT_HOME/lib):

        junit                  [REQUIRED] JUnit Ant task

    Check the build.properties file to find out what properties need to be set
    in order to successfully run this script.

    This script should be started with the following command line:

        ant <target>

    Run "ant -projecthelp" to get a list of available targets.
  =============================================================================
-->
<project name="Cactus Servlet Sample" default="dist" basedir=".">

    <!-- Give user a chance to override without editing this file
       (and without typing -D each time it compiles it) -->
  <property file="build.properties" />
  <property file="${user.home}/build.properties" />

  <!-- Global project properties -->
  <property name="project.name.text" value="Cactus Servlet Sample"/>
  <property name="project.name.file" value="cactus-sample-servlet"/>
  <property name="project.version" value="@version@"/>

  <!-- Prefix to add to all distributable files -->
  <property name="project.prefix" value="jakarta-"/>

  <!-- Generic properties -->
  <property name="year" value="@year@"/>
  <property name="debug" value="on"/>
  <property name="optimize" value="off"/>
  <property name="deprecation" value="off"/>

  <!-- Properties for the Cactus tests -->
  <property name="cactus.port" value="8080"/>

  <!-- Location where the logging properties files are located -->
  <property name="base.dir" location="."/>

  <!--
     ========================================================================
       Set the properties related to the source tree.
     ========================================================================
  -->
  <property name="src.dir" location="src"/>
  <property name="src.java.dir" location="${src.dir}/java"/>
  <property name="src.conf.dir" location="${src.dir}/conf"/>
  <property name="src.cactus.dir" location="${src.dir}/test-cactus"/>
  <property name="src.webapp.dir" location="${src.dir}/webapp"/>

  <!--
     ========================================================================
       Set the properties related to the target area
     ========================================================================
  -->
  <!-- Destination locations for the build -->
  <property name="target.dir" location="target"/>
  <property name="target.classes.dir" location="${target.dir}/classes"/>
  <property name="target.classes.java.dir"
      location="${target.classes.dir}/java"/>
  <property name="target.classes.cactus.dir"
      location="${target.classes.dir}/cactus"/>
  <property name="target.testreports.dir"
      location="${target.dir}/test-reports"/>

  <!-- Distribution directory, i.e. where the expanded distibutable files
       are located -->
  <property name="dist.dir" location="dist"/>

  <!--
     ========================================================================
       Set the properties related to the required libraries
     ========================================================================
  -->

  <!-- Libraries required for the sample project -->
  <property name="servlet.jar"
      location="../../lib/@servlet.jar.name@"/>
  <@[EMAIL PROTECTED] name="jstl.jar"
      location="lib/@jstl.jar.name@"/@j2ee13.end@>
  <@[EMAIL PROTECTED] name="standard.jar"
      location="lib/@standard.jar.name@"/@j2ee13.end@>
  <path id="project.classpath">
    <pathelement location="${servlet.jar}"/>
    <@[EMAIL PROTECTED] location="${jstl.jar}"/@j2ee13.end@>
    <@[EMAIL PROTECTED] location="${standard.jar}"/@j2ee13.end@>
  </path>

  <!-- Libraries required for the Cactus tests -->
  <property name="aspectjrt.jar"
      location="../../lib/@aspectjrt.jar.name@"/>
  <property name="cactus.jar"
      location="../../lib/@cactus.jar.name@"/>
  <property name="cactus.ant.jar"
      location="../../lib/@cactus.ant.jar.name@"/>
  <property name="cargo.jar"
      location="../../lib/@cargo.jar.name@"/>
  <property name="commons.httpclient.jar"
      location="../../lib/@commons.httpclient.jar.name@"/>
  <property name="commons.logging.jar"
      location="../../lib/@commons.logging.jar.name@"/>
  <property name="httpunit.jar"
      location="../../lib/@httpunit.jar.name@"/>
  <property name="junit.jar"
      location="../../lib/@junit.jar.name@"/>
  <property name="nekohtml.jar"
      location="../../lib/@nekohtml.jar.name@"/>

  <!-- This is optional and only needed if you wish to debug and use 
       Log4J for logging -->
  <property name="log4j.jar"
      location="../../lib/@log4j.jar.name@"/>

  <path id="cactus.classpath">
    <path refid="project.classpath"/>
    <pathelement location="${aspectjrt.jar}"/>
    <pathelement location="${cactus.jar}"/>
    <pathelement location="${cactus.ant.jar}"/>
    <pathelement location="${cargo.jar}"/>
    <pathelement location="${commons.httpclient.jar}"/>
    <pathelement location="${commons.logging.jar}"/>
    <pathelement location="${junit.jar}"/>
  </path>

  <!--
     ========================================================================
       Initialize the build. Must be called by all targets
     ========================================================================
  -->
  <target name="init">

    <condition property="properties.ok">
      <and>
        <available file="${servlet.jar}"/>
        <@[EMAIL PROTECTED] file="${jstl.jar}"/@j2ee13.end@>
        <@[EMAIL PROTECTED] file="${standard.jar}"/@j2ee13.end@>
      </and>
    </condition>
    <fail unless="properties.ok">Missing property or property pointing to an invalid file
(check your build.properties file)</fail>

    <taskdef resource="cactus.tasks" classpathref="cactus.classpath"/>
    <taskdef resource="cargo.tasks" classpathref="cactus.classpath"/>

    <tstamp/>

  </target>

  <!--
     ========================================================================
       Compiles the sources
     ========================================================================
  -->
  <!-- Compiles the java sources -->
  <target name="compile.java" depends="init">

    <mkdir dir="${target.classes.java.dir}"/>
    <javac destdir="${target.classes.java.dir}"
        deprecation="${deprecation}" optimize="${optimize}">
      <src path="${src.java.dir}"/>
      <classpath>
        <path refid="project.classpath"/>
      </classpath>
    </javac>

  </target>

  <!-- Compiles the Cactus test sources -->
  <target name="compile.cactus" depends="compile.java">

    <mkdir dir="${target.classes.cactus.dir}"/>
    <javac destdir="${target.classes.cactus.dir}"
        deprecation="${deprecation}" optimize="${optimize}">
      <src path="${src.cactus.dir}"/>
      <classpath>
        <path refid="cactus.classpath"/>
        <pathelement location="${httpunit.jar}"/>
        <pathelement location="${nekohtml.jar}"/>
        <pathelement location="${target.classes.java.dir}"/>
      </classpath>
    </javac>

  </target>

  <target name="compile" depends="compile.java, compile.cactus"
      description="Compile the sources"/>

  <!--
     ========================================================================
       Create the runtime war file
     ========================================================================
  -->
  <target name="war" depends="compile.java"
      description="Generate the runtime war">

    <war warfile="${target.dir}/${project.name.file}.war"
         webxml="${src.webapp.dir}/WEB-INF/web.xml">
      <fileset dir="${src.webapp.dir}">
        <exclude name="cactus-report.xsl"/>
        <exclude name="WEB-INF/cactus-web.xml"/>
        <exclude name="WEB-INF/web.xml"/>
      </fileset>
      <classes dir="${target.classes.java.dir}"/>
      <@[EMAIL PROTECTED] file="${jstl.jar}"/@j2ee13.end@>
      <@[EMAIL PROTECTED] file="${standard.jar}"/@j2ee13.end@>
    </war>

  </target>

  <!--
     ========================================================================
       Generate the distributable files
     ========================================================================
  -->
  <target name="dist" depends="clean, war, test"
      description="Generate the distributable files">

    <copy todir="${dist.dir}"
        file="${target.dir}/${project.name.file}.war"/>

  </target>

  <!--
     ========================================================================
       Clean generated files (including distributables)
     ========================================================================
  -->
  <target name="clean" depends="init" description="Clean all generated files">

    <delete dir="${target.dir}"/>
    <delete dir="${dist.dir}"/>

  </target>

  <!--
     ========================================================================
       Run the tests on the containers for which the Ant property
       "cactus.home.[container name]" has been defined.
     ========================================================================
  -->
  <target name="test.prepare.logging">
  
	<!-- Convert the path to logging_*.properties to use forward slashes
	     so that it works when loaded as a String in Java (backslashes
	     won't work. -->
	<pathconvert property="target.dir.normalized" dirsep="/">
	  <path>
	    <pathelement location="${target.dir}"/>
	  </path>
	</pathconvert>
	<copy todir="${target.dir}" filtering="on" failonerror="false">
	  <fileset dir="${base.dir}">
	    <include name="logging_*.properties"/>
	  </fileset>
	  <filterset>
        <filter token="target.dir" value="${target.dir.normalized}"/>
      </filterset>
	</copy>
    <!-- Make sure logging_*.properties files exist, even if empty -->
    <touch file="${target.dir}/logging_client.properties"/>
    <touch file="${target.dir}/logging_server.properties"/>

  </target>
  
  <target name="test.prepare" 
      depends="war, compile.cactus, test.prepare.logging">
  
    <!-- Cactify the web-app archive -->
    <cactifywar srcfile="${target.dir}/${project.name.file}.war"
        destfile="${target.dir}/${project.name.file}-cactified.war"
        mergewebxml="${src.webapp.dir}/WEB-INF/cactus-web.xml">
      <classes dir="${target.classes.cactus.dir}"/>
      <lib file="${httpunit.jar}"/>
      <lib file="${log4j.jar}"/>
      <!-- Provide a secured servlet redirector in addition to the
           default servlet redirector -->
      <servletredirector/>
      <servletredirector name="ServletRedirectorSecure"
          mapping="/ServletRedirectorSecure" roles="test"/>
      <!-- Orion fails on a servlet filter that is not mapped to an actual
           resource, to trick it -->
      <filterredirector mapping="/test/filterRedirector.jsp"/>
      <!-- Files needed for JBoss -->
      <classes dir="${src.conf.dir}/jboss3x">
        <include name="*.properties" if="cactus.home.jboss3x"/>
      </classes>
      <webinf dir="${src.conf.dir}/jboss3x">
        <include name="jboss-web.xml" if="cactus.home.jboss3x"/>
      </webinf>
      <!-- Needed for Clover coverage reports -->
      <@[EMAIL PROTECTED] file="${clover.jar}"/@clover.end@>
    </cactifywar>

  </target>

  <!-- Start a container  -->
  <macrodef name="start-container">
    <attribute name="containerKey"/>
    <sequential>
      <mkdir dir="${target.dir}/@{containerKey}"/>
      <cargo id="@{containerKey}" containerKey="@{containerKey}" action="start"
          homeDir="[EMAIL PROTECTED]"
          workingDir="${target.dir}/@{containerKey}/container"
          log="${target.dir}/@{containerKey}/cargo_start.log"
          output="${target.dir}/@{containerKey}/container_start.log">
  
        <property name="cargo.servlet.port" value="${cactus.port}"/>
        <property name="cargo.logging" value="high"/>

        <war warfile="${target.dir}/${project.name.file}-cactified.war"/>

        <!-- Configure Cactus for logging -->
        <syspropertyset file="${target.dir.normalized}/logging_server.properties"/>

        <!-- Additional jars that will be added to the classpath used to start 
             the container -->
        <extraclasspath>
          <@[EMAIL PROTECTED] location="${clover.jar}"/@clover.end@>
        </extraclasspath>
      </cargo>
    </sequential>
  </macrodef>

  <!-- Run JUnit Cactus tests on a running container  -->
  <macrodef name="junit-container">
    <attribute name="containerKey"/>
    <sequential>
      <mkdir dir="${target.testreports.dir}"/>
      <mkdir dir="${target.testreports.dir}/@{containerKey}"/>
      <property prefix="cactus.log" file="${target.dir.normalized}/logging_client.properties"/>
      <junit fork="yes" failureproperty="tests.failed" haltonerror="true">
        <sysproperty key="cactus.contextURL" value="http://localhost:${cactus.port}/${project.name.file}-cactified"/>
        <syspropertyset>
          <propertyref prefix="cactus.log"/>
          <mapper type="glob" from="cactus.log.*" to="*"/>
        </syspropertyset>
        <classpath>
          <path refid="project.classpath"/>
          <path refid="cactus.classpath"/>
          <@[EMAIL PROTECTED] location="${clover.jar}"/@clover.end@>
          <pathelement location="${httpunit.jar}"/>
          <pathelement location="${nekohtml.jar}"/>
          <pathelement location="${target.classes.java.dir}"/>
          <pathelement location="${target.classes.cactus.dir}"/>
          <pathelement location="${log4j.jar}"/>
        </classpath>
        <formatter type="brief" usefile="false"/>
        <formatter type="xml"/>
        <batchtest todir="${target.testreports.dir}/@{containerKey}">
          <fileset dir="${src.cactus.dir}">
            <!-- Due to some Cactus synchronization bug, the 'unit' tests need
                 to run before the 'sample' tests -->
            <include name="**/servlet/unit/Test*.java"/>
            <exclude name="**/servlet/unit/Test*All.java"/>
          </fileset>
        </batchtest>
        <batchtest todir="${target.testreports.dir}/@{containerKey}">
          <fileset dir="${src.cactus.dir}">
            <include name="**/servlet/Test*.java"/>
            <exclude name="**/servlet/Test*All.java"/>
          </fileset>
        </batchtest>
      </junit>
    </sequential>
  </macrodef>

  <!-- Stop a container  -->
  <macrodef name="stop-container">
    <attribute name="containerKey"/>
    <sequential>
      <cargo refid="@{containerKey}" action="stop"
          log="${target.dir}/@{containerKey}/cargo_stop.log"
          output="${target.dir}/@{containerKey}/container_stop.log"/>
    </sequential>
  </macrodef>

  <!-- Generate JUnit test reports for a container -->
  <macrodef name="report-container">
    <attribute name="containerKey"/>
    <sequential>
      <junitreport todir="${target.testreports.dir}/@{containerKey}">
        <fileset dir="${target.testreports.dir}/@{containerKey}"
            includes="TEST-*.xml"/>
        <report todir="${target.testreports.dir}/@{containerKey}"
            format="frames"/>
      </junitreport>
    </sequential>
  </macrodef>
  
  <!-- Execute tests on a single container -->
  <macrodef name="test-container-internal-check">
    <attribute name="containerKey"/>
    <sequential>
      <condition property="container.shouldRun">
        <isset property="[EMAIL PROTECTED]"/>
      </condition>
    </sequential>
  </macrodef>

  <target name="test-container-internal-check">
    <test-container-internal-check containerKey="${containerKey}"/>
  </target>

  <target name="test-container-internal-ok" if="container.shouldRun">
    <echo>Running tests on ${containerKey} container...</echo>
    <start-container containerKey="${containerKey}"/>
    <junit-container containerKey="${containerKey}"/>
    <stop-container containerKey="${containerKey}"/>
    <report-container containerKey="${containerKey}"/>
  </target>

  <target name="test-container-internal-nok" unless="container.shouldRun">
    <echo>Not running tests on ${containerKey} container as [cactus.home.${containerKey}] property not defined</echo>
  </target>

  <target name="test-container-internal" 
      depends="test-container-internal-check,test-container-internal-ok,test-container-internal-nok"/>

  <macrodef name="test-container">
    <attribute name="containerKey"/>
    <sequential>
      <antcall inheritAll="true" inheritRefs="true" target="test-container-internal">
        <param name="containerKey" value="@{containerKey}"/>
      </antcall>
    </sequential>
  </macrodef>

  <target name="test" depends="test.prepare"
      description="Run the tests on the defined containers">

    <!-- Need to add jboss 3.x once it is supported by Cargo:
    <@[EMAIL PROTECTED] containerKey="jboss3x"/@j2ee13.end@>-->

    <test-container containerKey="oc4j9x"/>
    <test-container containerKey="orion1x"/>
    <test-container containerKey="orion2x"/>
    <test-container containerKey="resin2x"/>
    <test-container containerKey="resin3x"/>
    <@[EMAIL PROTECTED] containerKey="tomcat3x"/@j2ee12.end@>
    <test-container containerKey="tomcat4x"/>
    <test-container containerKey="tomcat5x"/>
    <test-container containerKey="weblogic8x"/>
    
    <fail if="tests.failed">At least one test failed!</fail>

  </target>

</project>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to