diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java index 6bff42a88dd..3d96934291f 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java @@ -69,7 +69,7 @@ public abstract class AbstractHttpTest server.stop(); } - protected TestHttpResponse executeRequest() throws URISyntaxException, IOException + protected SimpleHttpParser.TestHttpResponse executeRequest() throws URISyntaxException, IOException { Socket socket = new Socket("localhost", connector.getLocalPort()); BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8")); @@ -84,12 +84,12 @@ public abstract class AbstractHttpTest return httpParser.readResponse(reader); } - protected void assertResponseBody(TestHttpResponse response, String expectedResponseBody) + protected void assertResponseBody(SimpleHttpParser.TestHttpResponse response, String expectedResponseBody) { assertThat("response body is" + expectedResponseBody, response.getBody(), is(expectedResponseBody)); } - protected void assertHeader(TestHttpResponse response, String headerName, String expectedValue) + protected void assertHeader(SimpleHttpParser.TestHttpResponse response, String headerName, String expectedValue) { assertThat(headerName + "=" + expectedValue, response.getHeaders().get(headerName), is(expectedValue)); } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java index 3735838a220..234d7f8d264 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java @@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.HttpVersion; +import org.eclipse.jetty.server.util.SimpleHttpParser; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -65,7 +66,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new DoesNotSetHandledHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 404", response.getCode(), is("404")); } @@ -76,7 +77,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new DoesNotSetHandledHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 500", response.getCode(), is("500")); } @@ -119,7 +120,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new OnlySetHandledHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); assertHeader(response, "content-length", "0"); @@ -131,7 +132,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new OnlySetHandledHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 500", response.getCode(), is("500")); } @@ -176,7 +177,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new SetHandledWriteSomeDataHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); assertHeader(response, "content-length", "6"); @@ -188,7 +189,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new SetHandledWriteSomeDataHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 500", response.getCode(), is("500")); } @@ -240,7 +241,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new ExplicitFlushHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); @@ -254,7 +255,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new ExplicitFlushHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); if ("HTTP/1.1".equals(httpVersion)) @@ -310,7 +311,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new SetHandledAndFlushWithoutContentHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); if ("HTTP/1.1".equals(httpVersion)) @@ -323,7 +324,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new SetHandledAndFlushWithoutContentHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); if ("HTTP/1.1".equals(httpVersion)) @@ -377,7 +378,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new WriteFlushWriteMoreHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); if ("HTTP/1.1".equals(httpVersion)) @@ -390,7 +391,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new WriteFlushWriteMoreHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); if ("HTTP/1.1".equals(httpVersion)) @@ -447,7 +448,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new OverflowHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); assertResponseBody(response, "foobar"); @@ -460,7 +461,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new OverflowHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); // response not committed when we throw, so 500 expected assertThat("response code is 500", response.getCode(), is("500")); @@ -515,7 +516,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new SetContentLengthAndWriteThatAmountOfBytesHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); assertThat("response body is foo", response.getBody(), is("foo")); @@ -528,7 +529,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new SetContentLengthAndWriteThatAmountOfBytesHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); //TODO: should we expect 500 here? assertThat("response code is 200", response.getCode(), is("200")); @@ -585,7 +586,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new SetContentLengthAndWriteMoreBytesHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); // jetty truncates the body when content-length is reached.! This is correct and desired behaviour? @@ -599,7 +600,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new SetContentLengthAndWriteMoreBytesHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); // TODO: we throw before response is committed. should we expect 500? assertThat("response code is 200", response.getCode(), is("200")); @@ -656,7 +657,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new WriteAndSetContentLengthHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); //TODO: jetty ignores setContentLength and sends transfer-encoding header. Correct? @@ -668,7 +669,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new WriteAndSetContentLengthHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); } @@ -723,7 +724,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new WriteAndSetContentLengthTooSmallHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); assertResponseBody(response, "foobar"); @@ -738,7 +739,7 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest server.setHandler(new WriteAndSetContentLengthTooSmallHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat(response.getCode(), is("500")); } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java index 0ad98bb881b..476da5d67fe 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToCommitTest.java @@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.HttpVersion; +import org.eclipse.jetty.server.util.SimpleHttpParser; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -57,7 +58,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new DoesNotSetHandledHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 404", response.getCode(), is("404")); } @@ -68,7 +69,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new DoesNotSetHandledHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 500", response.getCode(), is("500")); } @@ -94,7 +95,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new OnlySetHandledHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); assertHeader(response, "content-length", "0"); @@ -106,7 +107,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new OnlySetHandledHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 500", response.getCode(), is("500")); } @@ -133,7 +134,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new SetHandledWriteSomeDataHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); assertHeader(response, "content-length", "6"); @@ -145,7 +146,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new SetHandledWriteSomeDataHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 500", response.getCode(), is("500")); } @@ -172,7 +173,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new ExplicitFlushHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); @@ -186,7 +187,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new ExplicitFlushHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); if ("HTTP/1.1".equals(httpVersion)) @@ -216,7 +217,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new SetHandledAndFlushWithoutContentHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); if ("HTTP/1.1".equals(httpVersion)) @@ -229,7 +230,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new SetHandledAndFlushWithoutContentHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); if ("HTTP/1.1".equals(httpVersion)) @@ -258,7 +259,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new WriteFlushWriteMoreHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); if ("HTTP/1.1".equals(httpVersion)) @@ -271,7 +272,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new WriteFlushWriteMoreHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); if ("HTTP/1.1".equals(httpVersion)) @@ -302,7 +303,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new OverflowHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); assertResponseBody(response, "foobar"); @@ -315,7 +316,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new OverflowHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); // response not committed when we throw, so 500 expected assertThat("response code is 500", response.getCode(), is("500")); @@ -344,7 +345,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new SetContentLengthAndWriteThatAmountOfBytesHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); assertThat("response body is foo", response.getBody(), is("foo")); @@ -358,7 +359,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new SetContentLengthAndWriteThatAmountOfBytesHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); //TODO: should we expect 500 here? assertThat("response code is 200", response.getCode(), is("200")); @@ -389,7 +390,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new SetContentLengthAndWriteMoreBytesHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); // jetty truncates the body when content-length is reached.! This is correct and desired behaviour? @@ -403,7 +404,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new SetContentLengthAndWriteMoreBytesHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); // TODO: we throw before response is committed. should we expect 500? assertThat("response code is 200", response.getCode(), is("200")); @@ -434,7 +435,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new WriteAndSetContentLengthHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); //TODO: jetty ignores setContentLength and sends transfer-encoding header. Correct? @@ -446,7 +447,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new WriteAndSetContentLengthHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); } @@ -475,7 +476,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new WriteAndSetContentLengthTooSmallHandler(false)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat("response code is 200", response.getCode(), is("200")); assertResponseBody(response, "foobar"); @@ -490,7 +491,7 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest server.setHandler(new WriteAndSetContentLengthTooSmallHandler(true)); server.start(); - TestHttpResponse response = executeRequest(); + SimpleHttpParser.TestHttpResponse response = executeRequest(); assertThat(response.getCode(), is("500")); } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/TestHttpResponse.java b/jetty-server/src/test/java/org/eclipse/jetty/server/TestHttpResponse.java deleted file mode 100644 index 6f617f629c0..00000000000 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/TestHttpResponse.java +++ /dev/null @@ -1,60 +0,0 @@ -// -// ======================================================================== -// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd. -// ------------------------------------------------------------------------ -// All rights reserved. This program and the accompanying materials -// are made available under the terms of the Eclipse Public License v1.0 -// and Apache License v2.0 which accompanies this distribution. -// -// The Eclipse Public License is available at -// http://www.eclipse.org/legal/epl-v10.html -// -// The Apache License v2.0 is available at -// http://www.opensource.org/licenses/apache2.0.php -// -// You may elect to redistribute this code under either of these licenses. -// ======================================================================== -// - -package org.eclipse.jetty.server; - -import java.util.Map; - -public class TestHttpResponse -{ - private final String code; - private final Map headers; - private final String body; - - public TestHttpResponse(String code, Map headers, String body) - { - this.code = code; - this.headers = headers; - this.body = body; - } - - public String getCode() - { - return code; - } - - public Map getHeaders() - { - return headers; - } - - public String getBody() - { - return body; - } - - @Override - public String toString() - { - return "Response{" + - "code='" + code + '\'' + - ", headers=" + headers + - ", body='" + body + '\'' + - '}'; - } -} diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/util/SimpleHttpParser.java b/jetty-server/src/test/java/org/eclipse/jetty/server/util/SimpleHttpParser.java index ad443e6c5b5..59af6602c3c 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/util/SimpleHttpParser.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/util/SimpleHttpParser.java @@ -27,8 +27,6 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.eclipse.jetty.server.TestHttpResponse; - import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -161,4 +159,43 @@ public class SimpleHttpParser } return body; } + + public static class TestHttpResponse + { + private final String code; + private final Map headers; + private final String body; + + public TestHttpResponse(String code, Map headers, String body) + { + this.code = code; + this.headers = headers; + this.body = body; + } + + public String getCode() + { + return code; + } + + public Map getHeaders() + { + return headers; + } + + public String getBody() + { + return body; + } + + @Override + public String toString() + { + return "Response{" + + "code='" + code + '\'' + + ", headers=" + headers + + ", body='" + body + '\'' + + '}'; + } + } }