[Httpunit-commit] CVS: httpunit/test/com/meterware/httpunit PseudoServerTest.java,1.24,1.25 WebClien
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-06-26 15:12:04
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit
In directory usw-pr-cvs1:/tmp/cvs-serv4546/test/com/meterware/httpunit
Modified Files:
PseudoServerTest.java WebClientTest.java
Log Message:
Moved cookie test to more logical suite
Index: PseudoServerTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- PseudoServerTest.java 6 Mar 2002 04:59:52 -0000 1.24
+++ PseudoServerTest.java 26 Jun 2002 15:12:01 -0000 1.25
@@ -1,42 +1,38 @@
package com.meterware.httpunit;
/********************************************************************************************************************
-* $Id$
-*
-* Copyright (c) 2000-2002, Russell Gold
-*
-* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
-* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
-* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
-* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice shall be included in all copies or substantial portions
-* of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
-* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
-* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-* DEALINGS IN THE SOFTWARE.
-*
-*******************************************************************************************************************/
-import java.net.HttpURLConnection;
-
-import java.util.Dictionary;
-
-import junit.framework.Test;
+ * $Id$
+ *
+ * Copyright (c) 2000-2002, Russell Gold
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
+ * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
+ * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
+ * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ *******************************************************************************************************************/
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import com.meterware.httpunit.*;
+import java.net.HttpURLConnection;
+
public class PseudoServerTest extends HttpUnitTest {
- public static void main(String args[]) {
+ public static void main( String args[] ) {
junit.textui.TestRunner.run( suite() );
}
- public static Test suite() {
+ public static TestSuite suite() {
return new TestSuite( PseudoServerTest.class );
}
@@ -57,80 +53,52 @@
public void testNotFound() throws Exception {
- PseudoServer ps = new PseudoServer();
- int port = ps.getConnectedPort();
-
- WebConversation wc = new WebConversation();
- WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + "/nothing.htm" );
+ WebConversation wc = new WebConversation();
+ WebRequest request = new GetMethodWebRequest( getHostPath() + "/nothing.htm" );
try {
WebResponse response = wc.getResponse( request );
fail( "Should have rejected the request" );
} catch (HttpNotFoundException e) {
assertEquals( "Response code", HttpURLConnection.HTTP_NOT_FOUND, e.getResponseCode() );
- } finally {
- ps.shutDown();
}
}
public void testNotModifiedResponse() throws Exception {
- PseudoServer ps = new PseudoServer();
- ps.setErrorResource( "error.htm", 304, "Not Modified" );
- int port = ps.getConnectedPort();
+ defineResource( "error.htm", "Not Modified", 304 );
- try {
- WebConversation wc = new WebConversation();
- WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + "/error.htm" );
- WebResponse response = wc.getResponse( request );
- assertEquals( "Response code", 304, response.getResponseCode() );
- response.getText();
- response.getInputStream().read();
- } finally {
- ps.shutDown();
- }
+ WebConversation wc = new WebConversation();
+ WebRequest request = new GetMethodWebRequest( getHostPath() + "/error.htm" );
+ WebResponse response = wc.getResponse( request );
+ assertEquals( "Response code", 304, response.getResponseCode() );
+ response.getText();
+ response.getInputStream().read();
}
public void testInternalErrorException() throws Exception {
- PseudoServer ps = new PseudoServer();
- ps.setErrorResource( "error.htt", 501, "Internal error" );
- int port = ps.getConnectedPort();
+ defineResource( "error.htm", "Internal error", 501 );
- WebConversation wc = new WebConversation();
- WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + "/error.htt" );
+ WebConversation wc = new WebConversation();
+ WebRequest request = new GetMethodWebRequest( getHostPath() + "/error.htm" );
try {
WebResponse response = wc.getResponse( request );
fail( "Should have rejected the request" );
} catch (HttpException e) {
assertEquals( "Response code", 501, e.getResponseCode() );
- } finally {
- ps.shutDown();
}
}
public void testInternalErrorDisplay() throws Exception {
- PseudoServer ps = new PseudoServer();
- ps.setErrorResource( "error.htm", 501, "Internal error" );
- int port = ps.getConnectedPort();
-
- try {
- WebConversation wc = new WebConversation();
- wc.setExceptionsThrownOnErrorStatus( false );
- WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + "/error.htm" );
- WebResponse response = wc.getResponse( request );
- assertEquals( "Response code", 501, response.getResponseCode() );
- assertEquals( "Message contents", "Internal error", response.getText().trim() );
- } finally {
- ps.shutDown();
- }
- }
-
+ defineResource( "error.htm", "Internal error", 501 );
- public void testHeaderFields() throws Exception {
WebConversation wc = new WebConversation();
- wc.setHeaderField( "user-agent", "Mozilla 6" );
- assertEquals( "Mozilla 6", wc.getUserAgent() );
+ wc.setExceptionsThrownOnErrorStatus( false );
+ WebRequest request = new GetMethodWebRequest( getHostPath() + "/error.htm" );
+ WebResponse response = wc.getResponse( request );
+ assertEquals( "Response code", 501, response.getResponseCode() );
+ assertEquals( "Message contents", "Internal error", response.getText().trim() );
}
@@ -138,19 +106,13 @@
String resourceName = "something/interesting";
String resourceValue = "the desired content";
- PseudoServer ps = new PseudoServer();
- ps.setResource( resourceName, resourceValue );
- int port = ps.getConnectedPort();
+ defineResource( resourceName, resourceValue );
- try {
- WebConversation wc = new WebConversation();
- WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + resourceName );
- WebResponse response = wc.getResponse( request );
- assertEquals( "requested resource", resourceValue, response.getText().trim() );
- assertEquals( "content type", "text/html", response.getContentType() );
- } finally {
- ps.shutDown();
- }
+ WebConversation wc = new WebConversation();
+ WebRequest request = new GetMethodWebRequest( getHostPath() + '/' + resourceName );
+ WebResponse response = wc.getResponse( request );
+ assertEquals( "requested resource", resourceValue, response.getText().trim() );
+ assertEquals( "content type", "text/html", response.getContentType() );
}
@@ -158,138 +120,33 @@
StringBuffer sb = new StringBuffer();
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++) {
- sb.append( Integer.toHexString( chars[i] ) ).append( " " );
+ sb.append( Integer.toHexString( chars[i] ) ).append( " " );
}
return sb.toString();
}
- public void testCookies() throws Exception {
- String resourceName = "something/baking";
- String resourceValue = "the desired content";
-
- PseudoServer ps = new PseudoServer();
- int port = ps.getConnectedPort();
- ps.setResource( resourceName, resourceValue );
- ps.addResourceHeader( resourceName, "Set-Cookie: HSBCLoginFailReason=; path=/" );
- ps.addResourceHeader( resourceName, "Set-Cookie: age=12, name= george" );
- ps.addResourceHeader( resourceName, "Set-Cookie: type=short" );
- ps.addResourceHeader( resourceName, "Set-Cookie: funky=ab$==" );
- ps.addResourceHeader( resourceName, "Set-Cookie: p30waco_sso=3.0,en,us,AMERICA,Drew;path=/, PORTAL30_SSO_TEST=X" );
- ps.addResourceHeader( resourceName, "Set-Cookie: SESSION_ID=17585,Dzm5LzbRPnb95QkUyIX+7w5RDT7p6OLuOVZ91AMl4hsDATyZ1ej+FA==; path=/;" );
-
- try {
- WebConversation wc = new WebConversation();
- WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + resourceName );
- WebResponse response = wc.getResponse( request );
- assertEquals( "requested resource", resourceValue, response.getText().trim() );
- assertEquals( "content type", "text/html", response.getContentType() );
- assertEquals( "number of cookies", 8, wc.getCookieNames().length );
- assertEquals( "cookie 'HSBCLoginFailReason' value", "", wc.getCookieValue( "HSBCLoginFailReason" ) );
- assertEquals( "cookie 'age' value", "12", wc.getCookieValue( "age" ) );
- assertEquals( "cookie 'name' value", "george", wc.getCookieValue( "name" ) );
- assertEquals( "cookie 'type' value", "short", wc.getCookieValue( "type" ) );
- assertEquals( "cookie 'funky' value", "ab$==", wc.getCookieValue( "funky" ) );
- assertEquals( "cookie 'p30waco_sso' value", "3.0,en,us,AMERICA,Drew", wc.getCookieValue( "p30waco_sso" ) );
- assertEquals( "cookie 'PORTAL30_SSO_TEST' value", "X", wc.getCookieValue( "PORTAL30_SSO_TEST" ) );
- assertEquals( "cookie 'SESSION_ID' value", "17585,Dzm5LzbRPnb95QkUyIX+7w5RDT7p6OLuOVZ91AMl4hsDATyZ1ej+FA==", wc.getCookieValue( "SESSION_ID" ) );
- } finally {
- ps.shutDown();
- }
- }
-
-
- public void testOldCookies() throws Exception {
- String resourceName = "something/baking";
- String resourceValue = "the desired content";
-
- PseudoServer ps = new PseudoServer();
- int port = ps.getConnectedPort();
- ps.setResource( resourceName, resourceValue );
- ps.addResourceHeader( resourceName, "Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT" );
-
- try {
- WebConversation wc = new WebConversation();
- WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + resourceName );
- WebResponse response = wc.getResponse( request );
- assertEquals( "requested resource", resourceValue, response.getText().trim() );
- assertEquals( "content type", "text/html", response.getContentType() );
- assertEquals( "number of cookies", 1, wc.getCookieNames().length );
- assertEquals( "cookie 'CUSTOMER' value", "WILE_E_COYOTE", wc.getCookieValue( "CUSTOMER" ) );
- } finally {
- ps.shutDown();
- }
- }
-
-
-
public void testPseudoServlet() throws Exception {
String resourceName = "tellMe";
String name = "Charlie";
final String prefix = "Hello there, ";
String expectedResponse = prefix + name;
- PseudoServer ps = new PseudoServer();
- int port = ps.getConnectedPort();
+ defineResource( resourceName, new PseudoServlet() {
- try {
- ps.setResource( resourceName, new PseudoServlet() {
- public WebResource getPostResponse() {
- return new WebResource( prefix + getParameter( "name" )[0], "text/plain" );
- }
- } );
-
- WebConversation wc = new WebConversation();
- WebRequest request = new PostMethodWebRequest( "http://localhost:" + port + '/' + resourceName );
- request.setParameter( "name", name );
- WebResponse response = wc.getResponse( request );
- assertEquals( "Content type", "text/plain", response.getContentType() );
- assertEquals( "Response", expectedResponse, response.getText().trim() );
- } finally {
- ps.shutDown();
- }
- }
-
-
- public void testRefererHeader() throws Exception {
- String resourceName = "tellMe";
- String linkSource = "fromLink";
- String formSource = "fromForm";
-
- PseudoServer ps = new PseudoServer();
- int port = ps.getConnectedPort();
+ public WebResource getPostResponse() {
+ return new WebResource( prefix + getParameter( "name" )[0], "text/plain" );
+ }
+ } );
- String page0 = "http://localhost:" + port + '/' + resourceName;
- String page1 = "http://localhost:" + port + '/' + linkSource;
- String page2 = "http://localhost:" + port + '/' + formSource;
-
- ps.setResource( linkSource, "<html><head></head><body><a href=\"tellMe\">Go</a></body></html>" );
- ps.setResource( formSource, "<html><body><form action=\"tellMe\"><input type=submit></form></body></html>" );
-
- try {
- ps.setResource( resourceName, new PseudoServlet() {
- public WebResource getGetResponse() {
- String referer = getHeader( "Referer" );
- return new WebResource( referer == null ? "null" : referer, "text/plain" );
- }
- } );
-
- WebConversation wc = new WebConversation();
- WebResponse response = wc.getResponse( page0 );
- assertEquals( "Content type", "text/plain", response.getContentType() );
- assertEquals( "Default Referer header", "null", response.getText().trim() );
-
- response = wc.getResponse( page1 );
- response = wc.getResponse( response.getLinks()[0].getRequest() );
- assertEquals( "Link Referer header", page1, response.getText().trim() );
-
- response = wc.getResponse( page2 );
- response = wc.getResponse( response.getForms()[0].getRequest() );
- assertEquals( "Form Referer header", page2, response.getText().trim() );
- } finally {
- ps.shutDown();
- }
+ WebConversation wc = new WebConversation();
+ WebRequest request = new PostMethodWebRequest( getHostPath() + '/' + resourceName );
+ request.setParameter( "name", name );
+ WebResponse response = wc.getResponse( request );
+ assertEquals( "Content type", "text/plain", response.getContentType() );
+ assertEquals( "Response", expectedResponse, response.getText().trim() );
}
+
}
Index: WebClientTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebClientTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WebClientTest.java 11 Mar 2002 12:34:32 -0000 1.3
+++ WebClientTest.java 26 Jun 2002 15:12:01 -0000 1.4
@@ -19,7 +19,6 @@
* DEALINGS IN THE SOFTWARE.
*
*******************************************************************************************************************/
-
import junit.framework.TestSuite;
import java.io.ByteArrayOutputStream;
@@ -50,6 +49,92 @@
public WebClientTest( String name ) {
super( name );
+ }
+
+
+ public void testHeaderFields() throws Exception {
+ WebConversation wc = new WebConversation();
+ wc.setHeaderField( "user-agent", "Mozilla 6" );
+ assertEquals( "Mozilla 6", wc.getUserAgent() );
+ }
+
+
+ public void testCookies() throws Exception {
+ String resourceName = "something/baking";
+ String resourceValue = "the desired content";
+
+ defineResource( resourceName, resourceValue );
+ addResourceHeader( resourceName, "Set-Cookie: HSBCLoginFailReason=; path=/" );
+ addResourceHeader( resourceName, "Set-Cookie: age=12, name= george" );
+ addResourceHeader( resourceName, "Set-Cookie: type=short" );
+ addResourceHeader( resourceName, "Set-Cookie: funky=ab$==" );
+ addResourceHeader( resourceName, "Set-Cookie: p30waco_sso=3.0,en,us,AMERICA,Drew;path=/, PORTAL30_SSO_TEST=X" );
+ addResourceHeader( resourceName, "Set-Cookie: SESSION_ID=17585,Dzm5LzbRPnb95QkUyIX+7w5RDT7p6OLuOVZ91AMl4hsDATyZ1ej+FA==; path=/;" );
+
+ WebConversation wc = new WebConversation();
+ WebRequest request = new GetMethodWebRequest( getHostPath() + '/' + resourceName );
+ WebResponse response = wc.getResponse( request );
+ assertEquals( "requested resource", resourceValue, response.getText().trim() );
+ assertEquals( "content type", "text/html", response.getContentType() );
+ assertEquals( "number of cookies", 8, wc.getCookieNames().length );
+ assertEquals( "cookie 'HSBCLoginFailReason' value", "", wc.getCookieValue( "HSBCLoginFailReason" ) );
+ assertEquals( "cookie 'age' value", "12", wc.getCookieValue( "age" ) );
+ assertEquals( "cookie 'name' value", "george", wc.getCookieValue( "name" ) );
+ assertEquals( "cookie 'type' value", "short", wc.getCookieValue( "type" ) );
+ assertEquals( "cookie 'funky' value", "ab$==", wc.getCookieValue( "funky" ) );
+ assertEquals( "cookie 'p30waco_sso' value", "3.0,en,us,AMERICA,Drew", wc.getCookieValue( "p30waco_sso" ) );
+ assertEquals( "cookie 'PORTAL30_SSO_TEST' value", "X", wc.getCookieValue( "PORTAL30_SSO_TEST" ) );
+ assertEquals( "cookie 'SESSION_ID' value", "17585,Dzm5LzbRPnb95QkUyIX+7w5RDT7p6OLuOVZ91AMl4hsDATyZ1ej+FA==", wc.getCookieValue( "SESSION_ID" ) );
+ }
+
+
+ public void testOldCookies() throws Exception {
+ String resourceName = "something/baking";
+ String resourceValue = "the desired content";
+
+ defineResource( resourceName, resourceValue );
+ addResourceHeader( resourceName, "Set-Cookie: CUSTOMER=WILE_E_COYOTE; path=/; expires=Wednesday, 09-Nov-99 23:12:40 GMT" );
+
+ WebConversation wc = new WebConversation();
+ WebRequest request = new GetMethodWebRequest( getHostPath() + '/' + resourceName );
+ WebResponse response = wc.getResponse( request );
+ assertEquals( "requested resource", resourceValue, response.getText().trim() );
+ assertEquals( "content type", "text/html", response.getContentType() );
+ assertEquals( "number of cookies", 1, wc.getCookieNames().length );
+ assertEquals( "cookie 'CUSTOMER' value", "WILE_E_COYOTE", wc.getCookieValue( "CUSTOMER" ) );
+ }
+
+
+ public void testRefererHeader() throws Exception {
+ String resourceName = "tellMe";
+ String linkSource = "fromLink";
+ String formSource = "fromForm";
+
+ String page0 = getHostPath() + '/' + resourceName;
+ String page1 = getHostPath() + '/' + linkSource;
+ String page2 = getHostPath() + '/' + formSource;
+
+ defineResource( linkSource, "<html><head></head><body><a href=\"tellMe\">Go</a></body></html>" );
+ defineResource( formSource, "<html><body><form action=\"tellMe\"><input type=submit></form></body></html>" );
+ defineResource( resourceName, new PseudoServlet() {
+ public WebResource getGetResponse() {
+ String referer = getHeader( "Referer" );
+ return new WebResource( referer == null ? "null" : referer, "text/plain" );
+ }
+ } );
+
+ WebConversation wc = new WebConversation();
+ WebResponse response = wc.getResponse( page0 );
+ assertEquals( "Content type", "text/plain", response.getContentType() );
+ assertEquals( "Default Referer header", "null", response.getText().trim() );
+
+ response = wc.getResponse( page1 );
+ response = wc.getResponse( response.getLinks()[0].getRequest() );
+ assertEquals( "Link Referer header", page1, response.getText().trim() );
+
+ response = wc.getResponse( page2 );
+ response = wc.getResponse( response.getForms()[0].getRequest() );
+ assertEquals( "Form Referer header", page2, response.getText().trim() );
}
|