[Httpunit-commit] SF.net SVN: httpunit:[1062] trunk/httpunit
Brought to you by:
russgold
From: <wol...@us...> - 2009-12-22 15:34:37
|
Revision: 1062 http://httpunit.svn.sourceforge.net/httpunit/?rev=1062&view=rev Author: wolfgang_fahl Date: 2009-12-22 15:34:27 +0000 (Tue, 22 Dec 2009) Log Message: ----------- Patch for issue when server returns empty content type value + workaround for regression problem - do not try to redefine resources Modified Paths: -------------- trunk/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java trunk/httpunit/src/com/meterware/pseudoserver/PseudoServer.java trunk/httpunit/test/com/meterware/httpunit/EncodingTest.java trunk/httpunit/test/com/meterware/httpunit/MessageBodyRequestTest.java trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java trunk/httpunit/test/com/meterware/httpunit/javascript/NekoEnhancedScriptingTest.java Modified: trunk/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java =================================================================== --- trunk/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java 2009-09-10 05:23:52 UTC (rev 1061) +++ trunk/httpunit/src/com/meterware/httpunit/HttpUnitUtils.java 2009-12-22 15:34:27 UTC (rev 1062) @@ -75,16 +75,18 @@ **/ public static String[] parseContentTypeHeader( String header ) { String[] result = new String[] { "text/plain", null }; - StringTokenizer st = new StringTokenizer( header, ";=" ); - result[0] = st.nextToken(); - while (st.hasMoreTokens()) { - String parameter = st.nextToken(); - if (st.hasMoreTokens()) { - String value = stripQuotes( st.nextToken() ); - if (parameter.trim().equalsIgnoreCase( "charset" )) { - result[1] = value; - } - } + if (header.trim().length()>0){ + StringTokenizer st = new StringTokenizer( header, ";=" ); + result[0] = st.nextToken(); + while (st.hasMoreTokens()) { + String parameter = st.nextToken(); + if (st.hasMoreTokens()) { + String value = stripQuotes( st.nextToken() ); + if (parameter.trim().equalsIgnoreCase( "charset" )) { + result[1] = value; + } + } + } } return result; } Modified: trunk/httpunit/src/com/meterware/pseudoserver/PseudoServer.java =================================================================== --- trunk/httpunit/src/com/meterware/pseudoserver/PseudoServer.java 2009-09-10 05:23:52 UTC (rev 1061) +++ trunk/httpunit/src/com/meterware/pseudoserver/PseudoServer.java 2009-12-22 15:34:27 UTC (rev 1062) @@ -266,7 +266,7 @@ private boolean _active = true; - private boolean _debug; + private boolean _debug=true; private String asResourceName( String rawName ) { Modified: trunk/httpunit/test/com/meterware/httpunit/EncodingTest.java =================================================================== --- trunk/httpunit/test/com/meterware/httpunit/EncodingTest.java 2009-09-10 05:23:52 UTC (rev 1061) +++ trunk/httpunit/test/com/meterware/httpunit/EncodingTest.java 2009-12-22 15:34:27 UTC (rev 1062) @@ -62,6 +62,7 @@ */ public void testParseContentHeader() throws Exception { String headers[]={ + "", "text/plain", "text/html; charset=Cp1252", "text/html; charset=iso-8859-8", @@ -69,6 +70,7 @@ }; String expected[][]={ {"text/plain",null}, + {"text/plain",null}, {"text/html","Cp1252"}, {"text/html","iso-8859-8"}, {"text/html","EUC-JP"} Modified: trunk/httpunit/test/com/meterware/httpunit/MessageBodyRequestTest.java =================================================================== --- trunk/httpunit/test/com/meterware/httpunit/MessageBodyRequestTest.java 2009-09-10 05:23:52 UTC (rev 1061) +++ trunk/httpunit/test/com/meterware/httpunit/MessageBodyRequestTest.java 2009-12-22 15:34:27 UTC (rev 1062) @@ -27,6 +27,7 @@ import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.IOException; +import java.io.UnsupportedEncodingException; import junit.framework.Test; import junit.framework.TestSuite; @@ -51,21 +52,49 @@ public void setUp() throws Exception { super.setUp(); } - - public void testGenericPostRequest() throws Exception { - defineResource("ReportData", new BodyEcho()); - String sourceData = "This is an interesting test\nWith two lines"; + + /** + * make a Request from the given parameters + * @param resourceName + * @param sourceData + * @param contentType + * @return the new WebRequest + * @throws UnsupportedEncodingException + */ + public WebRequest makeRequest(String resourceName,String sourceData, String contentType) throws UnsupportedEncodingException{ + defineResource(resourceName, new BodyEcho()); InputStream source = new ByteArrayInputStream(sourceData .getBytes("iso-8859-1")); + WebRequest wr = new PostMethodWebRequest(getHostPath() + "/"+resourceName, + source, contentType); + return wr; + } + /** + * test a generic Post request + * @throws Exception + */ + public void testGenericPostRequest() throws Exception { WebConversation wc = new WebConversation(); - WebRequest wr = new PostMethodWebRequest(getHostPath() + "/ReportData", - source, "text/sample"); + String sourceData="This is an interesting test\nWith two lines"; + WebRequest wr = makeRequest("ReportData",sourceData, "text/sample"); WebResponse response = wc.getResponse(wr); assertEquals("Body response", "\nPOST\n" + sourceData, response .getText()); assertEquals("Content-type", "text/sample", response.getContentType()); } + + /** + * test for Patch by Serge Maslyukov for empty content Types + * @throws Exception + */ + public void testEmptyContentType() throws Exception { + WebConversation wc = new WebConversation(); + String emptyContentType=""; // this is an emptyContentType + WebRequest wr = makeRequest("something","some data",emptyContentType); + WebResponse response = wc.getResponse(wr); + assertEquals("Content-type", "",wr.getContentType()); + } public void testPutRequest() throws Exception { defineResource("ReportData", new BodyEcho()); Modified: trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java =================================================================== --- trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java 2009-09-10 05:23:52 UTC (rev 1061) +++ trunk/httpunit/test/com/meterware/httpunit/WebClientTest.java 2009-12-22 15:34:27 UTC (rev 1062) @@ -643,7 +643,7 @@ * @throws Exception */ public void dotestRefererHeader(boolean refererEnabled) throws Exception { - String resourceName = "tellMe"; + String resourceName = "tellMe"+refererEnabled; String linkSource = "fromLink"; String formSource = "fromForm"; @@ -651,8 +651,8 @@ 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( linkSource, "<html><head></head><body><a href=\""+resourceName+"\">Go</a></body></html>" ); + defineResource( formSource, "<html><body><form action=\""+resourceName+"\"><input type=submit></form></body></html>" ); defineResource( resourceName, new PseudoServlet() { public WebResource getGetResponse() { String referer = getHeader( "Referer" ); Modified: trunk/httpunit/test/com/meterware/httpunit/javascript/NekoEnhancedScriptingTest.java =================================================================== --- trunk/httpunit/test/com/meterware/httpunit/javascript/NekoEnhancedScriptingTest.java 2009-09-10 05:23:52 UTC (rev 1061) +++ trunk/httpunit/test/com/meterware/httpunit/javascript/NekoEnhancedScriptingTest.java 2009-12-22 15:34:27 UTC (rev 1062) @@ -49,7 +49,7 @@ public void testEmbeddedDocumentWrite() throws Exception { - defineResource( "OnCommand.html", "<html><head><title>something</title></head>" + + defineResource( "OnCommandWrite.html", "<html><head><title>something</title></head>" + "<body>" + "<script language='JavaScript'>" + "document.write( '<a id=here href=about:blank>' );" + @@ -58,7 +58,7 @@ "</script>" + "</body></html>" ); WebConversation wc = new WebConversation(); - WebResponse response = wc.getResponse( getHostPath() + "/OnCommand.html" ); + WebResponse response = wc.getResponse( getHostPath() + "/OnCommandWrite.html" ); WebLink link = response.getLinkWithID( "here" ); assertNotNull( "The link was not found", link ); assertEquals( "Link contents", "something", link.getText() ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |