You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by nc...@apache.org on 2005/10/02 00:01:40 UTC
svn commit: r293031 - in /jakarta/cactus/trunk: ./ framework/
framework/src/java/share-12-13-14/org/apache/cactus/internal/client/
integration/ant/src/scripts/share/ integration/maven/ samples/servlet/
samples/servlet/src/scripts/share/ samples/servlet...
Author: nchalumeau
Date: Sat Oct 1 15:00:33 2005
New Revision: 293031
URL: http://svn.apache.org/viewcvs?rev=293031&view=rev
Log:
[CACTUS-220] add html unit integration
Added:
jakarta/cactus/trunk/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/servlet/unit/TestHtmlUnitIntegration.java
Modified:
jakarta/cactus/trunk/.project
jakarta/cactus/trunk/build.properties.default
jakarta/cactus/trunk/build.xml
jakarta/cactus/trunk/dependencies.xml.default
jakarta/cactus/trunk/download.xml
jakarta/cactus/trunk/framework/build.xml
jakarta/cactus/trunk/framework/project.xml
jakarta/cactus/trunk/framework/src/java/share-12-13-14/org/apache/cactus/internal/client/WebResponseObjectFactory.java
jakarta/cactus/trunk/integration/ant/src/scripts/share/build-share.xml
jakarta/cactus/trunk/integration/maven/plugin.jelly
jakarta/cactus/trunk/samples/servlet/build.xml
jakarta/cactus/trunk/samples/servlet/src/scripts/share/build.xml
Modified: jakarta/cactus/trunk/.project
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/.project?rev=293031&r1=293030&r2=293031&view=diff
==============================================================================
--- jakarta/cactus/trunk/.project (original)
+++ jakarta/cactus/trunk/.project Sat Oct 1 15:00:33 2005
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>cactus</name>
+ <name>cactus-trunk</name>
<comment></comment>
<projects>
</projects>
@@ -10,8 +10,14 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>com.atlassw.tools.eclipse.checkstyle.CheckstyleBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>com.atlassw.tools.eclipse.checkstyle.CheckstyleNature</nature>
</natures>
</projectDescription>
Modified: jakarta/cactus/trunk/build.properties.default
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/build.properties.default?rev=293031&r1=293030&r2=293031&view=diff
==============================================================================
--- jakarta/cactus/trunk/build.properties.default (original)
+++ jakarta/cactus/trunk/build.properties.default Sat Oct 1 15:00:33 2005
@@ -220,6 +220,9 @@
# The location of the Httpunit jar
httpunit.jar = ${lib.repo}/${httpunit.project}/jars/${httpunit.artifact}-${httpunit.version}.jar
+# The location of the Hmlunit jar
+htmlunit.jar = ${lib.repo}/${htmlunit.project}/jars/${htmlunit.artifact}-${htmlunit.version}.jar
+
# The location of the Cargo jar
cargo.jar = ${lib.repo}/${cargo.project}/jars/${cargo.artifact}-${cargo.version}.jar
Modified: jakarta/cactus/trunk/build.xml
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/build.xml?rev=293031&r1=293030&r2=293031&view=diff
==============================================================================
--- jakarta/cactus/trunk/build.xml (original)
+++ jakarta/cactus/trunk/build.xml Sat Oct 1 15:00:33 2005
@@ -216,6 +216,8 @@
prefix="${main.release.name}/lib"/>
<zipfileset file="${httpunit.jar}"
prefix="${main.release.name}/lib"/>
+ <zipfileset file="${htmlunit.jar}"
+ prefix="${main.release.name}/lib"/>
<zipfileset file="${junit.jar}"
prefix="${main.release.name}/lib"/>
<zipfileset file="${nekohtml.jar}"
Modified: jakarta/cactus/trunk/dependencies.xml.default
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/dependencies.xml.default?rev=293031&r1=293030&r2=293031&view=diff
==============================================================================
--- jakarta/cactus/trunk/dependencies.xml.default (original)
+++ jakarta/cactus/trunk/dependencies.xml.default Sat Oct 1 15:00:33 2005
@@ -25,6 +25,8 @@
artifact="commons-logging" version="1.0.4"/>
<httpunit project="httpunit"
artifact="httpunit" version="1.6"/>
+ <htmlunit project="htmlunit"
+ artifact="htmlunit" version="1.6"/>
<j2ee.13 project="jboss"
artifact="jboss-j2ee" version="3.2.3"/>
<j2ee.14 project="jboss"
Modified: jakarta/cactus/trunk/download.xml
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/download.xml?rev=293031&r1=293030&r2=293031&view=diff
==============================================================================
--- jakarta/cactus/trunk/download.xml (original)
+++ jakarta/cactus/trunk/download.xml Sat Oct 1 15:00:33 2005
@@ -116,6 +116,7 @@
<download jar="commons.httpclient"/>
<download jar="commons.logging"/>
<download jar="httpunit"/>
+ <download jar="htmlunit"/>
<download jar="jasper-compiler"/>
<download jar="jasper-runtime"/>
<download jar="jetty"/>
Modified: jakarta/cactus/trunk/framework/build.xml
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/framework/build.xml?rev=293031&r1=293030&r2=293031&view=diff
==============================================================================
--- jakarta/cactus/trunk/framework/build.xml (original)
+++ jakarta/cactus/trunk/framework/build.xml Sat Oct 1 15:00:33 2005
@@ -96,6 +96,7 @@
<echo> commons.httpclient.jar = [${commons.httpclient.jar}]</echo>
<echo> commons.logging.jar = [${commons.logging.jar}]</echo>
<echo> httpunit.jar = [${httpunit.jar}]</echo>
+ <echo> htmlunit.jar = [${htmlunit.jar}]</echo>
<echo> j2ee.jar = [${j2ee.jar}]</echo>
<echo> servlet.jar = [${servlet.jar}]</echo>
<echo> jsp.jar = [${jsp.jar}]</echo>
@@ -115,6 +116,7 @@
<pathelement location="${commons.logging.jar}"/>
<pathelement location="${commons.httpclient.jar}"/>
<pathelement location="${httpunit.jar}"/>
+ <pathelement location="${htmlunit.jar}"/>
<pathelement location="${j2ee.jar}"/>
<pathelement location="${servlet.jar}"/>
<pathelement location="${jsp.jar}"/>
@@ -128,6 +130,7 @@
<available file="${commons.httpclient.jar}"/>
<available file="${commons.logging.jar}"/>
<available file="${httpunit.jar}"/>
+ <available file="${htmlunit.jar}"/>
<available file="${j2ee.jar}"/>
<available file="${servlet.jar}"/>
<available file="${jsp.jar}"/>
Modified: jakarta/cactus/trunk/framework/project.xml
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/framework/project.xml?rev=293031&r1=293030&r2=293031&view=diff
==============================================================================
--- jakarta/cactus/trunk/framework/project.xml (original)
+++ jakarta/cactus/trunk/framework/project.xml Sat Oct 1 15:00:33 2005
@@ -60,6 +60,11 @@
<url>http://www.httpunit.org/</url>
</dependency>
<dependency>
+ <groupId>htmlunit</groupId>
+ <artifactId>htmlunit</artifactId>
+ <version>1.6</version>
+ </dependency>
+ <dependency>
<groupId>j2ee</groupId>
<artifactId>j2ee</artifactId>
<version>${cactus.j2ee.version.full}</version>
Modified: jakarta/cactus/trunk/framework/src/java/share-12-13-14/org/apache/cactus/internal/client/WebResponseObjectFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/framework/src/java/share-12-13-14/org/apache/cactus/internal/client/WebResponseObjectFactory.java?rev=293031&r1=293030&r2=293031&view=diff
==============================================================================
--- jakarta/cactus/trunk/framework/src/java/share-12-13-14/org/apache/cactus/internal/client/WebResponseObjectFactory.java (original)
+++ jakarta/cactus/trunk/framework/src/java/share-12-13-14/org/apache/cactus/internal/client/WebResponseObjectFactory.java Sat Oct 1 15:00:33 2005
@@ -19,9 +19,12 @@
*/
package org.apache.cactus.internal.client;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
+import java.net.URL;
import java.net.URLConnection;
import org.apache.cactus.Request;
@@ -66,6 +69,13 @@
{
responseObject = createHttpUnitWebResponse(this.connection);
+ // Is it a Html Unit WebResponse ?
+ }
+ else if (theClassName.equals(
+ "com.gargoylesoftware.htmlunit.WebResponse"))
+ {
+ responseObject = createHtmlUnitWebResponse(this.connection);
+
// Is it a Cactus WebResponse ?
}
else if (theClassName.equals("org.apache.cactus.WebResponse"))
@@ -115,6 +125,48 @@
new Class[] {URLConnection.class});
webResponse = method.invoke(null, new Object[] {theConnection});
+ }
+ catch (Exception e)
+ {
+ throw new ClientException("Error calling "
+ + "[public static com.meterware.httpunit.WebResponse "
+ + "com.meterware.httpunit.WebResponse.newResponse("
+ + "java.net.URLConnection) throws java.io.IOException]", e);
+ }
+
+ return webResponse;
+ }
+
+ /**
+ * Create a HtmlUnit <code>WebResponse</code> object by reflection (so
+ * that we don't need the HtmlUnit jar for users who are not using
+ * the HttpUnit endXXX() signature).
+ *
+ * @param theConnection the HTTP connection that was used when connecting
+ * to the server side and which now contains the returned HTTP
+ * response that we will pass to HttpUnit so that it can construct
+ * a <code>com.gargoylesoftware.htmlunit.WebResponse</code> object.
+ * @return a HtmlUnit <code>WebResponse</code> object
+ * @exception ClientException if it failes to create a HttpClient
+ * WebResponse object for any reason
+ */
+ private Object createHtmlUnitWebResponse(HttpURLConnection theConnection)
+ throws ClientException
+ {
+ Object webResponse;
+
+ try
+ {
+ Class responseClass = Class.forName(
+ "com.gargoylesoftware.htmlunit.StringWebResponse");
+ Constructor method = responseClass.getConstructor(
+ new Class[] {String.class, URL.class});
+
+ InputStream input = theConnection.getInputStream();
+ byte[] buffer = new byte[input.available()];
+ input.read(buffer);
+ webResponse = method.newInstance(new Object[] {new String(buffer),
+ theConnection.getURL()});
}
catch (Exception e)
{
Modified: jakarta/cactus/trunk/integration/ant/src/scripts/share/build-share.xml
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/integration/ant/src/scripts/share/build-share.xml?rev=293031&r1=293030&r2=293031&view=diff
==============================================================================
--- jakarta/cactus/trunk/integration/ant/src/scripts/share/build-share.xml (original)
+++ jakarta/cactus/trunk/integration/ant/src/scripts/share/build-share.xml Sat Oct 1 15:00:33 2005
@@ -69,7 +69,8 @@
value="${cactus.lib.common.dir}/@junit.jar.name@"/>
<property name="cactus.httpunit.jar"
value="${cactus.lib.common.dir}/@httpunit.jar.name@"/>
-
+ <property name="cactus.htmlunit.jar"
+ value="${cactus.lib.common.dir}/@htmlunit.jar.name@"/>
<property name="cactus.commons.httpclient.jar"
value="${cactus.lib.client.dir}/@commons.httpclient.jar.name@"/>
<property name="cactus.nekohtml.jar"
@@ -115,6 +116,7 @@
<pathelement location="${cactus.junit.jar}"/>
<pathelement location="${cactus.commons.httpclient.jar}"/>
<pathelement location="${cactus.httpunit.jar}"/>
+ <pathelement location="${cactus.htmlunit.jar}"/>
<path refid="cactus.classpath"/>
</classpath>
</javac>
@@ -234,6 +236,8 @@
file="${cactus.junit.jar}"/>
<copy todir="${cactus.target.dir}/${cactus.context}/WEB-INF/lib"
file="${cactus.httpunit.jar}"/>
+ <copy todir="${cactus.target.dir}/${cactus.context}/WEB-INF/lib"
+ file="${cactus.htmlunit.jar}"/>
<!-- Copy the JSP Redirector -->
<copy todir="${cactus.target.dir}/${cactus.context}">
@@ -320,6 +324,7 @@
<pathelement location="${cactus.junit.jar}"/>
<pathelement location="${cactus.commons.httpclient.jar}"/>
<pathelement location="${cactus.httpunit.jar}"/>
+ <pathelement location="${cactus.htmlunit.jar}"/>
<pathelement location="${cactus.nekohtml.jar}"/>
<pathelement location="${cactus.xerces.jar}"/>
<pathelement location="${cactus.xmlapis.jar}"/>
@@ -373,6 +378,7 @@
<pathelement location="${cactus.junit.jar}"/>
<pathelement location="${cactus.commons.httpclient.jar}"/>
<pathelement location="${cactus.httpunit.jar}"/>
+ <pathelement location="${cactus.htmlunit.jar}"/>
<pathelement location="${cactus.nekohtml.jar}"/>
<pathelement location="${cactus.xerces.jar}"/>
<pathelement location="${cactus.xmlapis.jar}"/>
Modified: jakarta/cactus/trunk/integration/maven/plugin.jelly
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/integration/maven/plugin.jelly?rev=293031&r1=293030&r2=293031&view=diff
==============================================================================
--- jakarta/cactus/trunk/integration/maven/plugin.jelly (original)
+++ jakarta/cactus/trunk/integration/maven/plugin.jelly Sat Oct 1 15:00:33 2005
@@ -36,7 +36,7 @@
<!--
========================================================================
- Verify that the instlaled Maven has compatible versions of dependent
+ Verify that the installed Maven has compatible versions of dependent
plugins.
========================================================================
-->
@@ -100,6 +100,7 @@
<ant:pathelement location="${plugin.getDependencyPath('commons-httpclient:commons-httpclient')}"/>
<ant:pathelement location="${plugin.getDependencyPath('aspectj:aspectjrt')}"/>
<ant:pathelement location="${plugin.getDependencyPath('httpunit:httpunit')}"/>
+ <ant:pathelement location="${plugin.getDependencyPath('htmlunit:htmlunit')}"/>
<ant:pathelement location="${plugin.getDependencyPath('nekohtml:nekohtml')}"/>
<ant:pathelement location="${plugin.getDependencyPath('xerces:xerces')}"/>
<ant:pathelement location="${plugin.getDependencyPath('xml-apis:xml-apis')}"/>
Modified: jakarta/cactus/trunk/samples/servlet/build.xml
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/samples/servlet/build.xml?rev=293031&r1=293030&r2=293031&view=diff
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/build.xml (original)
+++ jakarta/cactus/trunk/samples/servlet/build.xml Sat Oct 1 15:00:33 2005
@@ -134,6 +134,7 @@
<basename property="commons.logging.jar.name"
file="${commons.logging.jar}"/>
<basename property="httpunit.jar.name" file="${httpunit.jar}"/>
+ <basename property="htmlunit.jar.name" file="${htmlunit.jar}"/>
<basename property="junit.jar.name" file="${junit.jar}"/>
<basename property="nekohtml.jar.name" file="${nekohtml.jar}"/>
<basename property="log4j.jar.name" file="${log4j.jar}"/>
@@ -152,6 +153,7 @@
<filter token="commons.logging.jar.name"
value="${commons.logging.jar.name}"/>
<filter token="httpunit.jar.name" value="${httpunit.jar.name}"/>
+ <filter token="htmlunit.jar.name" value="${htmlunit.jar.name}"/>
<filter token="junit.jar.name" value="${junit.jar.name}"/>
<filter token="nekohtml.jar.name" value="${nekohtml.jar.name}"/>
<filter token="log4j.jar.name" value="${log4j.jar.name}"/>
@@ -175,6 +177,7 @@
<echo> commons.httpclient.jar = [${commons.httpclient.jar}]</echo>
<echo> commons.logging.jar = [${commons.logging.jar}]</echo>
<echo> httpunit.jar = [${httpunit.jar}]</echo>
+ <echo> htmlunit.jar = [${htmlunit.jar}]</echo>
<echo> servlet.jar = [${servlet.jar}]</echo>
<echo> junit.jar = [${junit.jar}]</echo>
<echo> log4j.jar = [${log4j.jar}]</echo>
@@ -197,6 +200,7 @@
<available file="${commons.httpclient.jar}"/>
<available file="${commons.logging.jar}"/>
<available file="${httpunit.jar}"/>
+ <available file="${htmlunit.jar}"/>
<available file="${servlet.jar}"/>
<available file="${log4j.jar}"/>
<or>
Modified: jakarta/cactus/trunk/samples/servlet/src/scripts/share/build.xml
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/samples/servlet/src/scripts/share/build.xml?rev=293031&r1=293030&r2=293031&view=diff
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/scripts/share/build.xml (original)
+++ jakarta/cactus/trunk/samples/servlet/src/scripts/share/build.xml Sat Oct 1 15:00:33 2005
@@ -112,6 +112,8 @@
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"
@@ -187,6 +189,7 @@
<classpath>
<path refid="cactus.classpath"/>
<pathelement location="${httpunit.jar}"/>
+ <pathelement location="${htmlunit.jar}"/>
<pathelement location="${nekohtml.jar}"/>
<pathelement location="${target.classes.java.dir}"/>
</classpath>
@@ -283,6 +286,7 @@
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 -->
Added: jakarta/cactus/trunk/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/servlet/unit/TestHtmlUnitIntegration.java
URL: http://svn.apache.org/viewcvs/jakarta/cactus/trunk/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/servlet/unit/TestHtmlUnitIntegration.java?rev=293031&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/servlet/unit/TestHtmlUnitIntegration.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/servlet/unit/TestHtmlUnitIntegration.java Sat Oct 1 15:00:33 2005
@@ -0,0 +1,92 @@
+/*
+ * ========================================================================
+ *
+ * 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.unit;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.apache.cactus.ServletTestCase;
+
+/**
+ * Test the HtmlpUnit integration.
+ *
+ * @version $Id$
+ */
+public class TestHtmlUnitIntegration extends ServletTestCase
+{
+ /**
+ * Verify that the HtmlUnit integration works.
+ *
+ * @exception IOException on test failure
+ */
+ public void testHtmlUnitGetText() throws IOException
+ {
+ PrintWriter pw = response.getWriter();
+
+ pw.print("something to return for the test");
+ }
+
+ /**
+ * Verify that HttpUnit integration works
+ *
+ * @param theResponse the response from the server side.
+ *
+ * @exception IOException on test failure
+ */
+ public void endHtmlUnitGetText(
+ com.gargoylesoftware.htmlunit.WebResponse theResponse) throws IOException
+ {
+ String text = theResponse.getContentAsString();
+
+ assertEquals("something to return for the test", text);
+ }
+
+ //-------------------------------------------------------------------------
+// TODO: I have never use HtmlUnit and I don't find the real equivalent for
+// this test. The next method failed.
+// /**
+// * Verify that we can set several headers in the response and
+// * assert them in endXXX().
+// */
+// public void testResponseAddHeadersHtmlUnit()
+// {
+// response.addHeader("X-Access-Header1", "value1");
+// response.addHeader("X-Access-Header2", "value2");
+// }
+//
+// /**
+// * Verify that we can set several headers in the response and
+// * assert them in endXXX().
+// *
+// * @param theResponse the response from the server side.
+// */
+// public void endResponseAddHeadersHtmlUnit(
+// com.gargoylesoftware.htmlunit.WebResponse theResponse)
+// {
+// String value1 =
+// theResponse.getResponseHeaderValue("X-Access-Header1");
+// String value2 =
+// theResponse.getResponseHeaderValue("X-Access-Header2");
+//
+// assertEquals("value1", value1);
+// assertEquals("value2", value2);
+// }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org