Major update 4.0
+ Removing SimpleRequest
+ Removing http/SimpleHttpParser and http/SimpleHttpResponse
+ Removing all @deprecated methods
diff --git a/jetty-test-helper/pom.xml b/jetty-test-helper/pom.xml
index aadd850..d4e6009 100644
--- a/jetty-test-helper/pom.xml
+++ b/jetty-test-helper/pom.xml
@@ -9,7 +9,7 @@
</parent>
<artifactId>jetty-test-helper</artifactId>
<packaging>jar</packaging>
- <version>3.2-SNAPSHOT</version>
+ <version>4.0-SNAPSHOT</version>
<name>Jetty Toolchain :: Test Helper</name>
<description>Unit Testing Support for Jetty (common classes for some unit tests)</description>
<properties>
diff --git a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/MavenTestingUtils.java b/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/MavenTestingUtils.java
index 5440a6b..c5383a0 100644
--- a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/MavenTestingUtils.java
+++ b/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/MavenTestingUtils.java
@@ -51,21 +51,6 @@
*
* @return the equivalent to the maven ${basedir} property.
* @see #getBasePath()
- * @deprecated use {@link #getBaseDir()} instead
- */
- @Deprecated
- public static File getBasedir()
- {
- return getBaseDir();
- }
-
- /**
- * Obtain a {@link File} reference to the maven ${basedir} for the module.
- * <p>
- * Convenience method for <code>MavenTestingUtils.getBasePath().toFile()</code>
- *
- * @return the equivalent to the maven ${basedir} property.
- * @see #getBasePath()
*/
public static File getBaseDir()
{
@@ -357,31 +342,6 @@
}
/**
- * Using Junit 3.x test naming standards, attempt to discover a suitable test directory name
- * based on the execution stack when this method is called.
- *
- * @return the testing directory name (only the name, not the full path)
- * @deprecated Upgrade to Junit 4.x and use the {@link TestingDir} @Rule instead
- */
- @Deprecated
- public static String getTestIDAsPath()
- {
- TestID id = getTestID();
-
- id.classname = StringMangler.condensePackageString(id.classname);
-
- if (OS.IS_WINDOWS)
- {
- /* Condense the directory names to make them more friendly for the
- * 255 character pathname limitations that exist on windows.
- */
- id.methodname = StringMangler.maxStringLength(30,id.methodname);
- }
-
- return id.classname + File.separatorChar + id.methodname;
- }
-
- /**
* Get a {@link File} reference to a required file in the project module path, based on relative
* path references from maven ${basedir}.
* <p>
diff --git a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/PathAssert.java b/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/PathAssert.java
index e1ec9f8..70fc689 100644
--- a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/PathAssert.java
+++ b/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/PathAssert.java
@@ -97,36 +97,6 @@
* message about the test (used in case of assertion failure)
* @param path
* the path that should exist
- * @deprecated use {@link #assertPathExists(String, File)} instead
- */
- @Deprecated
- public static void assertExists(String msg, File path)
- {
- assertPathExists(msg,path);
- }
-
- /**
- * Assert that the path exist.
- *
- * @param msg
- * message about the test (used in case of assertion failure)
- * @param path
- * the path that should exist
- * @deprecated use {@link #assertPathExists(String, Path)} instead
- */
- @Deprecated
- public static void assertExists(String msg, Path path)
- {
- assertPathExists(msg,path);
- }
-
- /**
- * Assert that the path exist.
- *
- * @param msg
- * message about the test (used in case of assertion failure)
- * @param path
- * the path that should exist
*/
public static void assertPathExists(String msg, File path)
{
@@ -153,36 +123,6 @@
* message about the test (used in case of assertion failure)
* @param path
* the path that should not exist
- * @deprecated use {@link #assertNotPathExists(String, File)} instead
- */
- @Deprecated
- public static void assertNotExists(String msg, File path)
- {
- assertNotPathExists(msg,path);
- }
-
- /**
- * Assert that the path does not exist.
- *
- * @param msg
- * message about the test (used in case of assertion failure)
- * @param path
- * the path that should not exist
- * @deprecated use {@link #assertNotPathExists(String, Path)} instead
- */
- @Deprecated
- public static void assertNotExists(String msg, Path path)
- {
- assertNotPathExists(msg,path);
- }
-
- /**
- * Assert that the path does not exist.
- *
- * @param msg
- * message about the test (used in case of assertion failure)
- * @param path
- * the path that should not exist
*/
public static void assertNotPathExists(String msg, File path)
{
diff --git a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/SimpleRequest.java b/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/SimpleRequest.java
deleted file mode 100644
index 4a2ada0..0000000
--- a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/SimpleRequest.java
+++ /dev/null
@@ -1,166 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2015 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.toolchain.test;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringWriter;
-import java.net.HttpURLConnection;
-import java.net.URI;
-import java.util.Properties;
-
-/**
- * A super simple http request mechanism for simple testing purposes.
- * <p>
- * It is not meant to be robust or even configurable.
- * <p>
- * Do not use this for large responses, as the entire response body is always assumed to fit in a single {@link String}
- * object.
- */
-public class SimpleRequest
-{
- private URI baseUri;
-
- /**
- * Setup a SimpleRequest initiator against serverURI
- *
- * @param serverURI
- * the server URI to base all requests off of
- */
- public SimpleRequest(URI serverURI)
- {
- this.baseUri = serverURI;
- }
-
- /**
- * Initiate a simple GET request on the path specified.
- *
- * @param relativePath
- * the relative path of the serverURI to resource for this GET request
- * @return the response contents
- * @throws IOException
- * if unable to communicate with server
- */
- public String getString(String relativePath) throws IOException
- {
- URI uri = this.baseUri.resolve(relativePath);
- System.out.println("GET (String): " + uri.toASCIIString());
-
- InputStream in = null;
- InputStreamReader reader = null;
- HttpURLConnection connection = null;
-
- try
- {
- connection = (HttpURLConnection)uri.toURL().openConnection();
- connection.connect();
- if (HttpURLConnection.HTTP_OK != connection.getResponseCode())
- {
- String body = getPotentialBody(connection);
- String err = String.format("GET request failed (%d %s) %s%n%s",connection.getResponseCode(),connection.getResponseMessage(),
- uri.toASCIIString(),body);
- throw new IOException(err);
- }
- in = connection.getInputStream();
- reader = new InputStreamReader(in);
- StringWriter writer = new StringWriter();
- IO.copy(reader,writer);
- return writer.toString();
- }
- finally
- {
- IO.close(reader);
- IO.close(in);
- }
- }
-
- /**
- * Initiate a simple GET request on the path specified, returning the response contents as a {@link Properties}
- * object.
- * <p>
- * This expects that the GET response will be in the form of a Properties text file, in a format that is suitable
- * for {@link Properties#load(InputStream)} use.
- *
- * @param relativePath
- * the relative path of the serverURI to resource for this GET request
- * @return the response contents as a {@link Properties} object.
- * @throws IOException
- * if unable to communicate with server
- */
- public Properties getProperties(String relativePath) throws IOException
- {
- URI uri = this.baseUri.resolve(relativePath);
- System.out.println("GET (Properties): " + uri.toASCIIString());
-
- InputStream in = null;
- HttpURLConnection connection = null;
-
- try
- {
- connection = (HttpURLConnection)uri.toURL().openConnection();
- connection.connect();
- if (HttpURLConnection.HTTP_OK != connection.getResponseCode())
- {
- String body = getPotentialBody(connection);
- String err = String.format("GET request failed (%d %s) %s%n%s",connection.getResponseCode(),connection.getResponseMessage(),
- uri.toASCIIString(),body);
- throw new IOException(err);
- }
- in = connection.getInputStream();
- Properties props = new Properties();
- props.load(in);
- return props;
- }
- finally
- {
- IO.close(in);
- }
- }
-
- /**
- * Attempt to obtain the body text if available. Do not throw an exception if body is unable to be fetched.
- *
- * @param connection
- * the connection to fetch the body content from.
- * @return the body content, if present.
- */
- private String getPotentialBody(HttpURLConnection connection)
- {
- InputStream in = null;
- InputStreamReader reader = null;
- try
- {
- in = connection.getInputStream();
- reader = new InputStreamReader(in);
- StringWriter writer = new StringWriter();
- IO.copy(reader,writer);
- return writer.toString();
- }
- catch (IOException e)
- {
- return "<no body:" + e.getMessage() + ">";
- }
- finally
- {
- IO.close(reader);
- IO.close(in);
- }
- }
-}
diff --git a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/TestingDir.java b/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/TestingDir.java
index 3c9df85..f033fb1 100644
--- a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/TestingDir.java
+++ b/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/TestingDir.java
@@ -18,7 +18,6 @@
package org.eclipse.jetty.toolchain.test;
-import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -29,7 +28,7 @@
/**
* A junit 4.x {@link org.junit.Rule} to provide a common, easy to use, testing directory that is unique per unit test method.
* <p>
- * Similar in scope to the {@link org.junit.rules.TemporaryFolder} rule, as it creates a directory, when asked (via {@link #getDir()} or {@link #getEmptyDir()}) in the maven
+ * Similar in scope to the {@link org.junit.rules.TemporaryFolder} rule, as it creates a directory, when asked (via {@link #getPath()} or {@link #getEmptyPathDir()}) in the maven
* project familiar and friendly maven location of <code>${basedir}/target/tests/${testclass}/${testmethod}</code>.
* <p>
* Note: {@link MavenTestingUtils} will keep the directory name short for the sake of windows users.
@@ -48,30 +47,30 @@
* public TestingDir testingdir = new TestingDir();
*
* @Test
- * public void testUseDirectory()
+ * public void testUseDirectory() throws IOException
* {
- * File appDir = testingdir.getFile("app");
- * File tmpDir = testingdir.getFile("tmp");
- *
- * FS.ensureDirEmpty(appDir);
- * FS.ensureDirEmpty(tmpDir);
- *
- * File index = new File(appDir, "index.html");
- * FileWriter writer = new FileWriter(index);
- * writer.write("Hello World");
- * writer.close();
- *
+ * Path appDir = testingdir.getPathFile("app");
+ * Path tmpDir = testingdir.getPathFile("tmp");
+ *
+ * FS.ensureEmpty(appDir);
+ * FS.ensureEmpty(tmpDir);
+ *
+ * Path index = appDir.resolve("index.html");
+ * try(BufferedWriter writer = Files.newBufferedWriter(index, StandardCharsets.UTF_8))
+ * {
+ * writer.write("Hello World");
+ * }
+ *
* Server server = new Server();
* server.setTmpDir(tmpDir);
* server.addWebApp(appDir);
* server.start();
- *
+ *
* Client client = new Client();
* String response = client.request("http://localhost/app/");
- *
- * Assert.assertThat(response,containsString("Hello World"));
+ *
+ * Assert.assertThat(response, containsString("Hello World"));
* }
- * }
* </pre>
*/
public class TestingDir implements TestRule
@@ -111,36 +110,6 @@
}
/**
- * Get the test specific directory to use for testing work directory.
- * <p>
- * Name is derived from the test classname & method name.
- *
- * @return the test specific directory.
- * @deprecated use <code>javax.nio.file</code> replacement {@link #getPath()} instead
- */
- @Deprecated
- public File getDir()
- {
- return getPath().toFile();
- }
-
- /**
- * Get a file inside of the test specific test directory.
- * <p>
- * Note: No assertions are made if the file exists or not.
- *
- * @param name
- * the path name of the file (supports deep paths)
- * @return the file reference.
- * @deprecated use <code>javax.nio.file</code> replacement {@link #getPathFile(String)} instead
- */
- @Deprecated
- public File getFile(String name)
- {
- return getPathFile(name).toFile();
- }
-
- /**
* Get a {@link Path} file reference for content inside of the test specific test directory.
* <p>
* Note: No assertions are made if the file exists or not.
@@ -168,18 +137,6 @@
* Get the unique testing directory while ensuring that it is empty (if not).
*
* @return the unique testing directory, created, and empty.
- * @deprecated use <code>javax.nio.file</code> replacement {@link #getEmptyPathDir()} instead
- */
- @Deprecated
- public File getEmptyDir()
- {
- return getEmptyPathDir().toFile();
- }
-
- /**
- * Get the unique testing directory while ensuring that it is empty (if not).
- *
- * @return the unique testing directory, created, and empty.
*/
public Path getEmptyPathDir()
{
diff --git a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/http/SimpleHttpParser.java b/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/http/SimpleHttpParser.java
deleted file mode 100644
index 5ebc7b0..0000000
--- a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/http/SimpleHttpParser.java
+++ /dev/null
@@ -1,171 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2015 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.toolchain.test.http;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.junit.Assert.*;
-
-import java.io.BufferedReader;
-import java.io.EOFException;
-import java.io.IOException;
-import java.net.SocketTimeoutException;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * A simple http parser implementation to be used in tests. It's feed with a BufferedReader and will read from that
- * reader until the http response has been fully read.
- *
- * It returns a {@link SimpleHttpResponse} object that grants access to the response code,
- * headers and body of the parsed response.
- *
- * This class can easily be extended to provide more features. However keep in mind that it's primary focus is to
- * keep parsing as simple as possible.
- */
-public class SimpleHttpParser
-{
- /**
- * Reads from the given {@link BufferedReader} and returns the parsed response in a {@link SimpleHttpResponse}
- * object.
- *
- * @param reader
- * the inputReader to parse the response from
- * @return {@link SimpleHttpResponse} a {@link SimpleHttpResponse} object representing the parsed response
- * @throws IOException
- * if unable to read/parse the raw lines of http
- */
- public SimpleHttpResponse readResponse(BufferedReader reader) throws IOException
- {
- // Simplified parser for HTTP responses
- String line = reader.readLine();
- if (line == null)
- throw new EOFException();
- Matcher responseLine = Pattern.compile("HTTP/1.1" + "\\s+(\\d+)").matcher(line);
- assertThat("http version is 1.1",responseLine.lookingAt(),is(true));
- String code = responseLine.group(1);
-
- Map<String, String> headers = new LinkedHashMap<String, String>();
- while ((line = reader.readLine()) != null)
- {
- if (line.trim().length() == 0)
- break;
-
- parseHeader(line,headers);
- }
-
- StringBuilder body;
- if (headers.containsKey("content-length"))
- {
- body = parseContentLengthDelimitedBody(reader,headers);
- }
- else if ("chunked".equals(headers.get("transfer-encoding")))
- {
- body = parseChunkedBody(reader);
- }
- else
- {
- body = parseEOFDelimitedBody(reader,headers);
- }
-
- return new SimpleHttpResponse(code,headers,body.toString().trim());
- }
-
- private void parseHeader(String line, Map<String, String> headers)
- {
- Matcher header = Pattern.compile("([^:]+):\\s*(.*)").matcher(line);
- assertTrue(header.lookingAt());
- String headerName = header.group(1);
- String headerValue = header.group(2);
- headers.put(headerName.toLowerCase(),headerValue.toLowerCase());
- }
-
- private StringBuilder parseContentLengthDelimitedBody(BufferedReader reader, Map<String, String> headers) throws IOException
- {
- StringBuilder body;
- int readLen = 0;
- int length = Integer.parseInt(headers.get("content-length"));
- body = new StringBuilder(length);
- try
- {
- //TODO: UTF-8 reader from joakim
- for (int i = 0; i < length; ++i)
- {
- char c = (char)reader.read();
- body.append(c);
- readLen++;
- }
-
- }
- catch (SocketTimeoutException e)
- {
- System.err.printf("Read %,d bytes (out of an expected %,d bytes)%n",readLen,length);
- throw e;
- }
- return body;
- }
-
- private StringBuilder parseChunkedBody(BufferedReader reader) throws IOException
- {
- StringBuilder body;
- String line;
- body = new StringBuilder(64 * 1024);
- while ((line = reader.readLine()) != null)
- {
- if ("0".equals(line))
- {
- line = reader.readLine();
- assertThat("There's no more content after as 0 indicated the final chunk",line,is(""));
- break;
- }
-
- int length = Integer.parseInt(line,16);
- //TODO: UTF-8 reader from joakim
- for (int i = 0; i < length; ++i)
- {
- char c = (char)reader.read();
- body.append(c);
- }
- reader.readLine();
- // assertThat("chunk is followed by an empty line", line, is("")); //TODO: is this right? - NO. Don't
- // think you can really do chunks with read line generally, but maybe for this test is OK.
- }
- return body;
- }
-
- private StringBuilder parseEOFDelimitedBody(BufferedReader reader, Map<String, String> headers) throws IOException
- {
- StringBuilder body;
-
- // read until EOF
- body = new StringBuilder();
- while (true)
- {
- //TODO: UTF-8 reader from joakim
- int read = reader.read();
- if (read == -1)
- break;
- char c = (char)read;
- body.append(c);
- }
- return body;
- }
-
-}
diff --git a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/http/SimpleHttpResponse.java b/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/http/SimpleHttpResponse.java
deleted file mode 100644
index 2bca59f..0000000
--- a/jetty-test-helper/src/main/java/org/eclipse/jetty/toolchain/test/http/SimpleHttpResponse.java
+++ /dev/null
@@ -1,80 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2015 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.toolchain.test.http;
-
-import java.util.Collections;
-import java.util.Map;
-
-/**
- * A very simple container for an HttpResponse. Just holding response code, headers and body information.
- */
-public class SimpleHttpResponse
-{
- private final String code;
- private final Map<String, String> headers;
- private final String body;
-
- /**
- * Initialize the immutable HTTP Response details
- *
- * @param code the response status code
- * @param headers the response headers
- * @param body the response body content
- */
- public SimpleHttpResponse(String code, Map<String, String> headers, String body)
- {
- this.code = code;
- this.headers = headers;
- this.body = body;
- }
-
- /**
- * @return the response status code
- */
- public String getCode()
- {
- return code;
- }
-
- /**
- * @return the response headers
- */
- public Map<String, String> getHeaders()
- {
- return Collections.unmodifiableMap(headers);
- }
-
- /**
- * @return the response body content
- */
- public String getBody()
- {
- return body;
- }
-
- @Override
- public String toString()
- {
- return "Response{" +
- "code='" + code + '\'' +
- ", headers=" + headers +
- ", body='" + body + '\'' +
- '}';
- }
-}
diff --git a/jetty-test-helper/src/test/java/org/eclipse/jetty/toolchain/test/TestingDirTest.java b/jetty-test-helper/src/test/java/org/eclipse/jetty/toolchain/test/TestingDirTest.java
index 789c619..42f9ca4 100644
--- a/jetty-test-helper/src/test/java/org/eclipse/jetty/toolchain/test/TestingDirTest.java
+++ b/jetty-test-helper/src/test/java/org/eclipse/jetty/toolchain/test/TestingDirTest.java
@@ -18,7 +18,7 @@
package org.eclipse.jetty.toolchain.test;
-import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.CoreMatchers.containsString;
import java.io.IOException;
import java.nio.file.Path;
@@ -40,6 +40,6 @@
Path dir = testingdir.getPath();
String fullpath = dir.toString();
- Assert.assertThat(fullpath,containsString(expected));
+ Assert.assertThat(fullpath, containsString(expected));
}
}