Added: jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/java/org/apache/cactus/sample/servlet/util/GenericResponseWrapper.java URL: http://svn.apache.org/viewvc/jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/java/org/apache/cactus/sample/servlet/util/GenericResponseWrapper.java?rev=611181&view=auto ============================================================================== --- jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/java/org/apache/cactus/sample/servlet/util/GenericResponseWrapper.java (added) +++ jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/java/org/apache/cactus/sample/servlet/util/GenericResponseWrapper.java Fri Jan 11 06:08:55 2008 @@ -0,0 +1,140 @@ +/* + * ======================================================================== + * + * Copyright 2001-2003 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ======================================================================== + */ +package org.apache.cactus.sample.servlet.util; + +import java.io.ByteArrayOutputStream; +import java.io.PrintWriter; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponseWrapper; + +/** + * Wrapper around a <code>HttpServletResponse</code> that we use to easily + * write filters that manipulate the output stream. Indeed, we cannot pass + * the output stream of our filter direectly to the next filter in the chain + * because then we won't be able to write to it (the response will have been + * committed). Instead, we pass this wrapper class and then copy its data + * to our filter output stream. + * + * Note: This code was adapted from the Filter tutorial found + * [EMAIL PROTECTED] <a href="http://www.orionserver.com/tutorials/filters/lesson3/"> + * here</a>} + * + * @version $Id: GenericResponseWrapper.java 238816 2004-02-29 16:36:46Z vmassol $ + * + * @see FilterServletOutputStream + */ +public class GenericResponseWrapper extends HttpServletResponseWrapper +{ + /** + * Holder for the output data + */ + private ByteArrayOutputStream output; + + /** + * Save the content length so that we can query it at a later time + * (otherwise it would not be possible as + * <code>HttpServletResponseWrapper</code> does not have a method to get + * the content length). + */ + private int contentLength; + + /** + * Save the content type so that we can query it at a later time + * (otherwise it would not be possible as + * <code>HttpServletResponseWrapper</code> does not have a method to get + * the content type). + */ + private String contentType; + + // Constructors ---------------------------------------------------------- + + /** + * @param theResponse the wrapped response object + */ + public GenericResponseWrapper(HttpServletResponse theResponse) + { + super(theResponse); + this.output = new ByteArrayOutputStream(); + } + + // New methods ----------------------------------------------------------- + + /** + * @return the data sent to the output stream + */ + public byte[] getData() + { + return output.toByteArray(); + } + + // Overridden methods ---------------------------------------------------- + + /** + * @see HttpServletResponseWrapper#getOutputStream() + */ + public ServletOutputStream getOutputStream() + { + return new FilterServletOutputStream(this.output); + } + + /** + * @see HttpServletResponseWrapper#setContentLength(int) + */ + public void setContentLength(int theLength) + { + this.contentLength = theLength; + super.setContentLength(theLength); + } + + /** + * @see HttpServletResponseWrapper#getContentLength() + */ + public int getContentLength() + { + return this.contentLength; + } + + /** + * @see HttpServletResponseWrapper#setContentType(String) + */ + public void setContentType(String theType) + { + this.contentType = theType; + super.setContentType(theType); + } + + /** + * @see HttpServletResponseWrapper#getContentType() + */ + public String getContentType() + { + return this.contentType; + } + + /** + * @see HttpServletResponseWrapper#getWriter() + */ + public PrintWriter getWriter() + { + return new PrintWriter(getOutputStream(), true); + } +}
Added: jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/README URL: http://svn.apache.org/viewvc/jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/README?rev=611181&view=auto ============================================================================== --- jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/README (added) +++ jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/README Fri Jan 11 06:08:55 2008 @@ -0,0 +1,3 @@ +This sample application demonstrates: +- how to write Cactus test cases (Servlet, Taglibs and Filters) +- how to use the Ant Integration from your own Ant build file Added: jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/conf/jboss3x/jboss-web.xml URL: http://svn.apache.org/viewvc/jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/conf/jboss3x/jboss-web.xml?rev=611181&view=auto ============================================================================== --- jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/conf/jboss3x/jboss-web.xml (added) +++ jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/conf/jboss3x/jboss-web.xml Fri Jan 11 06:08:55 2008 @@ -0,0 +1,3 @@ +<jboss-web> + <security-domain>java:/jaas/other</security-domain> +</jboss-web> Added: jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/conf/jboss3x/roles.properties URL: http://svn.apache.org/viewvc/jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/conf/jboss3x/roles.properties?rev=611181&view=auto ============================================================================== --- jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/conf/jboss3x/roles.properties (added) +++ jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/conf/jboss3x/roles.properties Fri Jan 11 06:08:55 2008 @@ -0,0 +1,2 @@ +testuser=test +admin=JBossAdmin Added: jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/conf/jboss3x/users.properties URL: http://svn.apache.org/viewvc/jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/conf/jboss3x/users.properties?rev=611181&view=auto ============================================================================== --- jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/conf/jboss3x/users.properties (added) +++ jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/conf/jboss3x/users.properties Fri Jan 11 06:08:55 2008 @@ -0,0 +1,2 @@ +testuser=testpassword +admin=admin Added: jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/logging_client.properties.sample URL: http://svn.apache.org/viewvc/jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/logging_client.properties.sample?rev=611181&view=auto ============================================================================== --- jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/logging_client.properties.sample (added) +++ jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/logging_client.properties.sample Fri Jan 11 06:08:55 2008 @@ -0,0 +1,71 @@ +# ----------------------------------------------------------------------------- +# Logging properties +# ----------------------------------------------------------------------------- + +# Disable logging by default when running the tests. If you wish to use a +# logging subsystem, uncomment the line below. That will let Commons logging +# decide automatically of a suitable logging system for you. You can also force +# commons-logging to use a specific logging system. For more info, see +# http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/package-summary.html#package_description + +# Disable logging +#org.apache.commons.logging.Log = org.apache.commons.logging.impl.NoOpLog + +# Force to use JDK 1.4 logging +#org.apache.commons.logging.Log = org.apache.commons.logging.impl.Jdk14Logger + +# Force to use Log4J logging +#org.apache.commons.logging.Log = org.apache.commons.logging.impl.Log4JLogger + +# Force to use Simple logging +#org.apache.commons.logging.Log = org.apache.commons.logging.impl.SimpleLog + +# ---- JDK 1.4 logging properties + +# Following properties are useful if you're using the JDK 1.4 logging subsystem +# and wish to output logs to a file. Make sure to comment out the NoOpLog line +# above. +java.util.logging.config.file = @target.dir@/logging_client.properties +handlers = java.util.logging.FileHandler +java.util.logging.FileHandler.pattern = @target.dir@/test_client.log +java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter + +# If you want to provide finer grained logging, restrict the level for the +# specific package name. +# For example: +# org.apache.cactus.server.level = ALL +# org.apache.commons.httpclient.level = ALL +# .level = ALL +org.apache.cactus.level = ALL + +# ---- Log4J logging properties + +# Following properties are useful if you're using the Log4J logging subsystem +# and wish to output logs to a file. Make sure to comment out the NoOpLog line +# above. +log4j.configuration = file:/@target.dir@/logging_client.properties + +log4j.appender.cactus = org.apache.log4j.FileAppender +log4j.appender.cactus.File = @target.dir@/test_client.log +log4j.appender.cactus.Append = false +log4j.appender.cactus.layout = org.apache.log4j.PatternLayout +log4j.appender.cactus.layout.ConversionPattern = %d{ABSOLUTE} [%t] %-5p %-30.30c{2} %x - %m %n + +# Any application log which uses Log4J will be logged to the Cactus log file +log4j.rootCategory=DEBUG, cactus + +# Debug logs for Cactus +log4j.category.org.apache.cactus = DEBUG, cactus +log4j.additivity.org.apache.cactus = false + +# Debug logs for HttpClient +log4j.category.org.apache.commons.httpclient = DEBUG, cactus +log4j.additivity.org.apache.commons.httpclient = false +log4j.category.httpclient = WARN, cactus +log4j.additivity.httpclient = false + +# ---- SimpleLog logging properties + +org.apache.commons.logging.simplelog.showlogname = true +org.apache.commons.logging.simplelog.log.org.apache.cactus = trace +org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient = trace Added: jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/logging_server.properties.sample URL: http://svn.apache.org/viewvc/jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/logging_server.properties.sample?rev=611181&view=auto ============================================================================== --- jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/logging_server.properties.sample (added) +++ jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/logging_server.properties.sample Fri Jan 11 06:08:55 2008 @@ -0,0 +1,68 @@ +# ----------------------------------------------------------------------------- +# Logging properties +# ----------------------------------------------------------------------------- + +# Disable logging by default when running the tests. If you wish to use a +# logging subsystem, uncomment the line below. That will let Commons logging +# decide automatically of a suitable logging system for you. You can also force +# commons-logging to use a specific logging system. For more info, see +# http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/package-summary.html#package_description + +# Disable logging +#org.apache.commons.logging.Log = org.apache.commons.logging.impl.NoOpLog + +# Force to use JDK 1.4 logging +#org.apache.commons.logging.Log = org.apache.commons.logging.impl.Jdk14Logger + +# Force to use Log4J logging +#org.apache.commons.logging.Log = org.apache.commons.logging.impl.Log4JLogger + +# Force to use Simple logging +#org.apache.commons.logging.Log = org.apache.commons.logging.impl.SimpleLog + +# ---- JDK 1.4 logging properties + +# Following properties are useful if you're using the JDK 1.4 logging subsystem +# and wish to output logs to a file. Make sure to comment out the NoOpLog line +# above. +java.util.logging.config.file = @target.dir@/logging_server.properties +handlers = java.util.logging.FileHandler +java.util.logging.FileHandler.pattern = @target.dir@/test_server.log +java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter + +# If you want to provide finer grained logging, restrict the level for the +# specific package name. +# For example: org.apache.cactus.server.level = ALL +org.apache.cactus.level = ALL + +# ---- Log4J logging properties + +# Following properties are useful if you're using the Log4J logging subsystem +# and wish to output logs to a file. Make sure to comment out the NoOpLog line +# above. +log4j.configuration = file:/@target.dir@/logging_server.properties + +log4j.appender.cactus = org.apache.log4j.FileAppender +log4j.appender.cactus.File = @target.dir@/test_server.log +log4j.appender.cactus.Append = false +log4j.appender.cactus.layout = org.apache.log4j.PatternLayout +log4j.appender.cactus.layout.ConversionPattern = %d{ABSOLUTE} [%t] %-5p %-30.30c{2} %x - %m %n + +# Any application log which uses Log4J will be logged to the Cactus log file +log4j.rootCategory=DEBUG, cactus + +# Debug logs for Cactus +log4j.category.org.apache.cactus = DEBUG, cactus +log4j.additivity.org.apache.cactus = false + +# Debug logs for HttpClient +log4j.category.org.apache.commons.httpclient = DEBUG, cactus +log4j.additivity.org.apache.commons.httpclient = false +log4j.category.httpclient = WARN, cactus +log4j.additivity.httpclient = false + +# ---- SimpleLog logging properties + +org.apache.commons.logging.simplelog.showlogname = true +org.apache.commons.logging.simplelog.log.org.apache.cactus = trace +org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient = trace Added: jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/scripts/build.xml URL: http://svn.apache.org/viewvc/jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/scripts/build.xml?rev=611181&view=auto ============================================================================== --- jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/scripts/build.xml (added) +++ jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/resources/scripts/build.xml Fri Jan 11 06:08:55 2008 @@ -0,0 +1,478 @@ +<?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"/> + <property name="cactus.securitytest.users" value="testuser:testpassword:test"/> + <!-- 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="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="htmlunit.jar" + location="../../lib/@htmlunit.jar.name@"/> + <property name="junit.jar" + location="../../lib/@junit.jar.name@"/> + <property name="nekohtml.jar" + location="../../lib/@nekohtml.jar.name@"/> + <property name="cargo.jar" + location="../../lib/@cargo.jar.name@"/> + <property name="cargo.ant.jar" + location="../../lib/@cargo.ant.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="${cargo.ant.jar}"/> + <pathelement location="${commons.httpclient.jar}"/> + <pathelement location="${commons.logging.jar}"/> + <pathelement location="${junit.jar}"/> + <pathelement location="${htmlunit.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="${htmlunit.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="${htmlunit.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> + + <!-- Prepare the directories for the JUnit reports --> + <mkdir dir="${target.testreports.dir}"/> + <@[EMAIL PROTECTED] dir="${target.testreports.dir}/jboss3x"/@j2ee13.end@> + <mkdir dir="${target.testreports.dir}/orion1x"/> + <mkdir dir="${target.testreports.dir}/orion2x"/> + <mkdir dir="${target.testreports.dir}/resin2x"/> + <mkdir dir="${target.testreports.dir}/resin3x"/> + <@[EMAIL PROTECTED] dir="${target.testreports.dir}/tomcat3x"/@j2ee12.end@> + <mkdir dir="${target.testreports.dir}/tomcat4x"/> + <mkdir dir="${target.testreports.dir}/tomcat5x"/> + <mkdir dir="${target.testreports.dir}/weblogic7x"/> + + </target> + + <!-- Start a container --> + <macrodef name="start-container"> + <attribute name="containerKey"/> + <sequential> + <mkdir dir="${target.dir}/@{containerKey}"/> + <mkdir dir="${target.dir}/@{containerKey}/config"/> + <cargo id="@{containerKey}" containerId="@{containerKey}" action="start" + home="[EMAIL PROTECTED]" wait="false" + log="${target.dir}/@{containerKey}/cargo_start.log" + output="${target.dir}/@{containerKey}/container_start.log"> + <configuration home="${target.dir}/@{containerKey}/config"> + <property name="cargo.servlet.port" value="${cactus.port}"/> + <property name="cargo.servlet.users" value="${cactus.securitytest.users}"/> + <property name="cargo.logging" value="high"/> + + <deployable type="war" file="${target.dir}/${project.name.file}-cactified.war"/> + </configuration> + <!-- 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="run-testcases"> + <attribute name="containerKey"/> + <sequential> + <mkdir dir="${target.testreports.dir}"/> + <mkdir dir="${target.testreports.dir}/@{containerKey}"/> + <cactustests fork="yes" failureproperty="tests.failed" haltonerror="true" + servletport="${cactus.port}" + warfile="${target.dir}/${project.name.file}-cactified.war" + todir="${target.testreports.dir}/@{containerKey}" + logs="${target.dir.normalized}/logging_client.properties"> + + <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> + <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> + <fileset dir="${src.cactus.dir}"> + <include name="**/servlet/Test*.java"/> + <exclude name="**/servlet/Test*All.java"/> + </fileset> + </batchtest> + </cactustests> + </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}"/> + <!-- <input>Press Return key to do test ...</input> --> + <run-testcases 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"> + + <test-container containerKey="jboss3x"/> + <test-container containerKey="jboss4x"/> + <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> Added: jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/webapp/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/webapp/WEB-INF/web.xml?rev=611181&view=auto ============================================================================== --- jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/webapp/WEB-INF/web.xml (added) +++ jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/webapp/WEB-INF/web.xml Fri Jan 11 06:08:55 2008 @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!DOCTYPE web-app + PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" + "http://java.sun.com/dtd/web-app_2_3.dtd"> + +<web-app> + + <context-param> + <param-name>param</param-name> + <param-value>value used for testing</param-value> + </context-param> + + <servlet> + <servlet-name>ServletRedirectorPepo</servlet-name> + <servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class> + <init-param> + <param-name>param1</param-name> + <param-value>value1 used for testing</param-value> + </init-param> + </servlet> + + <servlet> + <servlet-name>ServletRedirector_TestOverride</servlet-name> + <servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class> + <init-param> + <param-name>param2</param-name> + <param-value>value2 used for testing</param-value> + </init-param> + </servlet> + + <servlet> + <servlet-name>TestJsp</servlet-name> + <jsp-file>/test/test.jsp</jsp-file> + </servlet> + + <servlet> + <servlet-name>JspRedirectorPepo</servlet-name> + <jsp-file>/jspRedirector.jsp</jsp-file> + <init-param> + <param-name>param1</param-name> + <param-value>value1 used for testing</param-value> + </init-param> + </servlet> + + <servlet-mapping> + <servlet-name>ServletRedirector_TestOverride</servlet-name> + <url-pattern>/ServletRedirectorOverride</url-pattern> + </servlet-mapping> + +</web-app> Added: jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/webapp/cactus-report.xsl URL: http://svn.apache.org/viewvc/jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/webapp/cactus-report.xsl?rev=611181&view=auto ============================================================================== --- jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/webapp/cactus-report.xsl (added) +++ jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/webapp/cactus-report.xsl Fri Jan 11 06:08:55 2008 @@ -0,0 +1,321 @@ +<?xml version="1.0"?> +<!-- + * ======================================================================== + * + * Copyright 2001-2003 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ======================================================================== +--> + +<!-- + + Sample stylesheet to be used with the Cactus ServletTestRunner output. + Based on the file junit-noframes.xsl from Apache Ant 1.5. + + @author Stephane Bailliez <a href="mailto:[EMAIL PROTECTED]"/> + @author Erik Hatcher <a href="mailto:[EMAIL PROTECTED]"/> + @author Christopher Lenz <a href="mailto:[EMAIL PROTECTED]"/> + +--> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> + <xsl:output method="html" indent="yes" encoding="US-ASCII"/> + <xsl:decimal-format decimal-separator="." grouping-separator="," /> + <xsl:template match="testsuites"> + <html> + <head> + <style type="text/css"> + body { + font:normal 68% verdana,arial,helvetica; + color:#000000; + } + table tr td, table tr th { + font-size: 68%; + } + table.details tr th{ + font-weight: bold; + text-align:left; + background:#a6caf0; + } + table.details tr td{ + background:#eeeee0; + } + + p { + line-height:1.5em; + margin-top:0.5em; margin-bottom:1.0em; + } + h1 { + margin: 0px 0px 5px; font: 165% verdana,arial,helvetica + } + h2 { + margin-top: 1em; margin-bottom: 0.5em; font: bold 125% verdana,arial,helvetica + } + h3 { + margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica + } + h4 { + margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica + } + h5 { + margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica + } + h6 { + margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica + } + .Error { + font-weight:bold; color:red; + } + .Failure { + font-weight:bold; color:purple; + } + </style> + </head> + <body> + <a name="top"></a> + <xsl:call-template name="header"/> + <xsl:call-template name="summary"/> + <hr size="1" width="95%" align="left"/> + <xsl:call-template name="classes"/> + </body> + </html> + </xsl:template> + + <xsl:template name="header"> + <h1>Unit Test Results</h1> + <table width="100%"> + <tr> + <td align="left"></td> + <td align="right"> + Designed for use with + <a href='http://jakarta.apache.org/cactus/'>Cactus</a>. + </td> + </tr> + </table> + <hr size="1"/> + </xsl:template> + + <xsl:template name="summary"> + <h2>Summary</h2> + <xsl:variable name="testCount" select="sum(testsuite/@tests)"/> + <xsl:variable name="errorCount" select="sum(testsuite/@errors)"/> + <xsl:variable name="failureCount" select="sum(testsuite/@failures)"/> + <xsl:variable name="timeCount" select="sum(testsuite/@time)"/> + <xsl:variable name="successRate" select="($testCount - $failureCount - $errorCount) div $testCount"/> + <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> + <tr valign="top"> + <th>Tests</th> + <th>Failures</th> + <th>Errors</th> + <th>Success rate</th> + <th>Time</th> + </tr> + <tr valign="top"> + <xsl:attribute name="class"> + <xsl:choose> + <xsl:when test="$failureCount > 0">Failure</xsl:when> + <xsl:when test="$errorCount > 0">Error</xsl:when> + </xsl:choose> + </xsl:attribute> + <td><xsl:value-of select="$testCount"/></td> + <td><xsl:value-of select="$failureCount"/></td> + <td><xsl:value-of select="$errorCount"/></td> + <td> + <xsl:call-template name="display-percent"> + <xsl:with-param name="value" select="$successRate"/> + </xsl:call-template> + </td> + <td> + <xsl:call-template name="display-time"> + <xsl:with-param name="value" select="$timeCount"/> + </xsl:call-template> + </td> + </tr> + </table> + <table border="0" width="95%"> + <tr> + <td style="text-align: justify;"> + Note: <i>failures</i> are anticipated and checked for with assertions + while <i>errors</i> are unanticipated. + </td> + </tr> + </table> + </xsl:template> + + <xsl:template name="classes"> + <xsl:for-each select="testsuite"> + <xsl:sort select="@name"/> + <!-- create an anchor to this class name --> + <a name="[EMAIL PROTECTED]"></a> + <h3>TestCase <xsl:value-of select="@name"/></h3> + + <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> + <xsl:call-template name="testcase.test.header"/> + <!-- + test can even not be started at all (failure to load the class) + so report the error directly + --> + <xsl:if test="./error"> + <tr class="Error"> + <td colspan="4"><xsl:apply-templates select="./error"/></td> + </tr> + </xsl:if> + <xsl:apply-templates select="./testcase" mode="print.test"/> + </table> + <p/> + <a href="#top">Back to top</a> + </xsl:for-each> + </xsl:template> + + <xsl:template match="testsuite" mode="header"> + <tr valign="top"> + <th width="80%">Name</th> + <th>Tests</th> + <th>Errors</th> + <th>Failures</th> + <th nowrap="nowrap">Time(s)</th> + </tr> + </xsl:template> + + <!-- class header --> + <xsl:template name="testsuite.test.header"> + <tr valign="top"> + <th width="80%">Name</th> + <th>Tests</th> + <th>Errors</th> + <th>Failures</th> + <th nowrap="nowrap">Time(s)</th> + </tr> + </xsl:template> + + <!-- method header --> + <xsl:template name="testcase.test.header"> + <tr valign="top"> + <th>Name</th> + <th>Status</th> + <th width="80%">Type</th> + <th nowrap="nowrap">Time(s)</th> + </tr> + </xsl:template> + + <!-- class information --> + <xsl:template match="testsuite" mode="print.test"> + <tr valign="top"> + <!-- set a nice color depending if there is an error/failure --> + <xsl:attribute name="class"> + <xsl:choose> + <xsl:when test="@failures[.> 0]">Failure</xsl:when> + <xsl:when test="@errors[.> 0]">Error</xsl:when> + </xsl:choose> + </xsl:attribute> + <!-- print testsuite information --> + <td><a href="[EMAIL PROTECTED]"><xsl:value-of select="@name"/></a></td> + <td><xsl:value-of select="@tests"/></td> + <td><xsl:value-of select="@errors"/></td> + <td><xsl:value-of select="@failures"/></td> + <td> + <xsl:call-template name="display-time"> + <xsl:with-param name="value" select="@time"/> + </xsl:call-template> + </td> + </tr> + </xsl:template> + + <xsl:template match="testcase" mode="print.test"> + <tr valign="top"> + <xsl:attribute name="class"> + <xsl:choose> + <xsl:when test="failure | error">Error</xsl:when> + </xsl:choose> + </xsl:attribute> + <td><xsl:value-of select="@name"/></td> + <xsl:choose> + <xsl:when test="failure"> + <td>Failure</td> + <td><xsl:apply-templates select="failure"/></td> + </xsl:when> + <xsl:when test="error"> + <td>Error</td> + <td><xsl:apply-templates select="error"/></td> + </xsl:when> + <xsl:otherwise> + <td>Success</td> + <td></td> + </xsl:otherwise> + </xsl:choose> + <td> + <xsl:call-template name="display-time"> + <xsl:with-param name="value" select="@time"/> + </xsl:call-template> + </td> + </tr> + </xsl:template> + + <xsl:template match="failure"> + <xsl:call-template name="display-failures"/> + </xsl:template> + + <xsl:template match="error"> + <xsl:call-template name="display-failures"/> + </xsl:template> + + <!-- Style for the error and failure in the tescase template --> + <xsl:template name="display-failures"> + <xsl:choose> + <xsl:when test="not(@message)">N/A</xsl:when> + <xsl:otherwise> + <xsl:value-of select="@message"/> + </xsl:otherwise> + </xsl:choose> + <!-- display the stacktrace --> + <code> + <p/> + <xsl:call-template name="br-replace"> + <xsl:with-param name="word" select="."/> + </xsl:call-template> + </code> + </xsl:template> + + <!-- + template that will convert a carriage return into a br tag + @param word the text from which to convert CR to BR tag + --> + <xsl:template name="br-replace"> + <xsl:param name="word"/> + <xsl:choose> + <xsl:when test="contains($word,'
')"> + <xsl:value-of select="substring-before($word,'
')"/> + <br/> + <xsl:call-template name="br-replace"> + <xsl:with-param name="word" select="substring-after($word,'
')"/> + </xsl:call-template> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$word"/> + </xsl:otherwise> + </xsl:choose> + </xsl:template> + + <xsl:template name="display-time"> + <xsl:param name="value"/> + <xsl:value-of select="format-number($value,'0.000')"/> + </xsl:template> + + <xsl:template name="display-percent"> + <xsl:param name="value"/> + <xsl:value-of select="format-number($value,'0.00%')"/> + </xsl:template> + +</xsl:stylesheet> + Added: jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/webapp/test/test.jsp URL: http://svn.apache.org/viewvc/jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/webapp/test/test.jsp?rev=611181&view=auto ============================================================================== --- jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/webapp/test/test.jsp (added) +++ jakarta/cactus/branches/CACTUS_TRUNK_MAMOUTH/samples/samples-servlet/src/main/webapp/test/test.jsp Fri Jan 11 06:08:55 2008 @@ -0,0 +1,7 @@ +<%-- Test JSP used by the TestServletTestCase test class to test --%> +<%-- RequestDispatcher call. --%> +<html> + <body> + Hello ! + </body> +</html> \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]