public class HttpAsserts
extends java.lang.Object
Constructor and Description |
---|
HttpAsserts() |
Modifier and Type | Method and Description |
---|---|
static <any> |
assertAsyncHttpStatusCodeContinuallyEquals(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 |
assertClientErrorStatusCode(int code)
Asserts that the given HTTP status code indicates "client error", i.e.
|
static void |
assertContentContainsText(java.lang.String url,
java.lang.String phrase,
java.lang.String... additionalPhrases) |
static void |
assertContentEventuallyContainsText(java.util.Map<java.lang.String,?> 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.util.Map<java.lang.String,?> flags,
java.lang.String url,
java.lang.String regex) |
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)
Asserts that the given HTTP status code indicates "success", i.e.
|
static void |
assertHttpStatusCodeEquals(java.lang.String url,
int... acceptableReturnCodes)
Assert that the status code returned from the URL is in the given codes.
|
static void |
assertHttpStatusCodeEventuallyEquals(java.util.Map<java.lang.String,?> flags,
java.lang.String url,
int expectedCode) |
static void |
assertHttpStatusCodeEventuallyEquals(java.lang.String url,
int expectedCode) |
static void |
assertNotHealthyStatusCode(int code)
Asserts that the given HTTP status code does not indicate "success", i.e.
|
static void |
assertServerErrorStatusCode(int code)
Asserts that the given HTTP status code indicates "server error", i.e.
|
static void |
assertUrlReachable(java.lang.String url)
Asserts that gets back any "valid" response - i.e.
|
static void |
assertUrlUnreachable(java.lang.String url)
Asserts that the URL could not be reached, detected as an IOException.
|
static void |
assertUrlUnreachableEventually(java.util.Map<java.lang.String,?> flags,
java.lang.String url)
Asserts that the URL becomes unreachable within a configurable time period.
|
static void |
assertUrlUnreachableEventually(java.lang.String url)
Asserts that the URL becomes unreachable within a default time period.
|
static boolean |
isClientErrorStatusCode(int code) |
static boolean |
isHealthyStatusCode(int code) |
static boolean |
isServerErrorStatusCode(int code) |
public static boolean isHealthyStatusCode(int code)
public static void assertHealthyStatusCode(int code)
isHealthyStatusCode(int)
is truepublic static void assertNotHealthyStatusCode(int code)
isHealthyStatusCode(int)
returns falsepublic static boolean isClientErrorStatusCode(int code)
public static void assertClientErrorStatusCode(int code)
isClientErrorStatusCode(int)
is truepublic static boolean isServerErrorStatusCode(int code)
public static void assertServerErrorStatusCode(int code)
isServerErrorStatusCode(int)
is truepublic static void assertUrlReachable(java.lang.String url)
url
- The URL to connect to.public static void assertUrlUnreachable(java.lang.String url)
url
- The URL to connect to.public static void assertUrlUnreachableEventually(java.lang.String url)
url
- The URLpublic static void assertUrlUnreachableEventually(java.util.Map<java.lang.String,?> flags, java.lang.String url)
flags
- The flags controlling the timeout.
For details see Asserts.succeedsEventually(java.util.Map, java.util.concurrent.Callable)
url
- The URLpublic static void assertHttpStatusCodeEquals(java.lang.String url, int... acceptableReturnCodes)
url
- The URL to get.acceptableReturnCodes
- The return codes that are expected.public static void assertHttpStatusCodeEventuallyEquals(java.lang.String url, int expectedCode)
public static void assertHttpStatusCodeEventuallyEquals(java.util.Map<java.lang.String,?> 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<java.lang.String,?> 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 void assertContentEventuallyMatches(java.util.Map<java.lang.String,?> flags, java.lang.String url, java.lang.String regex)
public static <any> assertAsyncHttpStatusCodeContinuallyEquals(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 its Asserts.failed
NOTE that the exception thrown by future.get() is a java.util.concurrent.ExecutionException,
not an AssertionError.
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.