Пример #1
0
 /**
  * Test that {@link GetMethod#setQueryString(java.lang.String)} can include a leading question
  * mark.
  */
 public void testGetMethodQueryString() throws Exception {
   this.server.setHttpService(new QueryInfoService());
   GetMethod method = new GetMethod("/");
   method.setQueryString("?hadQuestionMark=true");
   try {
     this.client.executeMethod(method);
     assertEquals(200, method.getStatusCode());
     String response = method.getResponseBodyAsString();
     assertTrue(response.indexOf("QueryString=\"hadQuestionMark=true\"") >= 0);
   } finally {
     method.releaseConnection();
   }
 }
Пример #2
0
 /**
  * Test that {@link GetMethod#addParameter(java.lang.String,java.lang.String)} works with a
  * parameter name but no value.
  */
 public void testGetMethodParameterWithoutValue() throws Exception {
   this.server.setHttpService(new QueryInfoService());
   GetMethod method = new GetMethod("/");
   method.setQueryString(new NameValuePair[] {new NameValuePair("param-without-value", null)});
   try {
     this.client.executeMethod(method);
     assertEquals(200, method.getStatusCode());
     String response = method.getResponseBodyAsString();
     assertTrue(response.indexOf("QueryString=\"param-without-value=\"") >= 0);
   } finally {
     method.releaseConnection();
   }
 }
Пример #3
0
 /**
  * Test that {@link GetMethod#addParameter(java.lang.String,java.lang.String)} works with a
  * parameter name that occurs more than once.
  */
 public void testGetMethodParameterAppearsTwice() throws Exception {
   this.server.setHttpService(new QueryInfoService());
   GetMethod method = new GetMethod("/");
   method.setQueryString(
       new NameValuePair[] {new NameValuePair("foo", "one"), new NameValuePair("foo", "two")});
   try {
     this.client.executeMethod(method);
     assertEquals(200, method.getStatusCode());
     String response = method.getResponseBodyAsString();
     assertTrue(response.indexOf("QueryString=\"foo=one&foo=two\"") >= 0);
   } finally {
     method.releaseConnection();
   }
 }
Пример #4
0
 public void testGetMethodOverwriteQueryString() throws Exception {
   this.server.setHttpService(new QueryInfoService());
   GetMethod method = new GetMethod("/");
   method.setQueryString("query=string");
   method.setQueryString(
       new NameValuePair[] {
         new NameValuePair("param", "eter"), new NameValuePair("para", "meter")
       });
   try {
     this.client.executeMethod(method);
     assertEquals(200, method.getStatusCode());
     String response = method.getResponseBodyAsString();
     assertFalse(response.indexOf("QueryString=\"query=string\"") >= 0);
     assertTrue(response.indexOf("QueryString=\"param=eter&para=meter\"") >= 0);
   } finally {
     method.releaseConnection();
   }
 }
Пример #5
0
 /**
  * Test that {@link GetMethod#addParameter(java.lang.String,java.lang.String)} works with multiple
  * parameters.
  */
 public void testGetMethodMultiParameters() throws Exception {
   this.server.setHttpService(new QueryInfoService());
   GetMethod method = new GetMethod("/");
   method.setQueryString(
       new NameValuePair[] {
         new NameValuePair("param-one", "param-value"),
         new NameValuePair("param-two", "param-value2"),
         new NameValuePair("special-chars", ":/?~.")
       });
   try {
     this.client.executeMethod(method);
     assertEquals(200, method.getStatusCode());
     String response = method.getResponseBodyAsString();
     assertTrue(
         response.indexOf(
                 "QueryString=\"param-one=param-value&param-two=param-value2&special-chars=:/?~.\"")
             >= 0);
   } finally {
     method.releaseConnection();
   }
 }