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 pt...@apache.org on 2008/09/24 15:20:12 UTC
svn commit: r698559 [1/3] - in /jakarta/cactus/trunk/samples/servlet: ./
src/main/java/org/apache/cactus/sample/servlet/
src/main/java/org/apache/cactus/sample/servlet/unit/ src/test/
src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test...
Author: ptahchiev
Date: Wed Sep 24 06:20:11 2008
New Revision: 698559
URL: http://svn.apache.org/viewvc?rev=698559&view=rev
Log:
Moved the tests to the src/test/java directory, where they actually should be. Also changed the surefire plugin declaration to point to them.
Added:
jakarta/cactus/trunk/samples/servlet/src/test/
jakarta/cactus/trunk/samples/servlet/src/test/java/
jakarta/cactus/trunk/samples/servlet/src/test/java/org/
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleBodyTag.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleFilter.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleJunit.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleServlet.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleServletConfig.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleTag.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestAll.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestBasicAuthentication.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestClientServerSynchronization.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestCookie.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestFilterHttpHeaders.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestGlobalBeginEnd.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHtmlUnitIntegration.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpHeaders.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpParameters.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpRequest.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpRequestSpecific.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpResponse.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpSession.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpUnitIntegration.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestJUnitTestCaseWrapper.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestJspOut.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestJspPageContext.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestJspTagLifecycle.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestRequestDispatcher.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestServerSideExceptions.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestServletConfig.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestServletContext.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestServletRedirectorOverride.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestSetURL.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestSetURLSpecific.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestSetUpTearDown.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestShareAll.java (with props)
jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestTearDownException.java (with props)
Removed:
jakarta/cactus/trunk/samples/servlet/src/main/java/org/apache/cactus/sample/servlet/TestSampleBodyTag.java
jakarta/cactus/trunk/samples/servlet/src/main/java/org/apache/cactus/sample/servlet/TestSampleFilter.java
jakarta/cactus/trunk/samples/servlet/src/main/java/org/apache/cactus/sample/servlet/TestSampleServlet.java
jakarta/cactus/trunk/samples/servlet/src/main/java/org/apache/cactus/sample/servlet/TestSampleServletConfig.java
jakarta/cactus/trunk/samples/servlet/src/main/java/org/apache/cactus/sample/servlet/TestSampleTag.java
jakarta/cactus/trunk/samples/servlet/src/main/java/org/apache/cactus/sample/servlet/unit/
Modified:
jakarta/cactus/trunk/samples/servlet/pom.xml
Modified: jakarta/cactus/trunk/samples/servlet/pom.xml
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/pom.xml?rev=698559&r1=698558&r2=698559&view=diff
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/pom.xml (original)
+++ jakarta/cactus/trunk/samples/servlet/pom.xml Wed Sep 24 06:20:11 2008
@@ -152,6 +152,12 @@
<destFile>${project.build.directory}/${pom.artifactId}-cactified.war</destFile>
<!--installLocally>true</installLocally-->
<mergeWebXml>src/main/webapp/WEB-INF/cactus-web.xml</mergeWebXml>
+ <testClasses>
+ <directory>target/test-classes</directory>
+ <includes>
+ <include>**/**Test*.class</include>
+ </includes>
+ </testClasses>
<libDependencies>
<dependency>
<groupId>javax.servlet</groupId>
@@ -251,8 +257,8 @@
<skip>false</skip>
<!--The next line is because we need the tests in src/main/java to ensure
that the classes are included in the archive.-->
- <testSourceDirectory>src/main/java</testSourceDirectory>
- <testClassesDirectory>target/classes</testClassesDirectory>
+ <!--testSourceDirectory>src/test/java</testSourceDirectory>
+ <testClassesDirectory>target/test-classes</testClassesDirectory-->
<systemProperties>
<property>
<name>cactus.contextURL</name>
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleBodyTag.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleBodyTag.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleBodyTag.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleBodyTag.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,113 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet;
+
+import javax.servlet.jsp.tagext.BodyContent;
+import javax.servlet.jsp.tagext.BodyTag;
+
+import org.apache.cactus.JspTestCase;
+import org.apache.cactus.WebResponse;
+
+/**
+ * Tests of the <code>SampleBodyTag</code> class.
+ *
+ * @version $Id: TestSampleBodyTag.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestSampleBodyTag extends JspTestCase
+{
+ /**
+ * Our tag instance being unit tested
+ */
+ private SampleBodyTag tag;
+
+ /**
+ * The tag body content to which we can write to in our unit tests
+ * to simulate a content.
+ */
+ private BodyContent tagContent;
+
+ /**
+ * In addition to creating the tag instance and adding the pageContext to
+ * it, this method creates a BodyContent object and passes it to the tag.
+ */
+ public void setUp()
+ {
+ this.tag = new SampleBodyTag();
+ this.tag.setPageContext(this.pageContext);
+
+ //create the BodyContent object and call the setter on the tag instance
+ this.tagContent = this.pageContext.pushBody();
+ this.tag.setBodyContent(this.tagContent);
+ }
+
+ /**
+ * @see TestCase#tearDown()
+ */
+ public void tearDown()
+ {
+ //necessary for tag to output anything on most servlet engines.
+ this.pageContext.popBody();
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Sets the replacement target and replacement String on the tag, then calls
+ * doAfterBody(). Most of the assertion work is done in endReplacement().
+ *
+ * @exception Exception if the test fails for an unexpected reason
+ */
+ public void testReplacement() throws Exception
+ {
+ //set the target and the String to replace it with
+ this.tag.setTarget("@target@");
+ this.tag.setReplacement("replacement");
+
+ //add the tag's body by writing to the BodyContent object created in
+ //setUp()
+ this.tagContent.println("@target@ is now @target@");
+ this.tagContent.println("@target@_@target@");
+
+ //none of the other life cycle methods need to be implemented, so they
+ //do not need to be called.
+ int result = this.tag.doAfterBody();
+
+ assertEquals(BodyTag.SKIP_BODY, result);
+ }
+
+ /**
+ * Verifies that the target String has indeed been replaced in the tag's
+ * body.
+ *
+ * @param theResponse the response from the server side.
+ */
+ public void endReplacement(WebResponse theResponse)
+ {
+ String content = theResponse.getText();
+
+ assertTrue("Response should have contained the ["
+ + "replacement is now replacement] string",
+ content.indexOf("replacement is now replacement") > -1);
+ assertTrue("Response should have contained the ["
+ + "replacement_replacement] string",
+ content.indexOf("replacement") > -1);
+ }
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleBodyTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleFilter.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleFilter.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleFilter.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleFilter.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,185 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.cactus.FilterTestCase;
+import org.apache.cactus.WebResponse;
+
+/**
+ * Tests of the <code>SampleFilter</code> filter class.
+ *
+ * @version $Id: TestSampleFilter.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestSampleFilter extends FilterTestCase
+{
+ /**
+ * Test that adding a header to the output stream is working fine when
+ * a header parameter is defined.
+ *
+ * @exception ServletException on test failure
+ * @exception IOException on test failure
+ */
+ public void testAddHeaderParamOK() throws ServletException, IOException
+ {
+ SampleFilter filter = new SampleFilter();
+
+ config.setInitParameter("header", "<h1>header</h1>");
+ filter.init(config);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ filter.addHeader(baos);
+
+ assertEquals("<h1>header</h1>", baos.toString());
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Test that adding a header to the output stream is working fine
+ * (i.e. nothing gets written) when no header parameter is defined.
+ *
+ * @exception ServletException on test failure
+ * @exception IOException on test failure
+ */
+ public void testAddHeaderParamNotDefined() throws ServletException,
+ IOException
+ {
+ SampleFilter filter = new SampleFilter();
+
+ filter.init(config);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ filter.addHeader(baos);
+
+ assertEquals("", baos.toString());
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Test that adding a footer to the output stream is working fine when
+ * a footer parameter is defined.
+ *
+ * @exception ServletException on test failure
+ * @exception IOException on test failure
+ */
+ public void testAddFooterParamOK() throws ServletException, IOException
+ {
+ SampleFilter filter = new SampleFilter();
+
+ config.setInitParameter("footer", "<h1>footer</h1>");
+ filter.init(config);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ filter.addFooter(baos);
+
+ assertEquals("<h1>footer</h1>", baos.toString());
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Test that adding a footer to the output stream is working fine
+ * (i.e. nothing gets written) when no footer parameter is defined.
+ *
+ * @exception ServletException on test failure
+ * @exception IOException on test failure
+ */
+ public void testAddFooterParamNotDefined() throws ServletException,
+ IOException
+ {
+ SampleFilter filter = new SampleFilter();
+
+ filter.init(config);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ filter.addFooter(baos);
+
+ assertEquals("", baos.toString());
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Test that the filter does correctly add a header and footer to
+ * any requets it is serving.
+ *
+ * @exception ServletException on test failure
+ * @exception IOException on test failure
+ */
+ public void testDoFilterOK() throws ServletException, IOException
+ {
+ SampleFilter filter = new SampleFilter();
+
+ config.setInitParameter("header", "<h1>header</h1>");
+ config.setInitParameter("footer", "<h1>footer</h1>");
+ filter.init(config);
+
+ FilterChain mockFilterChain = new FilterChain()
+ {
+ public void doFilter(ServletRequest theRequest,
+ ServletResponse theResponse) throws IOException,
+ ServletException
+ {
+ PrintWriter writer = theResponse.getWriter();
+
+ writer.print("<p>some content</p>");
+ writer.close();
+ }
+
+ public void init(FilterConfig theConfig)
+ {
+ }
+
+ public void destroy()
+ {
+ }
+ };
+
+ filter.doFilter(request, response, mockFilterChain);
+ }
+
+ /**
+ * Test that the filter does correctly add a header and footer to
+ * any requets it is serving.
+ *
+ * @param theResponse the response from the server side.
+ */
+ public void endDoFilterOK(WebResponse theResponse)
+ {
+ assertEquals("<h1>header</h1><p>some content</p><h1>footer</h1>",
+ theResponse.getText());
+ }
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleJunit.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleJunit.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleJunit.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleJunit.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,14 @@
+package org.apache.cactus.sample.servlet;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+import org.apache.cactus.ServletTestCase;
+
+public class TestSampleJunit
+{
+ @Test
+ public void blablaMetod() {
+ assertEquals(0,0);
+ }
+
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleJunit.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleServlet.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleServlet.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleServlet.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleServlet.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,404 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet;
+
+import java.io.IOException;
+
+import java.net.URLDecoder;
+
+import java.util.Hashtable;
+
+import org.apache.cactus.Cookie;
+import org.apache.cactus.ServletTestCase;
+import org.apache.cactus.WebRequest;
+import org.apache.cactus.WebResponse;
+
+/**
+ * Tests of the <code>SampleServlet</code> servlet class.
+ *
+ * @version $Id: TestSampleServlet.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestSampleServlet extends ServletTestCase
+{
+ /**
+ * Verify that we can assert the servlet output stream.
+ *
+ * @exception IOException on test failure
+ */
+ public void testReadServletOutputStream() throws IOException
+ {
+ SampleServlet servlet = new SampleServlet();
+
+ servlet.doGet(request, response);
+ }
+
+ /**
+ * Verify that we can assert the servlet output stream.
+ *
+ * @param theResponse the response from the server side.
+ *
+ * @exception IOException on test failure
+ */
+ public void endReadServletOutputStream(WebResponse theResponse)
+ throws IOException
+ {
+ String expected = "<html><head/><body>A GET request</body></html>";
+ String result = theResponse.getText();
+
+ assertEquals(expected, result);
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that we can simulate a POST request to a servlet. Note that
+ * we send a parameter to force a POST.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginPostMethod(WebRequest theRequest)
+ {
+ theRequest.addParameter("param", "value", WebRequest.POST_METHOD);
+ }
+
+ /**
+ * Verify that we can simulate a POST request to a servlet. Note that
+ * we send a parameter to force a POST. Otherwise Cactus will do a GET
+ * by default.
+ */
+ public void testPostMethod()
+ {
+ SampleServlet servlet = new SampleServlet();
+
+ assertEquals("POST", servlet.checkMethod(request));
+ assertEquals("value", request.getParameter("param"));
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that we can simulate a GET request to a servlet. Note: Cactus
+ * does a GET by default.
+ */
+ public void testGetMethod()
+ {
+ SampleServlet servlet = new SampleServlet();
+
+ assertEquals("GET", servlet.checkMethod(request));
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that by default the session implicit object is available and can
+ * be used.
+ */
+ public void testSetAttribute()
+ {
+ SampleServlet servlet = new SampleServlet();
+
+ servlet.setSessionVariable(request);
+
+ assertNotNull(session);
+ assertEquals("value_setSessionVariable",
+ session.getAttribute("name_setSessionVariable"));
+ }
+
+ /**
+ * Verify that we can set an attribute in the request.
+ */
+ public void testSetRequestAttribute()
+ {
+ SampleServlet servlet = new SampleServlet();
+
+ servlet.setRequestAttribute(request);
+
+ assertEquals("value_setRequestAttribute",
+ request.getAttribute("name_setRequestAttribute"));
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that we can simulate HTTP parameters in the HTTP request.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginSendParams(WebRequest theRequest)
+ {
+ theRequest.addParameter("param1", "value1");
+ theRequest.addParameter("param2", "value2");
+ }
+
+ /**
+ * Verify that we can send several parameters in the HTTP request.
+ */
+ public void testSendParams()
+ {
+ SampleServlet servlet = new SampleServlet();
+ Hashtable params = servlet.getRequestParameters(request);
+
+ assertNotNull(params.get("param1"));
+ assertNotNull(params.get("param2"));
+ assertEquals("value1", params.get("param1"));
+ assertEquals("value2", params.get("param2"));
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that we can simulate HTTP headers in the HTTP request.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginSendHeader(WebRequest theRequest)
+ {
+ theRequest.addHeader("testheader", "this is a header test");
+ }
+
+ /**
+ * Verify that we can simulate HTTP headers in the HTTP request.
+ */
+ public void testSendHeader()
+ {
+ SampleServlet servlet = new SampleServlet();
+ String headerValue = servlet.getRequestHeader(request);
+
+ assertEquals("this is a header test", headerValue);
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that we can simulate a single cookie sent in the HTTP request.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginSendCookie(WebRequest theRequest)
+ {
+ // Note: The cookie value that was chosen is a string without spaces
+ // because there is a problem with Resin 1.2.1 which does not support
+ // quoted cookies. It has been fixed since the 15/12/2000 release of
+ // Resin.
+ theRequest.addCookie("testcookie", "thisisacookie");
+ }
+
+ /**
+ * Verify that we can simulate a single cookie sent in the HTTP request.
+ */
+ public void testSendCookie()
+ {
+ SampleServlet servlet = new SampleServlet();
+ Hashtable cookies = servlet.getRequestCookies(request);
+
+ assertNotNull("Cannot find [testcookie] cookie in request",
+ cookies.get("testcookie"));
+ assertEquals("thisisacookie", cookies.get("testcookie"));
+ }
+
+ /**
+ * Verify that we can simulate multiple cookies sent in the HTTP request.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginSendMultipleCookies(WebRequest theRequest)
+ {
+ theRequest.addCookie("testcookie1", "cookie1");
+ theRequest.addCookie("testcookie2", "cookie2");
+ }
+
+ /**
+ * Verify that we can simulate multiple cookies sent in the HTTP request.
+ */
+ public void testSendMultipleCookies()
+ {
+ SampleServlet servlet = new SampleServlet();
+ Hashtable cookies = servlet.getRequestCookies(request);
+
+ assertNotNull(cookies.get("testcookie1"));
+ assertEquals("cookie1", cookies.get("testcookie1"));
+
+ assertNotNull(cookies.get("testcookie2"));
+ assertEquals("cookie2", cookies.get("testcookie2"));
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that it is possible to send back a header and verify it on the
+ * client side.
+ */
+ public void testReceiveHeader()
+ {
+ SampleServlet servlet = new SampleServlet();
+
+ servlet.setResponseHeader(response);
+ }
+
+ /**
+ * Verify that it is possible to send back a header and verify it on the
+ * client side.
+ *
+ * @param theResponse the response from the server side.
+ */
+ public void endReceiveHeader(WebResponse theResponse)
+ {
+ assertEquals("this is a response header",
+ theResponse.getConnection().getHeaderField("responseheader"));
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Test that it is possible to send back a Cookie and verify it on the
+ * client side.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginReceiveCookie(WebRequest theRequest)
+ {
+ // Why do we need to have a begin method here ? Good question !
+ // The answer is that in this test, the SampleServlet's
+ // setResponseCookie() method sets the domain name of the cookie
+ // to return to jakarta.apache.org. It means that for this cookie
+ // to be valid the domain of the request (i.e. the host) must be
+ // jakarta.apache.org (this is according to the cookies RFCs). Thus
+ // we need to simulate the URL and act as if we had sent a request
+ // to jakarta.apache.org ! Logical, no ?
+ theRequest.setURL("jakarta.apache.org", null, null, null, null);
+ }
+
+ /**
+ * Test that it is possible to send back a Cookie and verify it on the
+ * client side.
+ */
+ public void testReceiveCookie()
+ {
+ SampleServlet servlet = new SampleServlet();
+
+ servlet.setResponseCookie(response);
+ }
+
+ /**
+ * Test that it is possible to send back a Cookie and verify it on the
+ * client side.
+ *
+ * @param theResponse the response from the server side.
+ *
+ * @exception Exception for backward compatibility with JDK 1.2.2 (not
+ * needed for JDK 1.3+, but needed for URLDecoder.decode())
+ */
+ public void endReceiveCookie(WebResponse theResponse) throws Exception
+ {
+ Cookie cookie = theResponse.getCookie("responsecookie");
+
+ assertNotNull("Cannot find [responsecookie]", cookie);
+ assertEquals("responsecookie", cookie.getName());
+
+
+ // Some servers may encode the cookie value (ex: the latest
+ // version of Tomcat 4.0). In order for this test to succeed on
+ // all servlet engine, we URL decode the cookie value before
+ // comparing it.
+ assertEquals("this is a response cookie",
+ URLDecoder.decode(cookie.getValue()));
+
+ assertEquals("jakarta.apache.org", cookie.getDomain());
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that we can use a <code>RequestDispatcher</code> in the class to
+ * test to forward to another page and compare the result sent to the
+ * output stream on the client side.
+ *
+ * @exception Exception on test failure
+ */
+ public void testRequestDispatcherForward() throws Exception
+ {
+ SampleServlet servlet = new SampleServlet();
+
+ servlet.doForward(request, response, config);
+ }
+
+ /**
+ * Verify that we can use a <code>RequestDispatcher</code> in the class to
+ * test to forward to another page and compare the result sent to the
+ * output stream on the client side.
+ *
+ * @param theResponse the response from the server side.
+ *
+ * @exception IOException on test failure
+ */
+ public void endRequestDispatcherForward(WebResponse theResponse)
+ throws IOException
+ {
+ // We cannot test what is exactly returned by the called JSP between
+ // different Servlet engine return different text ! For example some
+ // return the JSP comment, other do not, ...
+ // Thus, we only test for a match of "Hello !"
+ assertTrue("Text missing 'Hello !' : [" + theResponse.getText() + "]",
+ theResponse.getText().indexOf("Hello !") > 0);
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that we can use a <code>RequestDispatcher</code> in the class to
+ * test to include another page and compare the result sent to the
+ * output stream on the client side.
+ *
+ * @exception Exception on test failure
+ */
+ public void testRequestDispatcherInclude() throws Exception
+ {
+ SampleServlet servlet = new SampleServlet();
+
+ servlet.doInclude(request, response, config);
+ }
+
+ /**
+ * Verify that we can use a <code>RequestDispatcher</code> in the class to
+ * test to include another page and compare the result sent to the
+ * output stream on the client side.
+ *
+ * @param theResponse the response from the server side.
+ *
+ * @exception IOException on test failure
+ */
+ public void endRequestDispatcherInclude(WebResponse theResponse)
+ throws IOException
+ {
+ // We cannot test what is exactly returned by the included JSP between
+ // different Servlet engine return different text ! For example some
+ // return the JSP comment, other do not, ...
+ // Thus, we only test for a match of "Hello !"
+ assertTrue("Text missing 'Hello !' : [" + theResponse.getText() + "]",
+ theResponse.getText().indexOf("Hello !") > 0);
+ }
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleServlet.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleServletConfig.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleServletConfig.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleServletConfig.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleServletConfig.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,56 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet;
+
+import javax.servlet.ServletException;
+
+import org.apache.cactus.ServletTestCase;
+
+/**
+ * Tests of the <code>SampleServletConfig</code> servlet class. This to show
+ * how servlet methods that makes calls to <code>getServletConfig()</code>,
+ * <code>getServletContext()</code>, <code>log()</code>, ... (i.e. methods that
+ * have been inherited from <code>GenericServlet</code>) can be unit-tested
+ * with Cactus.
+ *
+ * @version $Id: TestSampleServletConfig.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestSampleServletConfig extends ServletTestCase
+{
+ /**
+ * Verify that we can unit test a servlet that makes calls to
+ * <code>getServletConfig()</code>, <code>getServletContext()</code>,
+ * <code>log()</code>, ... (i.e. methods inherited from
+ * <code>GenericServlet</code>).
+ *
+ * @exception ServletException on test failure
+ */
+ public void testServletConfig() throws ServletException
+ {
+ SampleServletConfig servlet = new SampleServletConfig();
+
+ // VERY IMPORTANT : Call the init() method in order to initialize the
+ // Servlet ServletConfig object.
+ servlet.init(config);
+
+ assertEquals("value1 used for testing", servlet.getConfigData());
+ }
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleServletConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleTag.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleTag.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleTag.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleTag.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,197 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet;
+
+import javax.servlet.jsp.tagext.Tag;
+
+import org.apache.cactus.JspTestCase;
+import org.apache.cactus.WebResponse;
+
+/**
+ * Tests of the <code>SampleTag</code> class.
+ *
+ * @version $Id: TestSampleTag.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestSampleTag extends JspTestCase
+{
+ /**
+ * Our tag instance to unit test
+ */
+ private SampleTag tag;
+
+ /**
+ * @see TestCase#setUp()
+ */
+ public void setUp()
+ {
+ this.tag = new SampleTag();
+ this.tag.setPageContext(this.pageContext);
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Tests whether doStartTag() will skip the body if the corresponding tag
+ * attribute is set. Also tests whether an attribute put into page scope
+ * before the tag executes will be output to the response.
+ *
+ * @exception Exception if the test fails for an unexpected reason
+ */
+ public void testDoStartTag() throws Exception
+ {
+ //put something in page scope to see if it shows up in the response...
+ this.pageContext.setAttribute("test-key", "test-value");
+
+ this.tag.setShowBody("false");
+
+ int result = this.tag.doStartTag();
+
+ //body should not show up
+ assertEquals(Tag.SKIP_BODY, result);
+ }
+
+ /**
+ * Verifies that the output includes the output from doStartTag (a message
+ * from the tag and the attribute set into page scope).
+ *
+ * @param theResponse the response from the server side.
+ */
+ public void endDoStartTag(WebResponse theResponse)
+ {
+ // check that two of the lines output by the tag showed up in
+ // the response
+ assertContains(theResponse,
+ "The following attributes exist in page scope: <BR>");
+
+ assertContains(theResponse, "test-key = test-value <BR>");
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Test whether the tag's body will be shown if the corresponding attribute
+ * is set.
+ *
+ * @exception Exception if the test fails for an unexpected reason
+ */
+ public void testDoStartTagInclude() throws Exception
+ {
+ this.tag.setShowBody("true");
+
+ int result = this.tag.doStartTag();
+
+ //body should show up
+ assertEquals(Tag.EVAL_BODY_INCLUDE, result);
+ }
+
+ /**
+ * The tag prints a message before the body is included, here we check that
+ * the message shows up.
+ *
+ * @param theResponse the response from the server side.
+ */
+ public void endDoStartTagInclude(WebResponse theResponse)
+ {
+ // check that the pre-body message printed by the tag shows up
+ assertContains(theResponse, "Body Content Follows: <BR>");
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Checks if the tag will continue the page correctly if its stopPage
+ * property is set to false.
+ *
+ * @exception Exception if the test fails for an unexpected reason
+ */
+ public void testDoEndTagContinue() throws Exception
+ {
+ this.tag.setParent(new SampleTag());
+ this.tag.setStopPage("false");
+
+ int result = this.tag.doEndTag();
+
+ assertEquals(Tag.EVAL_PAGE, result);
+ }
+
+ /**
+ * Checks whether the tag has printed a message indicating that it has a
+ * parent tag.
+ *
+ * @param theResponse the response from the server side.
+ */
+ public void endDoEndTagContinue(WebResponse theResponse)
+ {
+ assertContains(theResponse, "This tag has a parent. <BR>");
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Checks if the tag will signal that page processing should stop if
+ * stopPage is set to "true"
+ *
+ * @exception Exception if the test fails for an unexpected reason
+ */
+ public void testDoEndTagStop() throws Exception
+ {
+ //no parent set
+ this.tag.setStopPage("true");
+
+ int result = this.tag.doEndTag();
+
+ assertEquals(Tag.SKIP_PAGE, result);
+ }
+
+ /**
+ * Checks whether the tag has printed a message indicating that it has a
+ * parent tag. (In this case it should not.)
+ *
+ * @param theResponse the response from the server side.
+ */
+ public void endDoEndTagStop(WebResponse theResponse)
+ {
+ String target = theResponse.getText();
+ boolean containsMessage =
+ target.indexOf("This tag has a parent. <BR>") > 0;
+ assertTrue(!containsMessage);
+ }
+
+ //--------------------------------------------------------------------------
+
+ /**
+ * Convenience function that asserts that a substring can be found in a
+ * the returned HTTP response body.
+ *
+ * @param theResponse the response from the server side.
+ * @param theSubstring the substring to look for
+ */
+ public void assertContains(WebResponse theResponse, String theSubstring)
+ {
+ String target = theResponse.getText();
+
+ if (target.indexOf(theSubstring) < 0)
+ {
+ fail("Response did not contain the substring: [" + theSubstring
+ + "]");
+ }
+ }
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/TestSampleTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestAll.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestAll.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestAll.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestAll.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,53 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet.unit;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Run all the Cactus unit tests related to J2EE API 1.3.
+ *
+ * @version $Id: TestAll.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestAll
+{
+ /**
+ * @return a test suite (<code>TestSuite</code>) that includes all methods
+ * starting with "test"
+ */
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite(
+ "Cactus unit tests for J2EE 1.3");
+
+ // Add shared tests
+ suite.addTest(TestShareAll.suite());
+
+ // Test cases specific to J2EE 1.3 only
+ suite.addTestSuite(TestHttpRequestSpecific.class);
+ suite.addTestSuite(TestJspTagLifecycle.class);
+ suite.addTestSuite(TestFilterHttpHeaders.class);
+ suite.addTestSuite(TestSetURLSpecific.class);
+
+ return suite;
+ }
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestAll.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestBasicAuthentication.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestBasicAuthentication.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestBasicAuthentication.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestBasicAuthentication.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,57 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet.unit;
+
+import org.apache.cactus.ServletTestCase;
+import org.apache.cactus.WebRequest;
+import org.apache.cactus.client.authentication.BasicAuthentication;
+
+/**
+ * Test running some test using BASIC authentication.
+ *
+ * @version $Id: TestBasicAuthentication.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestBasicAuthentication extends ServletTestCase
+{
+ /**
+ * Verify basic authentication.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginBasicAuthentication(WebRequest theRequest)
+ {
+ theRequest.setRedirectorName("ServletRedirectorSecure");
+ theRequest.setAuthentication(
+ new BasicAuthentication("testuser", "testpassword"));
+ }
+
+ /**
+ * Verify basic authentication. Note: This method is protected in the
+ * <code>web. xml</code> deployment descriptor.
+ */
+ public void testBasicAuthentication()
+ {
+ assertEquals("testuser", request.getUserPrincipal().getName());
+ assertEquals("testuser", request.getRemoteUser());
+ assertTrue("User not in 'test' role", request.isUserInRole("test"));
+ }
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestBasicAuthentication.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestClientServerSynchronization.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestClientServerSynchronization.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestClientServerSynchronization.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestClientServerSynchronization.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,80 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet.unit;
+
+import javax.servlet.ServletOutputStream;
+
+import org.apache.cactus.ServletTestCase;
+
+/**
+ * Verify that the Cactus client side only reads the test result *after* the
+ * test is finished (ie after the test result has been saved in the application
+ * scope). This JUnit test need to be the first one to be run. Otherwise, the
+ * test result might be that of the previous test and not the current test one,
+ * thus proving nothing !!
+ *
+ * @version $Id: TestClientServerSynchronization.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestClientServerSynchronization extends ServletTestCase
+{
+ /**
+ * Verify that the test result can be returned correctly even when the
+ * logic in the method to test takes a long time and thus it verifies that
+ * the test result is only returned after it has been written in the
+ * application scope on the server side.
+ *
+ * @exception Exception on test failure
+ */
+ public void testLongProcess() throws Exception
+ {
+ ServletOutputStream os = response.getOutputStream();
+
+ os.print("<html><head><Long Process></head><body>");
+ os.flush();
+
+ // do some processing that takes a while ...
+ Thread.sleep(3000);
+ os.println("Some data</body></html>");
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that when big amount of data is returned by the servlet output
+ * stream, it does not io-block.
+ *
+ * @exception Exception on test failure
+ */
+ public void testLotsOfData() throws Exception
+ {
+ ServletOutputStream os = response.getOutputStream();
+
+ os.println("<html><head>Lots of Data</head><body>");
+ os.flush();
+
+ for (int i = 0; i < 5000; i++)
+ {
+ os.println("<p>Lots and lots of data here");
+ }
+
+ os.println("</body></html>");
+ }
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestClientServerSynchronization.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestCookie.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestCookie.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestCookie.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestCookie.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,67 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet.unit;
+
+import org.apache.cactus.ServletTestCase;
+import org.apache.cactus.WebRequest;
+
+/**
+ * Tests related to Cookies.
+ *
+ * @version $Id: TestCookie.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestCookie extends ServletTestCase
+{
+ /**
+ * Verify that special characters in cookies are not URL encoded
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginCookieEncoding(WebRequest theRequest)
+ {
+ // Note: the pipe ('&') character is a special character regarding
+ // URL encoding
+ theRequest.addCookie("testcookie", "user&pwd");
+ }
+
+ /**
+ * Verify that special characters in cookies are not encoded
+ */
+ public void testCookieEncoding()
+ {
+ javax.servlet.http.Cookie[] cookies = request.getCookies();
+
+ assertNotNull("No cookies in request", cookies);
+
+ for (int i = 0; i < cookies.length; i++)
+ {
+ if (cookies[i].getName().equals("testcookie"))
+ {
+ assertEquals("user&pwd", cookies[i].getValue());
+ return;
+ }
+ }
+
+ fail("No cookie named 'testcookie' found");
+ }
+
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestCookie.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestFilterHttpHeaders.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestFilterHttpHeaders.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestFilterHttpHeaders.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestFilterHttpHeaders.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,60 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet.unit;
+
+import org.apache.cactus.FilterTestCase;
+
+import com.meterware.httpunit.WebResponse;
+
+/**
+ * Tests HTTP headers set in Filter code.
+ *
+ * @version $Id: TestFilterHttpHeaders.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestFilterHttpHeaders extends FilterTestCase
+{
+ /**
+ * Verify headers can be set in a Filter test case and retrieved using
+ * HttpUnit.
+ */
+ public void testHeaders()
+ {
+ response.setHeader("xparevcount", "xparevcount");
+ response.setHeader("xxparevcount", "xxparevcount");
+ }
+
+ /**
+ * Verify headers can be set in a Filter test case and retrieved using
+ * HttpUnit.
+ *
+ * @param theResponse the HTTP response
+ */
+ public void endHeaders(WebResponse theResponse)
+ {
+ String header1 = theResponse.getHeaderField("xxparevcount");
+ String header2 = theResponse.getHeaderField("xparevcount");
+ assertNotNull("Header 1 should not be null", header1);
+ assertNotNull("Header 2 should not be null", header2);
+ assertEquals("xxparevcount", header1);
+ assertEquals("xparevcount", header2);
+ }
+
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestFilterHttpHeaders.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestGlobalBeginEnd.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestGlobalBeginEnd.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestGlobalBeginEnd.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestGlobalBeginEnd.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,127 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet.unit;
+
+import org.apache.cactus.ServletTestCase;
+import org.apache.cactus.WebRequest;
+import org.apache.cactus.WebResponse;
+
+/**
+ * Test global client side <code>begin()</code> and <code>end()</code>
+ * methods.
+ *
+ * @version $Id: TestGlobalBeginEnd.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestGlobalBeginEnd extends ServletTestCase
+{
+ /**
+ * true if <code>end()</code> has been called.
+ */
+ private boolean isClientGlobalEndCalled;
+
+ /**
+ * Verifies that <code>end()</code> has been called correctly.
+ *
+ * @exception Throwable on test failure
+ */
+ protected void runTest() throws Throwable
+ {
+ super.runTest();
+
+ // Make sure we verify if end() has been called only on
+ // the client side. Reason is that the runTest() method is
+ // called both on the client side and on the server side.
+ if (this.request == null)
+ {
+ if (!this.isClientGlobalEndCalled)
+ {
+ fail("end() has not been called");
+ }
+ }
+ }
+
+ /**
+ * Verify that it is possible to modify the <code>WebRequest</code> in
+ * the common <code>begin()</code> method. It also verifies that
+ * <code>begin()</code> is called at all.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void begin(WebRequest theRequest)
+ {
+ theRequest.addParameter("param1", "value1");
+ }
+
+ /**
+ * Verify that it is possible to read the connection object once in
+ * endXXX() and then again in <code>end()</code>. It also
+ * verifies that <code>end()</code> is called at all.
+ *
+ * @param theResponse the response from the server side.
+ */
+ public void end(WebResponse theResponse)
+ {
+ assertEquals("Hello there!", theResponse.getText());
+ this.isClientGlobalEndCalled = true;
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that it is possible to modify the <code>WebRequest</code> in
+ * the common <code>begin()()</code> method. It also verifies that
+ * <code>begin()</code> is called at all.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginGlobalBeginEnd(WebRequest theRequest)
+ {
+ assertEquals("value1", theRequest.getParameterGet("param1"));
+ }
+
+ /**
+ * Verify that it is possible to modify the <code>WebRequest</code> in
+ * the common <code>begin()()</code> method. It also verifies that
+ * <code>begin()()</code> is called at all.
+ *
+ * @exception Exception on test failure
+ */
+ public void testGlobalBeginEnd() throws Exception
+ {
+ assertEquals("value1", request.getParameter("param1"));
+ response.getWriter().print("Hello there!");
+ }
+
+ /**
+ * Verify that it is possible to read the connection object once in
+ * endXXX() and then again in <code>end()</code>. It also
+ * verifies that <code>end()</code> is called at all.
+ *
+ * @param theResponse the response from the server side.
+ */
+ public void endGlobalBeginEnd(WebResponse theResponse)
+ {
+ assertEquals("Hello there!", theResponse.getText());
+ }
+
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestGlobalBeginEnd.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHtmlUnitIntegration.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHtmlUnitIntegration.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHtmlUnitIntegration.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHtmlUnitIntegration.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,121 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet.unit;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import org.apache.cactus.ServletTestCase;
+import org.apache.cactus.sample.servlet.SampleServlet;
+
+/**
+ * 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(0, value1);
+// assertEquals(0, value2);
+// }
+
+
+
+ /**
+ * Verify that we can initialize the <code>SampleServlet</code> and
+ * assert it in endXXX().
+ *
+ * @param theResponse the response from the server side.
+ */
+ public void testSampleServletResponse() throws Exception {
+ SampleServlet servlet = new SampleServlet();
+ servlet.doGet(request, response);
+ }
+
+ /**
+ * Verify that we can assert the servlet output stream.
+ *
+ * @param theResponse the response from the server side.
+ *
+ * @exception IOException on test failure
+ */
+ public void endSampleServletResponse(com.gargoylesoftware.htmlunit.WebResponse
+ theResponse) throws Exception {
+ assertEquals("<html><head/><body>A GET request</body></html>", theResponse.getContentAsString());
+ }
+
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHtmlUnitIntegration.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpHeaders.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpHeaders.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpHeaders.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpHeaders.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,148 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet.unit;
+
+import org.apache.cactus.ServletTestCase;
+import org.apache.cactus.WebRequest;
+import org.apache.cactus.WebResponse;
+
+/**
+ * Tests manipulating HTTP headers.
+ *
+ * @version $Id: TestHttpHeaders.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestHttpHeaders extends ServletTestCase
+{
+ /**
+ * Verify that we can simulate several HTTP header values with the same
+ * header name.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginSendMultivaluedHeader(WebRequest theRequest)
+ {
+ theRequest.addHeader("testheader", "value1");
+ theRequest.addHeader("testheader", "value2");
+ }
+
+ /**
+ * Verify that we can simulate several HTTP header values with the same
+ * header name.
+ */
+ public void testSendMultivaluedHeader()
+ {
+ // Note: I am not sure how to retrieve multi valued headers. The
+ // problem is that I use
+ // URLConnection.setRequestProperty("testheader", "value1,value2") in
+ // JdkConnectionHelper to send the headers but request.getHeaders() does
+ // not seem to separate the different header values.
+ // The RFC 2616 says :
+ // message-header = field-name ":" [ field-value ]
+ // field-name = token
+ // field-value = *( field-content | LWS )
+ // field-content = <the OCTETs making up the field-value
+ // and consisting of either *TEXT or combinations
+ // of token, separators, and quoted-string>
+ // [...]
+ // Multiple message-header fields with the same field-name MAY be
+ // present in a message if and only if the entire field-value for that
+ // header field is defined as a comma-separated list [i.e., #(values)].
+ // It MUST be possible to combine the multiple header fields into one
+ // "field-name: field-value" pair, without changing the semantics of
+ // the message, by appending each subsequent field-value to the first,
+ // each separated by a comma. The order in which header fields with the
+ // same field-name are received is therefore significant to the
+ // interpretation of the combined field value, and thus a proxy MUST
+ // NOT change the order of these field values when a message is
+ // forwarded.
+ // ... so it should be ok ...
+ assertEquals("value1,value2", request.getHeader("testheader"));
+
+ // Here is commented out what I would have thought I should have
+ // written to verify this test but it does not seem to work this way ...
+
+ /*
+ Enumeration values = request.getHeaders("testheader");
+ int count = 0;
+ while (values.hasMoreElements()) {
+ String value = (String)values.nextElement();
+ if (!(value.equals("value1") || value.equals("value2"))) {
+ fail("unknown value [" + value + "] for header [testheader]");
+ }
+ count++;
+ }
+ assertEquals("Should have received 2 values for header [testheader]",
+ 2, count);
+ */
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify we can set the content type by setting an HTTP header.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginSetContentTypeHeader(WebRequest theRequest)
+ {
+ theRequest.addHeader("Content-type", "text/xml");
+ }
+
+ /**
+ * Verify we can set the content type by setting an HTTP header.
+ */
+ public void testSetContentTypeHeader()
+ {
+ assertEquals("text/xml", request.getContentType());
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that we can set several headers in the response and
+ * assert them in endXXX().
+ */
+ public void testResponseAddHeaders()
+ {
+ response.addHeader("X-Test-Header1", "value1");
+ response.addHeader("X-Test-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 endResponseAddHeaders(WebResponse theResponse)
+ {
+ String value1 =
+ theResponse.getConnection().getHeaderField("X-Test-Header1");
+ String value2 =
+ theResponse.getConnection().getHeaderField("X-Test-Header2");
+
+ assertEquals("value1", value1);
+ assertEquals("value2", value2);
+ }
+
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpHeaders.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpParameters.java
URL: http://svn.apache.org/viewvc/jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpParameters.java?rev=698559&view=auto
==============================================================================
--- jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpParameters.java (added)
+++ jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpParameters.java Wed Sep 24 06:20:11 2008
@@ -0,0 +1,102 @@
+/*
+ * ========================================================================
+ *
+ * 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.
+ *
+ * ========================================================================
+ */
+package org.apache.cactus.sample.servlet.unit;
+
+import org.apache.cactus.ServletTestCase;
+import org.apache.cactus.WebRequest;
+
+/**
+ * Test passing HTTP parameters to the server side.
+ *
+ * @version $Id: TestHttpParameters.java 238816 2004-02-29 16:36:46Z vmassol $
+ */
+public class TestHttpParameters extends ServletTestCase
+{
+ /**
+ * Verify that multi value parameters can be sent in the
+ * <code>beingXXX()</code> method to the server redirector.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginMultiValueParameters(WebRequest theRequest)
+ {
+ theRequest.addParameter("multivalue", "value 1");
+ theRequest.addParameter("multivalue", "value 2");
+ }
+
+ /**
+ * Verify that multi value parameters can be sent in the
+ * <code>beingXXX()</code> method to the server redirector.
+ */
+ public void testMultiValueParameters()
+ {
+ String[] values = request.getParameterValues("multivalue");
+
+ if (values[0].equals("value 1"))
+ {
+ assertEquals("value 2", values[1]);
+ }
+ else if (values[0].equals("value 2"))
+ {
+ assertEquals("value 1", values[1]);
+ }
+ else
+ {
+ fail("Shoud have returned a vector with the "
+ + "values \"value 1\" and \"value 2\"");
+ }
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify we can set and retrieve several parameters.
+ *
+ * @param theRequest the request object that serves to initialize the
+ * HTTP connection to the server redirector.
+ */
+ public void beginSeveralParameters(WebRequest theRequest)
+ {
+ theRequest.addParameter("PostParameter1", "EMPLOYEE0145",
+ WebRequest.POST_METHOD);
+ theRequest.addParameter("PostParameter2", "W", WebRequest.GET_METHOD);
+ theRequest.addParameter("PostParameter3", "07/08/2002",
+ WebRequest.POST_METHOD);
+ theRequest.addParameter("PostParameter4", "/tas/ViewSchedule.esp",
+ WebRequest.GET_METHOD);
+ }
+
+ /**
+ * Verify we can set and retrieve several parameters.
+ */
+ public void testSeveralParameters()
+ {
+ assertEquals("parameter4", "/tas/ViewSchedule.esp",
+ request.getParameter("PostParameter4"));
+ assertEquals("parameter1", "EMPLOYEE0145",
+ request.getParameter("PostParameter1"));
+ assertEquals("parameter2", "W", request.getParameter("PostParameter2"));
+ assertEquals("parameter3", "07/08/2002",
+ request.getParameter("PostParameter3"));
+ }
+
+}
Propchange: jakarta/cactus/trunk/samples/servlet/src/test/java/org/apache/cactus/sample/servlet/unit/TestHttpParameters.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org