public class Helpers extends java.lang.Object implements Http.Status, Http.HeaderNames
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_TIMEOUT
Default Timeout (milliseconds) for fake requests issued by these Helpers.
|
static java.lang.String |
DELETE |
static java.lang.Class<? extends org.openqa.selenium.WebDriver> |
FIREFOX |
static java.lang.String |
GET |
static java.lang.String |
HEAD |
static java.lang.Class<? extends org.openqa.selenium.WebDriver> |
HTMLUNIT |
static java.lang.String |
POST |
static java.lang.String |
PUT |
ACCEPTED, BAD_GATEWAY, BAD_REQUEST, CONFLICT, CONTINUE, CREATED, EXPECTATION_FAILED, FAILED_DEPENDENCY, FORBIDDEN, FOUND, GATEWAY_TIMEOUT, GONE, HTTP_VERSION_NOT_SUPPORTED, INSUFFICIENT_STORAGE, INTERNAL_SERVER_ERROR, LENGTH_REQUIRED, LOCKED, METHOD_NOT_ALLOWED, MOVED_PERMANENTLY, MULTI_STATUS, MULTIPLE_CHOICES, NO_CONTENT, NON_AUTHORITATIVE_INFORMATION, NOT_ACCEPTABLE, NOT_FOUND, NOT_IMPLEMENTED, NOT_MODIFIED, OK, PARTIAL_CONTENT, PAYMENT_REQUIRED, PERMANENT_REDIRECT, PRECONDITION_FAILED, PROXY_AUTHENTICATION_REQUIRED, REQUEST_ENTITY_TOO_LARGE, REQUEST_TIMEOUT, REQUEST_URI_TOO_LONG, REQUESTED_RANGE_NOT_SATISFIABLE, RESET_CONTENT, SEE_OTHER, SERVICE_UNAVAILABLE, SWITCHING_PROTOCOLS, TEMPORARY_REDIRECT, TOO_MANY_REQUESTS, UNAUTHORIZED, UNPROCESSABLE_ENTITY, UNSUPPORTED_MEDIA_TYPE, UPGRADE_REQUIRED, USE_PROXY
ACCEPT, ACCEPT_CHARSET, ACCEPT_ENCODING, ACCEPT_LANGUAGE, ACCEPT_RANGES, ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN, ACCESS_CONTROL_EXPOSE_HEADERS, ACCESS_CONTROL_MAX_AGE, ACCESS_CONTROL_REQUEST_HEADERS, ACCESS_CONTROL_REQUEST_METHOD, AGE, ALLOW, AUTHORIZATION, CACHE_CONTROL, CONNECTION, CONTENT_DISPOSITION, CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_LOCATION, CONTENT_MD5, CONTENT_RANGE, CONTENT_TRANSFER_ENCODING, CONTENT_TYPE, COOKIE, DATE, ETAG, EXPECT, EXPIRES, FORWARDED, FROM, HOST, IF_MATCH, IF_MODIFIED_SINCE, IF_NONE_MATCH, IF_RANGE, IF_UNMODIFIED_SINCE, LAST_MODIFIED, LOCATION, MAX_FORWARDS, ORIGIN, PRAGMA, PROXY_AUTHENTICATE, PROXY_AUTHORIZATION, RANGE, REFERER, RETRY_AFTER, SERVER, SET_COOKIE, SET_COOKIE2, TE, TRAILER, TRANSFER_ENCODING, UPGRADE, USER_AGENT, VARY, VIA, WARNING, WWW_AUTHENTICATE, X_FORWARDED_FOR, X_FORWARDED_HOST, X_FORWARDED_PORT, X_FORWARDED_PROTO, X_REQUESTED_WITH
Constructor and Description |
---|
Helpers() |
Modifier and Type | Method and Description |
---|---|
static akka.util.ByteString |
contentAsBytes(play.twirl.api.Content content)
Extracts the content as bytes.
|
static akka.util.ByteString |
contentAsBytes(Result result)
Extracts the content as a
ByteString . |
static akka.util.ByteString |
contentAsBytes(Result result,
akka.stream.Materializer mat)
Extracts the content as a
ByteString . |
static akka.util.ByteString |
contentAsBytes(Result result,
akka.stream.Materializer mat,
long timeout)
Extracts the content as a
ByteString . |
static java.lang.String |
contentAsString(play.twirl.api.Content content)
Extracts the content as a String.
|
static java.lang.String |
contentAsString(Result result)
Extracts the content as a String.
|
static java.lang.String |
contentAsString(Result result,
akka.stream.Materializer mat)
Extracts the content as a String.
|
static java.lang.String |
contentAsString(Result result,
akka.stream.Materializer mat,
long timeout)
Extracts the content as a String.
|
static Application |
fakeApplication()
Build a new fake application.
|
static Application |
fakeApplication(GlobalSettings global)
Deprecated.
Use dependency injection (since 2.5.0)
|
static Application |
fakeApplication(java.util.Map<java.lang.String,? extends java.lang.Object> additionalConfiguration)
Build a new fake application.
|
static Application |
fakeApplication(java.util.Map<java.lang.String,? extends java.lang.Object> additionalConfiguration,
GlobalSettings global)
Deprecated.
Use the version without GlobalSettings (since 2.5.0)
|
static GlobalSettings |
fakeGlobal()
Deprecated.
Use dependency injection (since 2.5.0)
|
static Http.RequestBuilder |
fakeRequest()
Build a new GET / fake request.
|
static Http.RequestBuilder |
fakeRequest(Call call)
Build a new fake request corresponding to a given route call
|
static Http.RequestBuilder |
fakeRequest(java.lang.String method,
java.lang.String uri)
Build a new fake request.
|
static java.util.Map<java.lang.String,java.lang.String> |
inMemoryDatabase()
Constructs a in-memory (h2) database configuration to add to a fake application.
|
static java.util.Map<java.lang.String,java.lang.String> |
inMemoryDatabase(java.lang.String name)
Constructs a in-memory (h2) database configuration to add to a fake application.
|
static java.util.Map<java.lang.String,java.lang.String> |
inMemoryDatabase(java.lang.String name,
java.util.Map<java.lang.String,java.lang.String> options)
Constructs a in-memory (h2) database configuration to add to a fake application.
|
static <V> V |
invokeWithContext(Http.RequestBuilder requestBuilder,
java.util.concurrent.Callable<V> callable)
Calls a Callable which invokes a Controller or some other method with a Context
|
static Result |
route(Application app,
Call call) |
static Result |
route(Application app,
Call call,
long timeout) |
static Result |
route(Application app,
Http.RequestBuilder requestBuilder) |
static Result |
route(Application app,
Http.RequestBuilder requestBuilder,
long timeout) |
static Result |
route(Call call) |
static Result |
route(Call call,
long timeout) |
static Result |
route(Http.RequestBuilder requestBuilder) |
static Result |
route(Http.RequestBuilder requestBuilder,
long timeout) |
static Result |
routeAndCall(java.lang.Class<? extends Router> router,
Http.RequestBuilder requestBuilder,
long timeout) |
static Result |
routeAndCall(Http.RequestBuilder requestBuilder,
long timeout) |
static Result |
routeAndCall(Router router,
Http.RequestBuilder requestBuilder) |
static Result |
routeAndCall(Router router,
Http.RequestBuilder requestBuilder,
long timeout) |
static void |
running(Application application,
java.lang.Runnable block)
Executes a block of code in a running application.
|
static void |
running(TestServer server,
java.lang.Class<? extends org.openqa.selenium.WebDriver> webDriver,
java.util.function.Consumer<TestBrowser> block)
Executes a block of code in a running server, with a test browser.
|
static void |
running(TestServer server,
java.lang.Runnable block)
Executes a block of code in a running server.
|
static void |
running(TestServer server,
org.openqa.selenium.WebDriver webDriver,
java.util.function.Consumer<TestBrowser> block)
Executes a block of code in a running server, with a test browser.
|
static void |
start(Application application)
Starts a new application.
|
static void |
start(TestServer server)
Starts a Test server.
|
static void |
stop(Application application)
Stops an application.
|
static void |
stop(TestServer server)
Stops a Test server.
|
static TestBrowser |
testBrowser()
Creates a Test Browser.
|
static TestBrowser |
testBrowser(java.lang.Class<? extends org.openqa.selenium.WebDriver> webDriver)
Creates a Test Browser.
|
static TestBrowser |
testBrowser(java.lang.Class<? extends org.openqa.selenium.WebDriver> webDriver,
int port)
Creates a Test Browser.
|
static TestBrowser |
testBrowser(int port)
Creates a Test Browser.
|
static TestBrowser |
testBrowser(org.openqa.selenium.WebDriver of)
Creates a Test Browser.
|
static TestBrowser |
testBrowser(org.openqa.selenium.WebDriver of,
int port)
Creates a Test Browser.
|
static TestServer |
testServer()
Creates a new Test server listening on port defined by configuration setting "testserver.port" (defaults to 19001).
|
static TestServer |
testServer(Application app)
Creates a new Test server listening on port defined by configuration setting "testserver.port" (defaults to 19001) and using the given Application.
|
static TestServer |
testServer(int port)
Creates a new Test server.
|
static TestServer |
testServer(int port,
Application app)
Creates a new Test server.
|
public static java.lang.String GET
public static java.lang.String POST
public static java.lang.String PUT
public static java.lang.String DELETE
public static java.lang.String HEAD
public static java.lang.Class<? extends org.openqa.selenium.WebDriver> HTMLUNIT
public static java.lang.Class<? extends org.openqa.selenium.WebDriver> FIREFOX
public static final long DEFAULT_TIMEOUT
public static <V> V invokeWithContext(Http.RequestBuilder requestBuilder, java.util.concurrent.Callable<V> callable)
public static Http.RequestBuilder fakeRequest()
public static Http.RequestBuilder fakeRequest(java.lang.String method, java.lang.String uri)
public static Http.RequestBuilder fakeRequest(Call call)
public static Application fakeApplication()
@Deprecated public static Application fakeApplication(GlobalSettings global)
@Deprecated public static GlobalSettings fakeGlobal()
public static java.util.Map<java.lang.String,java.lang.String> inMemoryDatabase()
public static java.util.Map<java.lang.String,java.lang.String> inMemoryDatabase(java.lang.String name)
public static java.util.Map<java.lang.String,java.lang.String> inMemoryDatabase(java.lang.String name, java.util.Map<java.lang.String,java.lang.String> options)
public static Application fakeApplication(java.util.Map<java.lang.String,? extends java.lang.Object> additionalConfiguration)
@Deprecated public static Application fakeApplication(java.util.Map<java.lang.String,? extends java.lang.Object> additionalConfiguration, GlobalSettings global)
public static akka.util.ByteString contentAsBytes(Result result)
ByteString
.
This method is only capable of extracting the content of results with strict entities. To extract the content of
results with streamed entities, use contentAsBytes(Result, Materializer)
.result
- The result to extract the content from.java.lang.UnsupportedOperationException
- if the result does not have a strict entity.public static akka.util.ByteString contentAsBytes(Result result, akka.stream.Materializer mat)
ByteString
.result
- The result to extract the content from.mat
- The materializer to use to extract the body from the result stream.public static akka.util.ByteString contentAsBytes(Result result, akka.stream.Materializer mat, long timeout)
ByteString
.result
- The result to extract the content from.mat
- The materializer to use to extract the body from the result stream.timeout
- The amount of time, in milliseconds, to wait for the body to be produced.public static akka.util.ByteString contentAsBytes(play.twirl.api.Content content)
public static java.lang.String contentAsString(play.twirl.api.Content content)
public static java.lang.String contentAsString(Result result)
contentAsString(Result, Materializer)
.result
- The result to extract the content from.java.lang.UnsupportedOperationException
- if the result does not have a strict entity.public static java.lang.String contentAsString(Result result, akka.stream.Materializer mat)
result
- The result to extract the content from.mat
- The materializer to use to extract the body from the result stream.public static java.lang.String contentAsString(Result result, akka.stream.Materializer mat, long timeout)
result
- The result to extract the content from.mat
- The materializer to use to extract the body from the result stream.timeout
- The amount of time, in milliseconds, to wait for the body to be produced.public static Result routeAndCall(Http.RequestBuilder requestBuilder, long timeout)
public static Result routeAndCall(java.lang.Class<? extends Router> router, Http.RequestBuilder requestBuilder, long timeout)
public static Result routeAndCall(Router router, Http.RequestBuilder requestBuilder)
public static Result routeAndCall(Router router, Http.RequestBuilder requestBuilder, long timeout)
public static Result route(Application app, Call call)
public static Result route(Application app, Call call, long timeout)
public static Result route(Http.RequestBuilder requestBuilder)
public static Result route(Http.RequestBuilder requestBuilder, long timeout)
public static Result route(Application app, Http.RequestBuilder requestBuilder)
public static Result route(Application app, Http.RequestBuilder requestBuilder, long timeout)
public static void start(Application application)
public static void stop(Application application)
public static void running(Application application, java.lang.Runnable block)
public static TestServer testServer()
public static TestServer testServer(Application app)
public static TestServer testServer(int port)
public static TestServer testServer(int port, Application app)
public static void start(TestServer server)
public static void stop(TestServer server)
public static void running(TestServer server, java.lang.Runnable block)
public static void running(TestServer server, java.lang.Class<? extends org.openqa.selenium.WebDriver> webDriver, java.util.function.Consumer<TestBrowser> block)
public static void running(TestServer server, org.openqa.selenium.WebDriver webDriver, java.util.function.Consumer<TestBrowser> block)
public static TestBrowser testBrowser()
public static TestBrowser testBrowser(int port)
public static TestBrowser testBrowser(java.lang.Class<? extends org.openqa.selenium.WebDriver> webDriver)
public static TestBrowser testBrowser(java.lang.Class<? extends org.openqa.selenium.WebDriver> webDriver, int port)
public static TestBrowser testBrowser(org.openqa.selenium.WebDriver of, int port)
public static TestBrowser testBrowser(org.openqa.selenium.WebDriver of)