public class HttpTestUtils
extends java.lang.Object
Constructor and Description |
---|
HttpTestUtils() |
Modifier and Type | Method and Description |
---|---|
static com.google.common.util.concurrent.ListenableFuture<?> |
assertAsyncHttpStatusCodeContinuallyEquals(com.google.common.util.concurrent.ListeningExecutorService executor,
java.lang.String url,
int expectedStatusCode)
Schedules (with the given executor) a poller that repeatedly accesses the given url, to confirm it always gives
back the expected status code.
|
static void |
assertContentContainsText(java.lang.String url,
java.lang.String phrase,
java.lang.String... additionalPhrases) |
static void |
assertContentEventuallyContainsText(java.util.Map flags,
java.lang.String url,
java.lang.String phrase,
java.lang.String... additionalPhrases) |
static void |
assertContentEventuallyContainsText(java.lang.String url,
java.lang.String phrase,
java.lang.String... additionalPhrases) |
static void |
assertContentEventuallyMatches(java.lang.String url,
java.lang.String regex) |
static void |
assertContentMatches(java.lang.String url,
java.lang.String regex) |
static void |
assertContentNotContainsText(java.lang.String url,
java.lang.String phrase,
java.lang.String... additionalPhrases) |
static void |
assertErrorContentContainsText(java.lang.String url,
java.lang.String phrase,
java.lang.String... additionalPhrases) |
static void |
assertErrorContentNotContainsText(java.lang.String url,
java.lang.String phrase,
java.lang.String... additionalPhrases) |
static void |
assertHealthyStatusCode(int code) |
static void |
assertHttpStatusCodeEquals(java.lang.String url,
int... acceptableReturnCodes) |
static void |
assertHttpStatusCodeEventuallyEquals(java.util.Map flags,
java.lang.String url,
int expectedCode) |
static void |
assertHttpStatusCodeEventuallyEquals(java.lang.String url,
int expectedCode) |
static void |
assertUrlReachable(java.lang.String url)
Asserts that gets back any "valid" response - i.e.
|
static void |
assertUrlUnreachable(java.lang.String url) |
static void |
assertUrlUnreachableEventually(java.util.Map flags,
java.lang.String url) |
static void |
assertUrlUnreachableEventually(java.lang.String url) |
static void |
closeQuietly(java.net.HttpURLConnection connection)
Closes all streams of the connection, and disconnects it.
|
static java.net.URLConnection |
connectToUrl(java.lang.String u)
Connects to the given url and returns the connection.
|
static void |
consumeAndCloseQuietly(java.net.HttpURLConnection connection)
Consumes the input stream entirely and then cleanly closes the connection.
|
static java.lang.String |
getContent(java.lang.String url) |
static java.lang.String |
getErrorContent(java.lang.String url) |
static int |
getHttpStatusCode(java.lang.String url) |
public static java.net.URLConnection connectToUrl(java.lang.String u) throws java.lang.Exception
connection.getInputStream().close()
the result of this
(especially if they are making heavy use of this method).java.lang.Exception
public static void assertHealthyStatusCode(int code)
public static int getHttpStatusCode(java.lang.String url) throws java.lang.Exception
java.lang.Exception
public static void assertUrlReachable(java.lang.String url)
public static void assertUrlUnreachable(java.lang.String url)
public static void assertUrlUnreachableEventually(java.lang.String url)
public static void assertUrlUnreachableEventually(java.util.Map flags, java.lang.String url)
public static void assertHttpStatusCodeEquals(java.lang.String url, int... acceptableReturnCodes)
public static void assertHttpStatusCodeEventuallyEquals(java.lang.String url, int expectedCode)
public static void assertHttpStatusCodeEventuallyEquals(java.util.Map flags, java.lang.String url, int expectedCode)
public static void assertContentContainsText(java.lang.String url, java.lang.String phrase, java.lang.String... additionalPhrases)
public static void assertContentNotContainsText(java.lang.String url, java.lang.String phrase, java.lang.String... additionalPhrases)
public static void assertErrorContentContainsText(java.lang.String url, java.lang.String phrase, java.lang.String... additionalPhrases)
public static void assertErrorContentNotContainsText(java.lang.String url, java.lang.String phrase, java.lang.String... additionalPhrases)
public static void assertContentEventuallyContainsText(java.lang.String url, java.lang.String phrase, java.lang.String... additionalPhrases)
public static void assertContentEventuallyContainsText(java.util.Map flags, java.lang.String url, java.lang.String phrase, java.lang.String... additionalPhrases)
public static void assertContentMatches(java.lang.String url, java.lang.String regex)
public static void assertContentEventuallyMatches(java.lang.String url, java.lang.String regex)
public static java.lang.String getErrorContent(java.lang.String url)
public static java.lang.String getContent(java.lang.String url)
public static com.google.common.util.concurrent.ListenableFuture<?> assertAsyncHttpStatusCodeContinuallyEquals(com.google.common.util.concurrent.ListeningExecutorService executor, java.lang.String url, int expectedStatusCode)
Future<?> future = assertAsyncHttpStatusCodeContinuallyEquals(executor, url, 200);
// do other stuff...
if (future.isDone()) future.get(); // get exception if it's failed
For stopping it, you can either do future.cancel(true), or you can just do executor.shutdownNow().
TODO Look at difference between this and WebAppMonitor, to decide if this should be kept.public static void consumeAndCloseQuietly(java.net.HttpURLConnection connection)
public static void closeQuietly(java.net.HttpURLConnection connection)