Class Helpers
- All Implemented Interfaces:
Http.HeaderNames,Http.Status
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault Timeout (milliseconds) for fake requests issued by these Helpers.static Stringstatic Class<? extends org.openqa.selenium.WebDriver>static Stringstatic Stringstatic Class<? extends org.openqa.selenium.WebDriver>static Stringstatic StringFields inherited from interface play.mvc.Http.HeaderNames
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_PROTECTIONFields inherited from interface play.mvc.Http.Status
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ByteStringcontentAsBytes(Result result) Extracts the content as aByteString.static ByteStringcontentAsBytes(Result result, Materializer mat) Extracts the content as aByteString.static ByteStringcontentAsBytes(Result result, Materializer mat, long timeout) Extracts the content as aByteString.static ByteStringcontentAsBytes(play.twirl.api.Content content) Extracts the content as bytes.static StringcontentAsString(Result result) Extracts the content as a String.static StringcontentAsString(Result result, Materializer mat) Extracts the content as a String.static StringcontentAsString(Result result, Materializer mat, long timeout) Extracts the content as a String.static StringcontentAsString(play.twirl.api.Content content) Extracts the content as a String.static play.core.j.JavaContextComponentsDeprecated.Deprecated as of 2.8.0.static ApplicationBuilds a new fake application, using GuiceApplicationBuilder.static ApplicationfakeApplication(Map<String, ?> additionalConfiguration) Build a new fake application.static Http.RequestBuilderBuilds a new "GET /" fake request.static Http.RequestBuilderfakeRequest(String method, String uri) Builds a new fake request.static Http.RequestBuilderfakeRequest(Call call) Builds a new fake request corresponding to a given route call.Constructs a in-memory (h2) database configuration to add to a fake application.inMemoryDatabase(String name) Constructs a in-memory (h2) database configuration to add to a fake application.inMemoryDatabase(String name, Map<String, String> options) Constructs a in-memory (h2) database configuration to add to a fake application.static Resultroute(Application app, Call call) Route a call using the given application.static Resultroute(Application app, Call call, long timeout) Route a call using the given application and timeout.static Resultroute(Application app, Http.RequestBuilder requestBuilder) Route a request.static Resultroute(Application app, Http.RequestBuilder requestBuilder, long timeout) Route the request considering the given timeout.static ResultrouteAndCall(Application app, Router router, Http.RequestBuilder requestBuilder) Route and call the request.static ResultrouteAndCall(Application app, Router router, Http.RequestBuilder requestBuilder, long timeout) Route and call the request, respecting the given timeout.static voidrunning(Application application, Runnable block) Executes a block of code in a running application.static voidrunning(TestServer server, Class<? extends org.openqa.selenium.WebDriver> webDriver, Consumer<TestBrowser> block) Executes a block of code in a running server, with a test browser.static voidrunning(TestServer server, Runnable block) Executes a block of code in a running server.static voidrunning(TestServer server, org.openqa.selenium.WebDriver webDriver, Consumer<TestBrowser> block) Executes a block of code in a running server, with a test browser.static voidstart(Application application) Starts a new application.static voidstart(TestServer server) Starts a Test server.static voidstop(Application application) Stops an application.static voidstop(TestServer server) Stops a Test server.static MessagesApiConstructs an empty messagesApi instance.static MessagesApiConstructs a MessagesApi instance containing the given keys and values.static TestBrowserCreates a Test Browser.static TestBrowsertestBrowser(int port) Creates a Test Browser.static TestBrowsertestBrowser(Class<? extends org.openqa.selenium.WebDriver> webDriver) Creates a Test Browser.static TestBrowsertestBrowser(Class<? extends org.openqa.selenium.WebDriver> webDriver, int port) Creates a Test Browser.static TestBrowsertestBrowser(org.openqa.selenium.WebDriver of) Creates a Test Browser.static TestBrowsertestBrowser(org.openqa.selenium.WebDriver of, int port) Creates a Test Browser.static TestServerCreates a new Test server listening on port defined by configuration setting "testserver.port" (defaults to a random port).static TestServertestServer(int port) Creates a new Test server.static TestServertestServer(int port, int sslPort) Creates a new Test server.static TestServertestServer(int port, Application app) Creates a new Test server.static TestServertestServer(Application app) Creates a new Test server listening on port defined by configuration setting "testserver.port" (defaults to a random port) and using the given Application.
-
Field Details
-
DEFAULT_TIMEOUT
public static final long DEFAULT_TIMEOUTDefault Timeout (milliseconds) for fake requests issued by these Helpers. This value is determined from System property test.timeout. The default value is 30000 (30 seconds). -
GET
-
POST
-
PUT
-
DELETE
-
HEAD
-
HTMLUNIT
-
FIREFOX
-
-
Constructor Details
-
Helpers
public Helpers()
-
-
Method Details
-
fakeRequest
Builds a new "GET /" fake request.- Returns:
- the request builder.
-
fakeRequest
Builds a new fake request.- Parameters:
method- the request method.uri- the relative URL.- Returns:
- the request builder.
-
fakeRequest
Builds a new fake request corresponding to a given route call.- Parameters:
call- the route call.- Returns:
- the request builder.
-
contextComponents
Deprecated.Deprecated as of 2.8.0. Inject MessagesApi, Langs, FileMimeTypes or HttpConfiguration insteadCreates a new JavaContextComponents using play.api.Configuration.reference and play.api.Environment.simple as defaults- Returns:
- the newly created JavaContextComponents
-
fakeApplication
Builds a new fake application, using GuiceApplicationBuilder.- Returns:
- an application from the current path with no additional configuration.
-
inMemoryDatabase
Constructs a in-memory (h2) database configuration to add to a fake application.- Returns:
- a map of String containing database config info.
-
inMemoryDatabase
Constructs a in-memory (h2) database configuration to add to a fake application.- Parameters:
name- the database name.- Returns:
- a map of String containing database config info.
-
inMemoryDatabase
Constructs a in-memory (h2) database configuration to add to a fake application.- Parameters:
name- the database name.options- the database options.- Returns:
- a map of String containing database config info.
-
stubMessagesApi
Constructs an empty messagesApi instance.- Returns:
- a messagesApi instance containing no values.
-
stubMessagesApi
Constructs a MessagesApi instance containing the given keys and values.- Returns:
- a messagesApi instance containing given keys and values.
-
fakeApplication
Build a new fake application. Uses GuiceApplicationBuilder.- Parameters:
additionalConfiguration- map containing config info for the app.- Returns:
- an application from the current path with additional configuration.
-
contentAsBytes
Extracts the content as aByteString.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).- Parameters:
result- The result to extract the content from.- Returns:
- The content of the result as a ByteString.
- Throws:
UnsupportedOperationException- if the result does not have a strict entity.
-
contentAsBytes
Extracts the content as aByteString.- Parameters:
result- The result to extract the content from.mat- The materializer to use to extract the body from the result stream.- Returns:
- The content of the result as a ByteString.
-
contentAsBytes
Extracts the content as aByteString.- Parameters:
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.- Returns:
- The content of the result as a ByteString.
-
contentAsBytes
Extracts the content as bytes.- Parameters:
content- the content to be turned into bytes.- Returns:
- the body of the content as a byte string.
-
contentAsString
Extracts the content as a String.- Parameters:
content- the content.- Returns:
- the body of the content as a String.
-
contentAsString
Extracts the content as a String.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).- Parameters:
result- The result to extract the content from.- Returns:
- The content of the result as a String.
- Throws:
UnsupportedOperationException- if the result does not have a strict entity.
-
contentAsString
Extracts the content as a String.- Parameters:
result- The result to extract the content from.mat- The materializer to use to extract the body from the result stream.- Returns:
- The content of the result as a String.
-
contentAsString
Extracts the content as a String.- Parameters:
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.- Returns:
- The content of the result as a String.
-
routeAndCall
public static Result routeAndCall(Application app, Router router, Http.RequestBuilder requestBuilder) Route and call the request.- Parameters:
app- The application used while routing and executing the requestrouter- The routerrequestBuilder- The request builder- Returns:
- the result
-
routeAndCall
public static Result routeAndCall(Application app, Router router, Http.RequestBuilder requestBuilder, long timeout) Route and call the request, respecting the given timeout.- Parameters:
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.- Returns:
- the result
-
route
Route a call using the given application.- Parameters:
app- the applicationcall- the call to route- Returns:
- the result
- See Also:
-
route
Route a call using the given application and timeout.- Parameters:
app- the applicationcall- the call to routetimeout- the time out- Returns:
- the result
- See Also:
-
route
Route a request.- Parameters:
app- The application used while routing and executing the requestrequestBuilder- the request builder- Returns:
- the result.
-
route
Route the request considering the given timeout.- Parameters:
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.- Returns:
- the result
-
start
Starts a new application.- Parameters:
application- the application to start.
-
stop
Stops an application.- Parameters:
application- the application to stop.
-
running
Executes a block of code in a running application.- Parameters:
application- the application context.block- the block to run after the Play app is started.
-
testServer
Creates a new Test server listening on port defined by configuration setting "testserver.port" (defaults to a random port).- Returns:
- the test server.
-
testServer
Creates a new Test server listening on port defined by configuration setting "testserver.port" (defaults to a random port) and using the given Application.- Parameters:
app- the application.- Returns:
- the test server.
-
testServer
Creates a new Test server.- Parameters:
port- the port to run the server on.- Returns:
- the test server.
-
testServer
Creates a new Test server.- Parameters:
port- the port to run the server on.sslPort- the port to run the server on.- Returns:
- the test server.
-
testServer
Creates a new Test server.- Parameters:
port- the port to run the server on.app- the Play application.- Returns:
- the test server.
-
start
Starts a Test server.- Parameters:
server- the test server to start.
-
stop
Stops a Test server.- Parameters:
server- the test server to stop.a
-
running
Executes a block of code in a running server.- Parameters:
server- the server to start.block- the block of code to run after the server starts.
-
running
public static void running(TestServer server, Class<? extends org.openqa.selenium.WebDriver> webDriver, Consumer<TestBrowser> block) Executes a block of code in a running server, with a test browser.- Parameters:
server- the test server.webDriver- the web driver class.block- the block of code to execute.
-
running
public static void running(TestServer server, org.openqa.selenium.WebDriver webDriver, Consumer<TestBrowser> block) Executes a block of code in a running server, with a test browser.- Parameters:
server- the test server.webDriver- the web driver instance.block- the block of code to execute.
-
testBrowser
Creates a Test Browser.Be aware: If set, the port the test browser is using is defined by the system property "testserver.port". Starting with Play 2.9, if this property is not set, the port by default is 0, which means the operating system will assign a random port. Thus, you should only use this method here if you did explicitly set the "testserver.port" property, otherwise you should use the testBrowser(port) method (which takes a port param).
- Returns:
- the test browser.
-
testBrowser
Creates a Test Browser.- Parameters:
port- the local port.- Returns:
- the test browser.
-
testBrowser
Creates a Test Browser.Be aware: If set, the port the test browser is using is defined by the system property "testserver.port". Starting with Play 2.9, if this property is not set, the port by default is 0, which means the operating system will assign a random port. Thus, you should only use this method here if you did explicitly set the "testserver.port" property, otherwise you should use the testBrowser(webDriver, port) method (which takes a port param).
- Parameters:
webDriver- the class of webdriver.- Returns:
- the test browser.
-
testBrowser
public static TestBrowser testBrowser(Class<? extends org.openqa.selenium.WebDriver> webDriver, int port) Creates a Test Browser.- Parameters:
webDriver- the class of webdriver.port- the local port to test against.- Returns:
- the test browser.
-
testBrowser
Creates a Test Browser.- Parameters:
of- the web driver to run the browser with.port- the port to run against http://localhost- Returns:
- the test browser.
-
testBrowser
Creates a Test Browser.Be aware: If set, the port the test browser is using is defined by the system property "testserver.port". Starting with Play 2.9, if this property is not set, the port by default is 0, which means the operating system will assign a random port. Thus, you should only use this method here if you did explicitly set the "testserver.port" property, otherwise you should use the testBrowser(of, port) method (which takes a port param).
- Parameters:
of- the web driver to run the browser with.- Returns:
- the test browser.
-