- * Convenience method for MavenTestingUtils.getBasePath().toFile()
- *
- * @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.
*
@@ -356,31 +341,6 @@ public final class MavenTestingUtils public String methodname; } - /** - * 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}. 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 @@ -90,36 +90,6 @@ public final class PathAssert Assert.assertTrue(msg + " path should be a File : " + path,Files.isRegularFile(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, 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. * @@ -146,36 +116,6 @@ public final class PathAssert Assert.assertTrue(msg + " path should exist: " + path,Files.exists(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, 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. * 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. - *
- * It is not meant to be robust or even configurable. - *
- * 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. - *
- * 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 "
- * 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
* Note: {@link MavenTestingUtils} will keep the directory name short for the sake of windows users.
@@ -48,30 +47,30 @@ import org.junit.runners.model.Statement;
* 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"));
* }
- * }
*
*/
public class TestingDir implements TestRule
@@ -110,36 +109,6 @@ public class TestingDir implements TestRule
return dir;
}
- /**
- * Get the test specific directory to use for testing work directory.
- *
- * Name is derived from the test classname & method name.
- *
- * @return the test specific directory.
- * @deprecated use
- * 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
@@ -164,18 +133,6 @@ public class TestingDir implements TestRule
FS.ensureEmpty(dir);
}
- /**
- * Get the unique testing directory while ensuring that it is empty (if not).
- *
- * @return the unique testing directory, created, and empty.
- * @deprecated use ${basedir}/target/tests/${testclass}/${testmethod}
.
* javax.nio.file
replacement {@link #getPath()} instead
- */
- @Deprecated
- public File getDir()
- {
- return getPath().toFile();
- }
-
- /**
- * Get a file inside of the test specific test directory.
- * javax.nio.file
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.
* javax.nio.file
replacement {@link #getEmptyPathDir()} instead
- */
- @Deprecated
- public File getEmptyDir()
- {
- return getEmptyPathDir().toFile();
- }
-
/**
* Get the unique testing directory while ensuring that it is empty (if not).
*
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