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, IM_A_TEAPOT, INSUFFICIENT_STORAGE, INTERNAL_SERVER_ERROR, LENGTH_REQUIRED, LOCKED, METHOD_NOT_ALLOWED, MOVED_PERMANENTLY, MULTI_STATUS, MULTIPLE_CHOICES, NETWORK_AUTHENTICATION_REQUIRED, NO_CONTENT, NON_AUTHORITATIVE_INFORMATION, NOT_ACCEPTABLE, NOT_FOUND, NOT_IMPLEMENTED, NOT_MODIFIED, OK, PARTIAL_CONTENT, PAYMENT_REQUIRED, PERMANENT_REDIRECT, PRECONDITION_FAILED, PRECONDITION_REQUIRED, PROXY_AUTHENTICATION_REQUIRED, REQUEST_ENTITY_TOO_LARGE, REQUEST_HEADER_FIELDS_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_SECURITY_POLICY, CONTENT_SECURITY_POLICY_REPORT_ONLY, 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, LINK, LOCATION, MAX_FORWARDS, ORIGIN, PRAGMA, PROXY_AUTHENTICATE, PROXY_AUTHORIZATION, RANGE, REFERER, REFERRER_POLICY, RETRY_AFTER, SERVER, SET_COOKIE, SET_COOKIE2, STRICT_TRANSPORT_SECURITY, TE, TRAILER, TRANSFER_ENCODING, UPGRADE, USER_AGENT, VARY, VIA, WARNING, WWW_AUTHENTICATE, X_CONTENT_SECURITY_POLICY_NONCE_HEADER, X_CONTENT_TYPE_OPTIONS, X_FORWARDED_FOR, X_FORWARDED_HOST, X_FORWARDED_PORT, X_FORWARDED_PROTO, X_FRAME_OPTIONS, X_PERMITTED_CROSS_DOMAIN_POLICIES, X_REQUESTED_WITH, X_XSS_PROTECTION
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 play.core.j.JavaContextComponents |
contextComponents()
Deprecated.
Deprecated as of 2.8.0. Inject MessagesApi, Langs, FileMimeTypes or
HttpConfiguration instead
|
static Application |
fakeApplication()
Builds a new fake application, using GuiceApplicationBuilder.
|
static Application |
fakeApplication(java.util.Map<java.lang.String,?> additionalConfiguration)
Build a new fake application.
|
static Http.RequestBuilder |
fakeRequest()
Builds a new "GET /" fake request.
|
static Http.RequestBuilder |
fakeRequest(Call call)
Builds a new fake request corresponding to a given route call.
|
static Http.RequestBuilder |
fakeRequest(java.lang.String method,
java.lang.String uri)
Builds 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 Result |
route(Application app,
Call call)
Route a call using the given application.
|
static Result |
route(Application app,
Call call,
long timeout)
Route a call using the given application and timeout.
|
static Result |
route(Application app,
Http.RequestBuilder requestBuilder)
Route a request.
|
static Result |
route(Application app,
Http.RequestBuilder requestBuilder,
long timeout)
Route the request considering the given timeout.
|
static Result |
routeAndCall(Application app,
java.lang.Class<? extends Router> router,
Http.RequestBuilder requestBuilder,
long timeout)
Route and call the request, respecting the given timeout.
|
static Result |
routeAndCall(Application app,
Http.RequestBuilder requestBuilder,
long timeout)
Route and call the request, respecting the given timeout.
|
static Result |
routeAndCall(Application app,
Router router,
Http.RequestBuilder requestBuilder)
Route and call the request.
|
static Result |
routeAndCall(Application app,
Router router,
Http.RequestBuilder requestBuilder,
long timeout)
Route and call the request, respecting the given 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 MessagesApi |
stubMessagesApi()
Constructs an empty messagesApi instance.
|
static MessagesApi |
stubMessagesApi(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> messages,
Langs langs)
Constructs a MessagesApi instance containing the given keys and values.
|
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.
|
static TestServer |
testServer(int port,
int sslPort)
Creates a new Test server.
|
public static final long DEFAULT_TIMEOUT
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 Http.RequestBuilder fakeRequest()
public static Http.RequestBuilder fakeRequest(java.lang.String method, java.lang.String uri)
method
- the request method.uri
- the relative URL.public static Http.RequestBuilder fakeRequest(Call call)
call
- the route call.@Deprecated public static play.core.j.JavaContextComponents contextComponents()
public static Application fakeApplication()
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)
name
- the database 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)
name
- the database name.options
- the database options.public static MessagesApi stubMessagesApi()
public static MessagesApi stubMessagesApi(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> messages, Langs langs)
public static Application fakeApplication(java.util.Map<java.lang.String,?> additionalConfiguration)
additionalConfiguration
- map containing config info for the app.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)
content
- the content to be turned into bytes.public static java.lang.String contentAsString(play.twirl.api.Content content)
content
- the content.public static java.lang.String contentAsString(Result result)
This method is only capable of extracting the content of results with strict entities. To
extract the content of results with streamed entities, use 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(Application app, Http.RequestBuilder requestBuilder, long timeout)
app
- The application used while routing and executing the requestrequestBuilder
- The request buildertimeout
- The amount of time, in milliseconds, to wait for the body to be produced.public static Result routeAndCall(Application app, java.lang.Class<? extends Router> router, Http.RequestBuilder requestBuilder, long timeout)
app
- The application used while routing and executing the requestrouter
- The router typerequestBuilder
- The request buildertimeout
- The amount of time, in milliseconds, to wait for the body to be produced.public static Result routeAndCall(Application app, Router router, Http.RequestBuilder requestBuilder)
app
- The application used while routing and executing the requestrouter
- The routerrequestBuilder
- The request builderpublic static Result routeAndCall(Application app, Router router, Http.RequestBuilder requestBuilder, long timeout)
app
- The application used while routing and executing the requestrouter
- The routerrequestBuilder
- The request buildertimeout
- The amount of time, in milliseconds, to wait for the body to be produced.public static Result route(Application app, Call call)
app
- the applicationcall
- the call to routeGuiceApplicationBuilder
public static Result route(Application app, Call call, long timeout)
app
- the applicationcall
- the call to routetimeout
- the time outGuiceApplicationBuilder
public static Result route(Application app, Http.RequestBuilder requestBuilder)
app
- The application used while routing and executing the requestrequestBuilder
- the request builderpublic static Result route(Application app, Http.RequestBuilder requestBuilder, long timeout)
app
- The application used while routing and executing the requestrequestBuilder
- the request buildertimeout
- the amount of time, in milliseconds, to wait for the body to be produced.public static void start(Application application)
application
- the application to start.public static void stop(Application application)
application
- the application to stop.public static void running(Application application, java.lang.Runnable block)
application
- the application context.block
- the block to run after the Play app is started.public static TestServer testServer()
public static TestServer testServer(Application app)
app
- the application.public static TestServer testServer(int port)
port
- the port to run the server on.public static TestServer testServer(int port, int sslPort)
port
- the port to run the server on.sslPort
- the port to run the server on.public static TestServer testServer(int port, Application app)
port
- the port to run the server on.app
- the Play application.public static void start(TestServer server)
server
- the test server to start.public static void stop(TestServer server)
server
- the test server to stop.apublic static void running(TestServer server, java.lang.Runnable block)
server
- the server to start.block
- the block of code to run after the server starts.public static void running(TestServer server, java.lang.Class<? extends org.openqa.selenium.WebDriver> webDriver, java.util.function.Consumer<TestBrowser> block)
server
- the test server.webDriver
- the web driver class.block
- the block of code to execute.public static void running(TestServer server, org.openqa.selenium.WebDriver webDriver, java.util.function.Consumer<TestBrowser> block)
server
- the test server.webDriver
- the web driver instance.block
- the block of code to execute.public static TestBrowser testBrowser()
public static TestBrowser testBrowser(int port)
port
- the local port.public static TestBrowser testBrowser(java.lang.Class<? extends org.openqa.selenium.WebDriver> webDriver)
webDriver
- the class of webdriver.public static TestBrowser testBrowser(java.lang.Class<? extends org.openqa.selenium.WebDriver> webDriver, int port)
webDriver
- the class of webdriver.port
- the local port to test against.public static TestBrowser testBrowser(org.openqa.selenium.WebDriver of, int port)
of
- the web driver to run the browser with.port
- the port to run against http://localhostpublic static TestBrowser testBrowser(org.openqa.selenium.WebDriver of)
of
- the web driver to run the browser with.