commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestMethodsNoHost.java
Date Wed, 10 Jul 2002 11:33:40 GMT
dion        2002/07/10 04:33:40

  Modified:    httpclient/src/test/org/apache/commons/httpclient
                        TestMethodsNoHost.java
  Log:
  Fix for bug 10634 kindly provided by Jeffrey Dever.
  Cleanups and tests also provided.
  
  Revision  Changes    Path
  1.3       +55 -14    jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java
  
  Index: TestMethodsNoHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestMethodsNoHost.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestMethodsNoHost.java	10 Jul 2002 04:54:58 -0000	1.2
  +++ TestMethodsNoHost.java	10 Jul 2002 11:33:40 -0000	1.3
  @@ -66,6 +66,7 @@
   import org.apache.commons.httpclient.methods.*;
   
   /**
  + * @author <a href="mailto:jsdever@sympatico.ca">Jeffrey Dever</a>
    * @author Rodney Waldhoff
    * @version $Revision$ $Date$
    */
  @@ -106,6 +107,7 @@
           }
       }
   
  +    /** Ensure setRequestBody fails after addParameter is called. */
       public void testPostCantSetBodyAfterAddParam() throws Exception {
           PostMethod post = new PostMethod("/foo");
           post.addParameter("name","value");
  @@ -117,11 +119,11 @@
           }
       }
   
  -      
  +
       /** Ensure that parameters can be added and getted. */
       public void testPostAddGetParameter() {
           PostMethod post = new PostMethod();
  -       
  +
           //no parameters
           assertNull(post.getParameter("non-existant"));
           assertEquals(0, post.getParameters().length);
  @@ -135,7 +137,7 @@
           post.addParameter(PAIR0);
           assertEquals(PAIR0, post.getParameter(PAIR0.getName()));
           assertEquals(2, post.getParameters().length);
  -        
  +
           //add two more parameters
           post.addParameters(new NameValuePair[]{ PAIR1, PAIR2 });
           assertEquals(4, post.getParameters().length);
  @@ -150,18 +152,57 @@
       public void testPostAddParameterErrorCases() {
           PostMethod post = new PostMethod();
   
  +        //add null paramters
  +        try{
  +            post.addParameter(null);
  +            fail("Expected IllegalArgumentException");
  +        } catch(IllegalArgumentException e) { }
  +
  +        try{
  +            post.addParameter(null, "value");
  +            fail("Expected IllegalArgumentException");
  +        } catch(IllegalArgumentException e) { }
  +
  +        try{
  +            post.addParameter("name", null);
  +            fail("Expected IllegalArgumentException");
  +        } catch(IllegalArgumentException e) { }
  +    }
  +
  +    /** Adding the same parameter twice should be OK. */
  +    public void testPostAddSameParameter() {
  +        PostMethod post = new PostMethod();
  +
           //add same parameter twice
           post.addParameter(PAIR0);
           post.addParameter(PAIR0);
  -        assertEquals(1, post.getParameters().length);
   
  -        //add null paramter
  -        post.addParameter(null);
  -        post.addParameter(null, "value");
  -        post.addParameter("name", null);
  +        assertEquals(2, post.getParameters().length);
  +        NameValuePair[] pairs = post.getParameters();
  +        assertEquals(pairs[0], pairs[1]);
       }
  -        
  - 
  +
  +    public void testPostParametersEncoding(){
  +        PostMethod post = new PostMethod();
  +        post.addParameter(PAIR);
  +        assertEquals("name=value", post.getRequestBody());
  +
  +        post.addParameters(new NameValuePair[]{ PAIR1, PAIR2 });
  +        assertEquals("name=value&name1=value1&name2=value2", post.getRequestBody());
  +
  +        post.addParameter("hasSpace", "a b c d");
  +        assertEquals("name=value&name1=value1&name2=value2&hasSpace=a+b+c+d",
post.getRequestBody());
  +
  +    }
  +
  +    public void testPostSetRequestBody() throws Exception {
  +        PostMethod post = new PostMethod("/foo");
  +        String body = "this+is+the+body";
  +        post.setRequestBody(body);
  +        assertEquals(body, post.getRequestBody());
  +    }
  +
  +
       public void testPostSetRequestBodyThrowsIllegalState() throws Exception {
           PostMethod post = new PostMethod("/foo");
           post.addParameter(NAME0, VALUE0);
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message