Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
Add test for query parameters in HTTP requests
Browse files Browse the repository at this point in the history
  • Loading branch information
royclarkson committed Jun 24, 2015
1 parent 2f21201 commit 7997f4b
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

Expand All @@ -41,6 +42,7 @@
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;
Expand Down Expand Up @@ -81,6 +83,7 @@ private static void setUpJetty() throws Exception {
baseUrl = "http://localhost:" + port;
Context jettyContext = new Context(jettyServer, "/");
jettyContext.addServlet(new ServletHolder(new EchoServlet()), "/echo");
jettyContext.addServlet(new ServletHolder(new ParameterServlet()), "/params");
jettyContext.addServlet(new ServletHolder(new GzipServlet()), "/gzip");
jettyContext.addServlet(new ServletHolder(new IdentityServlet()), "/identity");
jettyContext.addServlet(new ServletHolder(new NoEncodingServlet()), "/noencoding");
Expand Down Expand Up @@ -316,6 +319,20 @@ protected void assertHttpMethod(String path, HttpMethod method) throws Exception
}
}

@MediumTest
public void testQueryParameters() throws Exception {
URI uri = new URI(baseUrl + "/params?param1=value&param2=value1&param2=value2");
ClientHttpRequest request = factory.createRequest(uri, HttpMethod.GET);

ClientHttpResponse response = request.execute();
try {
assertEquals("Invalid status code", HttpStatus.OK, response.getStatusCode());
}
finally {
response.close();
}
}

@MediumTest
public void testGetAcceptEncodingGzip() throws Exception {
ClientHttpRequest request = factory.createRequest(new URI(baseUrl + "/gzip"), HttpMethod.GET);
Expand Down Expand Up @@ -553,6 +570,28 @@ private void echo(HttpServletRequest request, HttpServletResponse response) thro
}
}

@SuppressWarnings("serial")
private static class ParameterServlet extends HttpServlet {

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Map<String, String[]> parameters = req.getParameterMap();
assertEquals(2, parameters.size());

String[] values = parameters.get("param1");
assertEquals(1, values.length);
assertEquals("value", values[0]);

values = parameters.get("param2");
assertEquals(2, values.length);
assertEquals("value1", values[0]);
assertEquals("value2", values[1]);

resp.setStatus(200);
resp.setContentLength(0);
}
}

@SuppressWarnings("serial")
private static class GzipServlet extends HttpServlet {

Expand Down

0 comments on commit 7997f4b

Please sign in to comment.