[Httpunit-commit] CVS: httpunit/test/com/meterware/servletunit HttpServletRequestTest.java,1.19,1.20
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2004-03-02 11:13:53
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27879/test/com/meterware/servletunit Modified Files: HttpServletRequestTest.java RequestContextTest.java Log Message: support request body encoding in ServletUnit Index: HttpServletRequestTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- HttpServletRequestTest.java 26 Feb 2004 17:36:47 -0000 1.19 +++ HttpServletRequestTest.java 2 Mar 2004 10:54:15 -0000 1.20 @@ -34,6 +34,7 @@ import com.meterware.httpunit.GetMethodWebRequest; import com.meterware.httpunit.WebRequest; import com.meterware.httpunit.PutMethodWebRequest; +import com.meterware.httpunit.PostMethodWebRequest; import junit.framework.Test; import junit.framework.TestSuite; @@ -419,6 +420,28 @@ } + public void testSpecifiedCharEncoding() throws Exception { + String hebrewValue = "\u05d0\u05d1\u05d2\u05d3"; + String paramString = "param1=red¶m2=" + hebrewValue; + WebRequest wr = new PostMethodWebRequest( "http://localhost/simple" ); + wr.setHeaderField( "Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-8" ); + ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), paramString.getBytes( "ISO-8859-8" ) ); + assertEquals( "param1 value", "red", request.getParameter( "param1") ); + assertEquals( "param2 value", hebrewValue, request.getParameter( "param2") ); + } + + + public void testSuppliedCharEncoding() throws Exception { + String hebrewValue = "\u05d0\u05d1\u05d2\u05d3"; + String paramString = "param1=red¶m2=" + hebrewValue; + WebRequest wr = new PostMethodWebRequest( "http://localhost/simple" ); + ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), paramString.getBytes( "ISO-8859-8" ) ); + request.setCharacterEncoding( "ISO-8859-8" ); + assertEquals( "param1 value", "red", request.getParameter( "param1") ); + assertEquals( "param2 value", hebrewValue, request.getParameter( "param2") ); + } + + private final static byte[] NO_MESSAGE_BODY = new byte[0]; private final static ServletMetaData NULL_SERVLET_REQUEST = new ServletMetaData() { Index: RequestContextTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/RequestContextTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- RequestContextTest.java 13 Feb 2003 20:25:56 -0000 1.2 +++ RequestContextTest.java 2 Mar 2004 10:54:15 -0000 1.3 @@ -73,7 +73,7 @@ /** - * Verify parsing of a query string. + * Verify override of parent request parameters. */ public void testParameterOverride() throws Exception { HttpServletRequest request = new DummyHttpServletRequest( new URL( "http://localhost/basic?param=red¶m1=old¶m=blue" ) ); @@ -85,6 +85,33 @@ } + /** + * Verify parsing of message body parameters. + */ + public void testPostParameterParsing() throws Exception { + RequestContext rc = new RequestContext( new URL( "http://localhost/basic" )); + rc.setMessageBody( "param=red¶m1=old¶m=blue".getBytes() ); + assertMatchingSet( "parameter names", new String[] { "param", "param1" }, rc.getParameterNames() ); + assertMatchingSet( "param values", new String[] { "red", "blue" }, rc.getParameterValues( "param" ) ); + assertEquals( "param1 value", "old", ((String[]) rc.getParameterMap().get( "param1"))[0] ); + } + + + /** + * Verify parsing of message body parameters using a specified character encoding. + */ + public void testEncodedParameterParsing() throws Exception { + RequestContext rc = new RequestContext( new URL( "http://localhost/basic" )); + String hebrewValue = "\u05d0\u05d1\u05d2\u05d3"; + String paramString = "param=red¶m1=" + hebrewValue + "¶m=blue"; + rc.setMessageBody( paramString.getBytes( "iso-8859-8" ) ); + rc.setMessageEncoding( "iso-8859-8" ); + assertMatchingSet( "parameter names", new String[] { "param", "param1" }, rc.getParameterNames() ); + assertMatchingSet( "param values", new String[] { "red", "blue" }, rc.getParameterValues( "param" ) ); + assertEquals( "param1 value", hebrewValue, ((String[]) rc.getParameterMap().get( "param1"))[0] ); + } + + class DummyHttpServletRequest implements HttpServletRequest { private RequestContext _requestContext; |