cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r611748 - in /cocoon/trunk: core/cocoon-webapp/ core/cocoon-webapp/src/test/ core/cocoon-webapp/src/test/java/ core/cocoon-webapp/src/test/java/org/ core/cocoon-webapp/src/test/java/org/apache/ core/cocoon-webapp/src/test/java/org/apache/co...
Date Mon, 14 Jan 2008 09:45:11 GMT
Author: reinhard
Date: Mon Jan 14 01:45:07 2008
New Revision: 611748

URL: http://svn.apache.org/viewvc?rev=611748&view=rev
Log:
enable integration tests for trunk: use the 'it'profile for that purpose (mvn install -P it)

Added:
    cocoon/trunk/core/cocoon-webapp/src/test/
    cocoon/trunk/core/cocoon-webapp/src/test/java/
    cocoon/trunk/core/cocoon-webapp/src/test/java/org/
    cocoon/trunk/core/cocoon-webapp/src/test/java/org/apache/
    cocoon/trunk/core/cocoon-webapp/src/test/java/org/apache/cocoon/
    cocoon/trunk/core/cocoon-webapp/src/test/java/org/apache/cocoon/it/
    cocoon/trunk/core/cocoon-webapp/src/test/java/org/apache/cocoon/it/servletservice/
    cocoon/trunk/core/cocoon-webapp/src/test/java/org/apache/cocoon/it/servletservice/RequestInformationPassing.java
  (with props)
    cocoon/trunk/tools/cocoon-it-fw/   (with props)
    cocoon/trunk/tools/cocoon-it-fw/pom.xml   (with props)
    cocoon/trunk/tools/cocoon-it-fw/src/
    cocoon/trunk/tools/cocoon-it-fw/src/main/
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyContainer.java
  (with props)
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStarterMojo.java
  (with props)
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStopperMojo.java
  (with props)
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HtmlUnitTestCase.java
  (with props)
    cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HttpClientResponse.java
  (with props)
Modified:
    cocoon/trunk/core/cocoon-webapp/pom.xml
    cocoon/trunk/parent/pom.xml

Modified: cocoon/trunk/core/cocoon-webapp/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-webapp/pom.xml?rev=611748&r1=611747&r2=611748&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-webapp/pom.xml (original)
+++ cocoon/trunk/core/cocoon-webapp/pom.xml Mon Jan 14 01:45:07 2008
@@ -106,10 +106,73 @@
       <groupId>org.apache.cocoon</groupId>
       <artifactId>cocoon-template-sample</artifactId>
     </dependency>
+
+    <!-- Integration Tests -->
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-it-fw</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <profiles>
     <profile>
