/** Test the return value of the PostMethod#removeParameter. */
  public void testRemoveParameterReturnValue() throws Exception {
    PostMethod method = new PostMethod("/");

    method.addParameter("param", "whatever");
    assertTrue(
        "Return value of the method is expected to be true", method.removeParameter("param"));
    assertFalse(
        "Return value of the method is expected to be false", method.removeParameter("param"));
  }
  /** Test that the body can be set as a String without an explict content type */
  public void testStringBodyToBodyServlet() throws Exception {
    PostMethod method = new PostMethod("/");
    String stringBody = "pname1=pvalue1&pname2=pvalue2";

    method.setRequestEntity(new StringRequestEntity(stringBody, null, null));
    this.server.setHttpService(new EchoService());
    try {
      this.client.executeMethod(method);
      assertEquals(200, method.getStatusCode());
      String body = method.getResponseBodyAsString();
      assertEquals("pname1=pvalue1&pname2=pvalue2", body);
    } finally {
      method.releaseConnection();
    }
  }
  /** Test that parameters can be added. */
  public void testAddParametersToParamServlet() throws Exception {
    PostMethod method = new PostMethod("/");

    method.addParameter(new NameValuePair("pname1", "pvalue1"));
    method.addParameter(new NameValuePair("pname2", "pvalue2"));

    this.server.setHttpService(new EchoService());
    try {
      this.client.executeMethod(method);
      assertEquals(200, method.getStatusCode());
      String body = method.getResponseBodyAsString();
      assertEquals("pname1=pvalue1&pname2=pvalue2", body);
    } finally {
      method.releaseConnection();
    }
  }
  /** Test if setParameter overwrites existing parameter values. */
  public void testAddParameterFollowedBySetParameter() throws Exception {
    PostMethod method = new PostMethod("/");

    method.addParameter("param", "a");
    method.addParameter("param", "b");
    method.addParameter("param", "c");
    assertEquals("param=a&param=b&param=c", getRequestAsString(method.getRequestEntity()));
    method.setParameter("param", "a");
    assertEquals("param=a", getRequestAsString(method.getRequestEntity()));
  }
 /**
  * Test that {@link PostMethod#addParameter(java.lang.String,java.lang.String)} and {@link
  * PostMethod#setQueryString(java.lang.String)} combine properly.
  */
 public void testPostMethodParameterAndQueryString() throws Exception {
   this.server.setHttpService(new QueryInfoService());
   PostMethod method = new PostMethod("/");
   method.setQueryString("query=string");
   method.setRequestBody(
       new NameValuePair[] {
         new NameValuePair("param", "eter"), new NameValuePair("para", "meter")
       });
   try {
     this.client.executeMethod(method);
     assertEquals(200, method.getStatusCode());
     String response = method.getResponseBodyAsString();
     assertTrue(response.indexOf("QueryString=\"query=string\"") >= 0);
     assertFalse(response.indexOf("QueryString=\"param=eter&para=meter\"") >= 0);
   } finally {
     method.releaseConnection();
   }
 }