Merge "372115: codeformat of AsyncContextTest.java"

This commit is contained in:
Jesse McConnell 2012-03-05 08:43:35 -05:00 committed by Gerrit Code Review @ Eclipse.org
commit d5443ded0e
1 changed files with 59 additions and 59 deletions

View File

@ -9,7 +9,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import junit.framework.Assert; import junit.framework.Assert;
import org.eclipse.jetty.continuation.ContinuationSupport; import org.eclipse.jetty.continuation.ContinuationSupport;
@ -62,74 +62,74 @@ public class AsyncContextTest
@Test @Test
public void testSimpleAsyncContext() throws Exception public void testSimpleAsyncContext() throws Exception
{ {
String request = "GET /servletPath HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" String request = "GET /servletPath HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
+ "Connection: close\r\n" + "\r\n"; + "Connection: close\r\n" + "\r\n";
String responseString = _connector.getResponses(request); String responseString = _connector.getResponses(request);
BufferedReader br = parseHeader(responseString); BufferedReader br = parseHeader(responseString);
Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath", br.readLine()); Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath",br.readLine());
Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath", br.readLine()); Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath",br.readLine());
Assert.assertEquals("async context gets right path in async","async:run:attr:servletPath:/servletPath", br.readLine()); Assert.assertEquals("async context gets right path in async","async:run:attr:servletPath:/servletPath",br.readLine());
} }
@Test @Test
public void testDispatchAsyncContext() throws Exception public void testDispatchAsyncContext() throws Exception
{ {
String request = "GET /servletPath?dispatch=true HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" String request = "GET /servletPath?dispatch=true HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
+ "Connection: close\r\n" + "\r\n"; + "Connection: close\r\n" + "\r\n";
String responseString = _connector.getResponses(request); String responseString = _connector.getResponses(request);
BufferedReader br = parseHeader(responseString); BufferedReader br = parseHeader(responseString);
Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath2", br.readLine()); Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath2",br.readLine());
Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath2", br.readLine()); Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath2",br.readLine());
Assert.assertEquals("servlet path attr is original","async:run:attr:servletPath:/servletPath", br.readLine()); Assert.assertEquals("servlet path attr is original","async:run:attr:servletPath:/servletPath",br.readLine());
Assert.assertEquals("path info attr is correct","async:run:attr:pathInfo:null", br.readLine()); Assert.assertEquals("path info attr is correct","async:run:attr:pathInfo:null",br.readLine());
Assert.assertEquals("query string attr is correct","async:run:attr:queryString:dispatch=true", br.readLine()); Assert.assertEquals("query string attr is correct","async:run:attr:queryString:dispatch=true",br.readLine());
Assert.assertEquals("context path attr is correct","async:run:attr:contextPath:", br.readLine()); Assert.assertEquals("context path attr is correct","async:run:attr:contextPath:",br.readLine());
Assert.assertEquals("request uri attr is correct","async:run:attr:requestURI:/servletPath", br.readLine()); Assert.assertEquals("request uri attr is correct","async:run:attr:requestURI:/servletPath",br.readLine());
} }
@Test @Test
public void testSimpleWithContextAsyncContext() throws Exception public void testSimpleWithContextAsyncContext() throws Exception
{ {
_contextHandler.setContextPath("/foo"); _contextHandler.setContextPath("/foo");
String request = "GET /foo/servletPath HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" String request = "GET /foo/servletPath HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
+ "Connection: close\r\n" + "\r\n"; + "Connection: close\r\n" + "\r\n";
String responseString = _connector.getResponses(request); String responseString = _connector.getResponses(request);
BufferedReader br = parseHeader(responseString); BufferedReader br = parseHeader(responseString);
Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath", br.readLine()); Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath",br.readLine());
Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath", br.readLine()); Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath",br.readLine());
Assert.assertEquals("async context gets right path in async","async:run:attr:servletPath:/servletPath", br.readLine()); Assert.assertEquals("async context gets right path in async","async:run:attr:servletPath:/servletPath",br.readLine());
} }
@Test @Test
public void testDispatchWithContextAsyncContext() throws Exception public void testDispatchWithContextAsyncContext() throws Exception
{ {
_contextHandler.setContextPath("/foo"); _contextHandler.setContextPath("/foo");
String request = "GET /foo/servletPath?dispatch=true HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" String request = "GET /foo/servletPath?dispatch=true HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
+ "Connection: close\r\n" + "\r\n"; + "Connection: close\r\n" + "\r\n";
String responseString = _connector.getResponses(request); String responseString = _connector.getResponses(request);
BufferedReader br = parseHeader(responseString); BufferedReader br = parseHeader(responseString);
Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath2", br.readLine()); Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath2",br.readLine());
Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath2", br.readLine()); Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath2",br.readLine());
Assert.assertEquals("servlet path attr is original","async:run:attr:servletPath:/servletPath", br.readLine()); Assert.assertEquals("servlet path attr is original","async:run:attr:servletPath:/servletPath",br.readLine());
Assert.assertEquals("path info attr is correct","async:run:attr:pathInfo:null", br.readLine()); Assert.assertEquals("path info attr is correct","async:run:attr:pathInfo:null",br.readLine());
Assert.assertEquals("query string attr is correct","async:run:attr:queryString:dispatch=true", br.readLine()); Assert.assertEquals("query string attr is correct","async:run:attr:queryString:dispatch=true",br.readLine());
Assert.assertEquals("context path attr is correct","async:run:attr:contextPath:/foo", br.readLine()); Assert.assertEquals("context path attr is correct","async:run:attr:contextPath:/foo",br.readLine());
Assert.assertEquals("request uri attr is correct","async:run:attr:requestURI:/foo/servletPath", br.readLine()); Assert.assertEquals("request uri attr is correct","async:run:attr:requestURI:/foo/servletPath",br.readLine());
} }
@Test @Test
public void testDispatch() throws Exception public void testDispatch() throws Exception
@ -187,28 +187,28 @@ public class AsyncContextTest
} }
} }
private class AsyncDispatchingServlet extends HttpServlet private class AsyncDispatchingServlet extends HttpServlet
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override
protected void doGet(HttpServletRequest req, final HttpServletResponse response) throws ServletException, IOException protected void doGet(HttpServletRequest req, final HttpServletResponse response) throws ServletException, IOException
{ {
Request request = (Request)req; Request request = (Request)req;
if (request.getDispatcherType() == DispatcherType.ASYNC) if (request.getDispatcherType() == DispatcherType.ASYNC)
{ {
response.getOutputStream().print("Dispatched back to AsyncDispatchingServlet"); response.getOutputStream().print("Dispatched back to AsyncDispatchingServlet");
} }
else else
{ {
final AsyncContext asyncContext; final AsyncContext asyncContext;
if (request.getParameter("dispatchRequestResponse") != null) if (request.getParameter("dispatchRequestResponse") != null)
asyncContext = request.startAsync(request,response); asyncContext = request.startAsync(request,response);
else else
asyncContext = request.startAsync(); asyncContext = request.startAsync();
new Thread(new DispatchingRunnable(asyncContext)).start(); new Thread(new DispatchingRunnable(asyncContext)).start();
} }
} }
} }