+      <id>it</id>
+      <build>
+        <plugins>
+          <!-- Integration tests -->
+          <plugin>
+            <groupId>org.apache.cocoon</groupId>
+            <artifactId>cocoon-it-fw</artifactId>
+            <configuration>
+              <webAppDirectory>./target/cocoon-webapp</webAppDirectory>
+            </configuration>
+            <executions>
+              <execution>
+                <id>jetty-start</id>
+                <goals>
+                  <goal>jetty-start</goal>
+                </goals>
+                <phase>pre-integration-test</phase>
+              </execution>
+              <execution>
+                <id>jetty-stop</id>
+                <goals>
+                  <goal>jetty-stop</goal>
+                </goals>
+                <phase>post-integration-test</phase>
+              </execution>
+            </executions>
+          </plugin>
+          <plugin>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <excludes>
+                <exclude>**/cocoon/it/**</exclude>
+              </excludes>
+            </configuration>
+            <executions>
+              <execution>
+                <id>integration-test</id>
+                <goals>
+                  <goal>test</goal>
+                </goals>
+                <phase>integration-test</phase>
+                <configuration>
+                  <excludes>
+                    <exclude>none</exclude>
+                  </excludes>
+                  <includes>
+                    <include>**/cocoon/it/**</include>
+                  </includes>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    <profile>
       <id>allblocks</id>
       <dependencies>
         <dependency>
@@ -143,7 +206,7 @@
         <dependency>
           <groupId>org.apache.cocoon</groupId>
           <artifactId>cocoon-captcha-sample</artifactId>
-        </dependency>    
+        </dependency>
         <dependency>
           <groupId>org.apache.cocoon</groupId>
           <artifactId>cocoon-chaperon-sample</artifactId>
@@ -155,7 +218,7 @@
         <dependency>
           <groupId>org.apache.cocoon</groupId>
           <artifactId>cocoon-databases-sample</artifactId>
-        </dependency>    
+        </dependency>
         <dependency>
           <groupId>org.apache.cocoon</groupId>
           <artifactId>cocoon-deli-sample</artifactId>
@@ -252,7 +315,7 @@
         <dependency>
           <groupId>org.apache.cocoon</groupId>
           <artifactId>cocoon-portal-sample</artifactId>
-        </dependency>    
+        </dependency>
         <dependency>
           <groupId>org.apache.cocoon</groupId>
           <artifactId>cocoon-profiler-sample</artifactId>

Added: cocoon/trunk/core/cocoon-webapp/src/test/java/org/apache/cocoon/it/servletservice/RequestInformationPassing.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-webapp/src/test/java/org/apache/cocoon/it/servletservice/RequestInformationPassing.java?rev=611748&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-webapp/src/test/java/org/apache/cocoon/it/servletservice/RequestInformationPassing.java
(added)
+++ cocoon/trunk/core/cocoon-webapp/src/test/java/org/apache/cocoon/it/servletservice/RequestInformationPassing.java
Mon Jan 14 01:45:07 2008
@@ -0,0 +1,14 @@
+package org.apache.cocoon.it.servletservice;
+
+import junit.framework.Assert;
+
+import org.apache.cocoon.tools.it.HtmlUnitTestCase;
+
+public class RequestInformationPassing extends HtmlUnitTestCase {
+
+    public void testAttributes() throws Exception {
+        this.loadResponse("test1/test1");
+        Assert.assertTrue(this.response.getStatusCode() == 200);
+    }
+
+}

Propchange: cocoon/trunk/core/cocoon-webapp/src/test/java/org/apache/cocoon/it/servletservice/RequestInformationPassing.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/core/cocoon-webapp/src/test/java/org/apache/cocoon/it/servletservice/RequestInformationPassing.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/core/cocoon-webapp/src/test/java/org/apache/cocoon/it/servletservice/RequestInformationPassing.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/parent/pom.xml?rev=611748&r1=611747&r2=611748&view=diff
==============================================================================
--- cocoon/trunk/parent/pom.xml (original)
+++ cocoon/trunk/parent/pom.xml Mon Jan 14 01:45:07 2008
@@ -1047,7 +1047,7 @@
         <otherArchive>http://www.mail-archive.com/users@cocoon.apache.org/</otherArchive>
         <otherArchive>http://marc.theaimsgroup.com/?l=xml-cocoon-user</otherArchive>
         <otherArchive>http://news.gmane.org/gmane.text.xml.cocoon.user</otherArchive>
-        <otherArchive>http://cocoon.markmail.org/search/list:org.apache.cocoon.users</otherArchive>
       
+        <otherArchive>http://cocoon.markmail.org/search/list:org.apache.cocoon.users</otherArchive>
       </otherArchives>
     </mailingList>
     <mailingList>
@@ -2109,12 +2109,6 @@
         <version>1.1</version>
       </dependency>
       <dependency>
-        <groupId>xmlunit</groupId>
-        <artifactId>xmlunit</artifactId>
-        <version>0.8</version>
-        <scope>test</scope>
-      </dependency>
-      <dependency>
         <groupId>org.outerj.xreporter</groupId>
         <artifactId>xreporter-expression</artifactId>
         <version>1.2.1.1</version>
@@ -2124,6 +2118,45 @@
         <artifactId>xreporter-grouping</artifactId>
         <version>1.2.1.1</version>
       </dependency>
+      <dependency>
+        <groupId>org.apache.maven</groupId>
+        <artifactId>maven-plugin-api</artifactId>
+        <version>2.0</version>
+      </dependency>
+      <dependency>
+        <groupId>org.mortbay.jetty</groupId>
+        <artifactId>jetty</artifactId>
+        <version>6.1.6</version>
+      </dependency>
+      <dependency>
+        <groupId>org.mortbay.jetty</groupId>
+        <artifactId>jetty-util</artifactId>
+        <version>6.1.6</version>
+      </dependency>
+      <dependency>
+        <groupId>org.mortbay.jetty</groupId>
+        <artifactId>servlet-api-2.5</artifactId>
+        <version>6.1.6</version>
+      </dependency>
+      <dependency>
+        <groupId>htmlunit</groupId>
+        <artifactId>htmlunit</artifactId>
+        <version>1.13</version>
+        <scope>test</scope>
+        <exclusions>
+          <exclusion>
+            <groupId>avalon-framework</groupId>
+            <artifactId>avalon-framework</artifactId>
+          </exclusion>
+        </exclusions>
+      </dependency>
+      <dependency>
+        <groupId>xmlunit</groupId>
+        <artifactId>xmlunit</artifactId>
+        <version>1.1</version>
+        <scope>test</scope>
+      </dependency>
+
       <!-- Cocoon SNAPSHOT dependencies -->
       <dependency>
         <groupId>org.apache.cocoon</groupId>
@@ -2412,6 +2445,12 @@
         <groupId>org.apache.cocoon</groupId>
         <artifactId>cocoon-imageop-sample</artifactId>
         <version>1.0.0-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.cocoon</groupId>
+        <artifactId>cocoon-it-fw</artifactId>
+        <version>1.0.0-SNAPSHOT</version>
+        <scope>test</scope>
       </dependency>
       <dependency>
         <groupId>org.apache.cocoon</groupId>

Propchange: cocoon/trunk/tools/cocoon-it-fw/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jan 14 01:45:07 2008
@@ -0,0 +1,4 @@
+.settings
+target
+.classpath
+.project

Added: cocoon/trunk/tools/cocoon-it-fw/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-it-fw/pom.xml?rev=611748&view=auto
==============================================================================
--- cocoon/trunk/tools/cocoon-it-fw/pom.xml (added)
+++ cocoon/trunk/tools/cocoon-it-fw/pom.xml Mon Jan 14 01:45:07 2008
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you 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.
+-->
+<!-- @version $Id$ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>maven-plugin</packaging>
+
+  <parent>
+    <artifactId>cocoon-tools-modules</artifactId>
+    <groupId>org.apache.cocoon</groupId>
+    <version>5-SNAPSHOT</version>
+  </parent>
+  <artifactId>cocoon-it-fw</artifactId>
+
+  <version>1.0.0-SNAPSHOT</version>
+  <name>Cocoon Integration Test Framework [maven-plugin]</name>
+  <dependencies>
+    <!-- The Maven 2 plugin -->
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty-util</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>servlet-api-2.5</artifactId>
+    </dependency>
+    <!-- Base libraries for integration tests -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>htmlunit</groupId>
+      <artifactId>htmlunit</artifactId>
+      <scope>compile</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>avalon-framework</groupId>
+          <artifactId>avalon-framework</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>xmlunit</groupId>
+      <artifactId>xmlunit</artifactId>
+      <scope>compile</scope>
+    </dependency>
+  </dependencies>
+
+</project>

Propchange: cocoon/trunk/tools/cocoon-it-fw/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-it-fw/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-it-fw/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyContainer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyContainer.java?rev=611748&view=auto
==============================================================================
--- cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyContainer.java
(added)
+++ cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyContainer.java
Mon Jan 14 01:45:07 2008
@@ -0,0 +1,34 @@
+package org.apache.cocoon.maven.test.jetty;
+
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.webapp.WebAppContext;
+
+public class JettyContainer {
+
+    private static Server jetty;
+    private int port;
+
+    void start(String contextPath, String webappPath, int port) throws Exception {
+        this.port = port;
+        WebAppContext webContext = new WebAppContext(webappPath, contextPath);
+        JettyContainer.jetty = new Server();
+        Connector connector = new SelectChannelConnector();
+        connector.setPort(port);
+        JettyContainer.jetty.setConnectors(new Connector[] { connector });
+        JettyContainer.jetty.addHandler(webContext);
+        JettyContainer.jetty.start();
+    }
+
+    void stop() throws Exception {
+        if (JettyContainer.jetty != null) {
+            JettyContainer.jetty.stop();
+        }
+    }
+
+    public int getPort() {
+        return this.port;
+    }
+
+}
\ No newline at end of file

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyContainer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyContainer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyContainer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStarterMojo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStarterMojo.java?rev=611748&view=auto
==============================================================================
--- cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStarterMojo.java
(added)
+++ cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStarterMojo.java
Mon Jan 14 01:45:07 2008
@@ -0,0 +1,41 @@
+package org.apache.cocoon.maven.test.jetty;
+
+import java.io.File;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * Start all servers to run the Cocoon integration tests.
+ *
+ * @goal jetty-start
+ */
+public class JettyStarterMojo extends AbstractMojo {
+
+    /**
+     * The absolute path to the web application under test.
+     *
+     * @parameter
+     * @required
+     */
+    private File webAppDirectory;
+
+    /**
+     * @parameter
+     */
+    private boolean skip;
+
+    public void execute() throws MojoExecutionException {
+        if (this.skip) {
+            this.getLog().info("Skip starting server environment.");
+            return;
+        }
+        try {
+            new JettyContainer().start("/", webAppDirectory.getAbsolutePath(), 8888);
+        } catch (Exception e) {
+            throw new MojoExecutionException("Can't start Jetty.", e);
+        }
+    }
+
+
+}

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStarterMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStarterMojo.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStarterMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStopperMojo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStopperMojo.java?rev=611748&view=auto
==============================================================================
--- cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStopperMojo.java
(added)
+++ cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStopperMojo.java
Mon Jan 14 01:45:07 2008
@@ -0,0 +1,30 @@
+package org.apache.cocoon.maven.test.jetty;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+/**
+ * Stop all JettyContainer instances.
+ *
+ * @goal jetty-stop
+ */
+public class JettyStopperMojo extends AbstractMojo {
+
+    /**
+     * @parameter
+     */
+    private boolean skip;
+
+    public void execute() throws MojoExecutionException {
+        if (this.skip) {
+            this.getLog().info("Skip starting server environment.");
+            return;
+        }
+
+        try {
+            new JettyContainer().stop();
+        } catch (Exception e) {
+            this.getLog().error("Can't stop JettyContainer. ", e);
+        }
+    }
+}

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStopperMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStopperMojo.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/maven/test/jetty/JettyStopperMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HtmlUnitTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HtmlUnitTestCase.java?rev=611748&view=auto
==============================================================================
--- cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HtmlUnitTestCase.java
(added)
+++ cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HtmlUnitTestCase.java
Mon Jan 14 01:45:07 2008
@@ -0,0 +1,189 @@
+package org.apache.cocoon.tools.it;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.SimpleNamespaceContext;
+import org.jaxen.XPath;
+import org.jaxen.dom.DOMXPath;
+import org.w3c.dom.Document;
+
+import com.gargoylesoftware.htmlunit.Page;
+import com.gargoylesoftware.htmlunit.SubmitMethod;
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.WebRequestSettings;
+import com.gargoylesoftware.htmlunit.WebResponse;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.gargoylesoftware.htmlunit.html.xpath.HtmlUnitXPath;
+import com.gargoylesoftware.htmlunit.xml.XmlPage;
+
+/**
+ * This class is useful as base class for JUnit TestCase classes to setup an
+ * environment which makes it possible to easily test web pages. First call one
+ * of the load methods and then assert on the response object, XML document
+ * (@see loadXmlPage), or HTML document (@see loadHtmlPage).
+ *
+ * @version $Id$
+ */
+public abstract class HtmlUnitTestCase extends TestCase {
+
+    private static final String BASEURL = "http://localhost:8888";
+
+    protected Log log = LogFactory.getLog(this.getClass());
+
+    /**
+     * Low-level access to WebClient object.
+     */
+    protected WebClient webClient;
+
+    /**
+     * Low-level access to WebResponse object.
+     */
+    protected WebResponse response;
+
+    /**
+     * Low-level access to XML document (org.w3c.dom.Document) or HTML document
+     * (com.gargoylesoftware.htmlunit.html.HtmlPage).
+     */
+    protected Object document;
+
+    /**
+     * Low-level access to namespace mappings for XPath expressions.
+     */
+    protected Map namespaces = new HashMap();
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        this.webClient = new WebClient();
+        this.webClient.setRedirectEnabled(false);
+        this.namespaces.clear();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        this.response = null;
+        this.document = null;
+        this.webClient = null;
+    }
+
+
+    protected URL setupBaseUrl() throws Exception {
+        String baseUrl = System.getProperty("htmlunit.base-url");
+        if (baseUrl == null) {
+            baseUrl = BASEURL;
+        }
+        return new URL(baseUrl);
+    }
+
+    /**
+     * Sends HTTP GET request and loads response object.
+     */
+    protected void loadResponse(String pageURL) throws Exception {
+        URL url = new URL(this.setupBaseUrl(), pageURL);
+        this.response = this.webClient.loadWebResponse(new WebRequestSettings(url, SubmitMethod.GET));
+    }
+
+    /**
+     * Sends HTTP DELETE request and loads response object.
+     */
+    protected void loadDeleteResponse(String pageURL) throws Exception {
+        URL url = new URL(this.setupBaseUrl(), pageURL);
+        DeleteMethod method = new DeleteMethod(url.toExternalForm());
+        this.response = new HttpClientResponse(url, method);
+    }
+
+    /**
+     * Sends HTTP PUT request and loads response object.
+     */
+    protected void loadPutResponse(String pageURL, String content) throws Exception {
+        URL url = new URL(this.setupBaseUrl(), pageURL);
+        PutMethod method = new PutMethod(url.toExternalForm());
+        method.setRequestEntity(new StringRequestEntity(content));
+        this.response = new HttpClientResponse(url, method);
+    }
+
+    /**
+     * Sends HTTP POST request and loads response object.
+     */
+    protected void loadPostResponse(String pageURL, String content) throws Exception {
+        URL url = new URL(this.setupBaseUrl(), pageURL);
+        PostMethod method = new PostMethod(url.toExternalForm());
+        method.setRequestEntity(new StringRequestEntity(content));
+        this.response = new HttpClientResponse(url, method);
+    }
+
+    /**
+     * Sends HTTP request and parses response as HTML document.
+     */
+    protected void loadHtmlPage(String pageURL) throws Exception {
+        URL url = new URL(this.setupBaseUrl(), pageURL);
+        Page page = this.webClient.getPage(url);
+        this.response = page.getWebResponse();
+        assertTrue("Response should be an HTML page", page instanceof HtmlPage);
+        this.document = page;
+        assertNotNull("Response contains invalid HTML", this.document);
+    }
+
+    /**
+     * Sends HTTP request and parses response as XML document.
+     */
+    protected void loadXmlPage(String pageURL) throws Exception {
+        URL url = new URL(this.setupBaseUrl(), pageURL);
+        Page page = this.webClient.getPage(url);
+        this.response = page.getWebResponse();
+        assertTrue("Response should be an XML page", page instanceof XmlPage);
+        XmlPage xmlPage = (XmlPage) page;
+        this.document = xmlPage.getXmlDocument();
+        assertNotNull("Response contains invalid XML", this.document);
+    }
+
+    /**
+     * Returns XPath expression as string.
+     *
+     * @param xpathExpr
+     *            XPath expression
+     *
+     * @return Value of XPath expression in current document. Empty string if
+     *         XPath not matched.
+     */
+    protected String evalXPath(String xpathExpr) throws Exception {
+        XPath xpath = null;
+        if (this.document == null) {
+            return null;
+        } else if (this.document instanceof HtmlPage) {
+            xpath = new HtmlUnitXPath(xpathExpr);
+        } else if (this.document instanceof Document) {
+            xpath = new DOMXPath(xpathExpr);
+        } else {
+            fail("Document type " + this.document.getClass().getName());
+        }
+
+        xpath.setNamespaceContext(new SimpleNamespaceContext(this.namespaces));
+
+        return xpath.stringValueOf(this.document);
+    }
+
+    /**
+     * Add a namespace mapping for XPath expressions.
+     */
+    protected void addNamespace(String prefix, String uri) throws Exception {
+        this.namespaces.put(prefix, uri);
+    }
+
+    /**
+     * Assert that XPath expression result matches exactly expected value.
+     */
+    protected void assertXPath(String xpathExpr, String expected) throws Exception {
+        assertEquals(xpathExpr, expected, this.evalXPath(xpathExpr));
+    }
+
+}

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HtmlUnitTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HtmlUnitTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HtmlUnitTestCase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HttpClientResponse.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HttpClientResponse.java?rev=611748&view=auto
==============================================================================
--- cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HttpClientResponse.java
(added)
+++ cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HttpClientResponse.java
Mon Jan 14 01:45:07 2008
@@ -0,0 +1,91 @@
+package org.apache.cocoon.tools.it;
+
+import com.gargoylesoftware.htmlunit.SubmitMethod;
+import com.gargoylesoftware.htmlunit.WebResponse;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethodBase;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+
+class HttpClientResponse implements WebResponse {
+    private URL url;
+
+    private HttpMethodBase method;
+
+    private int statusCode;
+
+    private long loadTime;
+
+    HttpClientResponse(URL url, HttpMethodBase method) throws IOException {
+        long t0 = System.currentTimeMillis();
+        this.url = url;
+        this.method = method;
+        HttpClient client = new HttpClient();
+        statusCode = client.executeMethod(method);
+        long t1 = System.currentTimeMillis();
+        this.loadTime = t1 - t0;
+    }
+
+    public int getStatusCode() {
+        return statusCode;
+    }
+
+    public String getStatusMessage() {
+        return method.getStatusText();
+    }
+
+    public String getContentType() {
+        return method.getResponseHeader("Content-type").getValue();
+    }
+
+    public String getContentAsString() {
+        try {
+            return method.getResponseBodyAsString();
+        } catch (IOException ex) {
+            return null;
+        }
+    }
+
+    public InputStream getContentAsStream() throws IOException {
+        return method.getResponseBodyAsStream();
+    }
+
+    public URL getUrl() {
+        return url;
+    }
+
+    public String getResponseHeaderValue(String headerName) {
+        return method.getResponseHeader(headerName).getValue();
+    }
+
+    public long getLoadTimeInMilliSeconds() {
+        return loadTime;
+    }
+
+    public String getContentCharSet() {
+        return method.getResponseCharSet();
+    }
+
+    public byte[] getResponseBody() {
+        try {
+            return method.getResponseBody();
+        } catch (IOException ex) {
+            return null;
+        }
+    }
+
+    public SubmitMethod getRequestMethod() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public List getResponseHeaders() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HttpClientResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HttpClientResponse.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/trunk/tools/cocoon-it-fw/src/main/java/org/apache/cocoon/tools/it/HttpClientResponse.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message