324110 Added test harnesses for merging of QueryStrings

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2897 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2011-03-16 22:23:31 +00:00
parent 47c2db544d
commit 3ec94365ae
2 changed files with 95 additions and 0 deletions

View File

@ -1,4 +1,5 @@
jetty-7.3.2-SNAPSHOT
+ 324110 Added test harnesses for merging of QueryStrings.
+ 337685 Update websocket API in preparation for draft -07
+ 338627 HashSessionManager.getIdleSavePeriod returns milliseconds instead of seconds
+ 338819 Externally control Deployment Manager application lifecycle

View File

@ -0,0 +1,94 @@
package org.eclipse.jetty.servlet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.continuation.Continuation;
import org.eclipse.jetty.continuation.ContinuationSupport;
import org.eclipse.jetty.server.AsyncContinuation;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.LocalConnector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* This tests verifies that merging of queryStrings works when dispatching
* Requests via {@link Continuation} multiple times.
*
* @author tbecker
*
*/
public class AsyncContextDispatchWithQueryStrings {
private Server _server = new Server();
private ServletContextHandler _contextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
private LocalConnector _connector = new LocalConnector();
@Before
public void setUp() throws Exception {
_connector.setMaxIdleTime(30000);
_server.setConnectors(new Connector[] { _connector });
_contextHandler.setContextPath("/");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/initialCall");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/firstDispatchWithNewQueryString");
_contextHandler.addServlet(new ServletHolder(new TestServlet()), "/secondDispatchNewValueForExistingQueryString");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { _contextHandler, new DefaultHandler() });
_server.setHandler(handlers);
_server.start();
}
@Test
public void testMultipleDispatchesWithNewQueryStrings() throws Exception {
String request = "GET /initialCall?initialParam=right HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
+ "Connection: close\r\n" + "\r\n";
String responseString = _connector.getResponses(request);
assertTrue("Not the expected response. Check STDOUT for details.", responseString.startsWith("HTTP/1.1 200"));
}
@After
public void tearDown() throws Exception {
_server.stop();
_server.join();
}
private class TestServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String path = request.getRequestURI();
String queryString = request.getQueryString();
if ("/initialCall".equals(path)) {
AsyncContinuation continuation = (AsyncContinuation) ContinuationSupport.getContinuation(request);
continuation.suspend();
continuation.dispatch("/firstDispatchWithNewQueryString?newQueryString=initialValue");
assertEquals("initialParam=right", queryString);
} else if ("/firstDispatchWithNewQueryString".equals(path)) {
AsyncContinuation continuation = (AsyncContinuation) ContinuationSupport.getContinuation(request);
continuation.suspend();
continuation.dispatch("/secondDispatchNewValueForExistingQueryString?newQueryString=newValue");
assertEquals("newQueryString=initialValue&initialParam=right", queryString);
} else {
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("<h1>woohhooooo</h1>");
assertEquals("newQueryString=newValue&initialParam=right", queryString);
}
}
}
}