public abstract class RequestFixtureAction extends Object implements Action<RequestFixture>, RequestFixture
RequestFixture configuration actions.execute()| Constructor and Description |
|---|
RequestFixtureAction() |
| Modifier and Type | Method and Description |
|---|---|
RequestFixture |
body(byte[] bytes,
String contentType)
Sets the request body to be the given bytes, and adds a
Content-Type request header of the given value. |
RequestFixture |
body(String text,
String contentType)
Sets the request body to be the given string in utf8 bytes, and adds a
Content-Type request header of the given value. |
protected abstract void |
execute()
Implementations can naturally use the
RequestFixture DSL for the duration of this method. |
void |
execute(RequestFixture requestFixture)
Delegates to
execute(), using the given requestFixture for delegation. |
RegistrySpec |
getRegistry()
A specification of the context registry.
|
protected RequestFixture |
getRequestFixture() |
HandlingResult |
handle(Action<? super Chain> chainAction)
Similar to
RequestFixture.handle(ratpack.handling.Handler), but for testing a handler chain. |
HandlingResult |
handle(Handler handler)
Invokes the given handler with a newly created
Context based on the state of this fixture. |
RequestFixture |
header(String name,
String value)
Set a request header value.
|
RequestFixture |
launchConfig(Action<? super LaunchConfigBuilder> action)
Configures the launch config to have no base dir and given configuration.
|
RequestFixture |
launchConfig(Path baseDir,
Action<? super LaunchConfigBuilder> action)
Configures the launch config to have the given base dir and given configuration.
|
RequestFixture |
method(String method)
Set the request method (case insensitive).
|
RequestFixture |
pathBinding(Map<String,String> pathTokens)
Adds a path binding, with the given path tokens.
|
RequestFixture |
pathBinding(String boundTo,
String pastBinding,
Map<String,String> pathTokens)
Adds a path binding, with the given path tokens and parts.
|
RequestFixture |
registry(Action<? super RegistrySpec> action)
Configures the context registry.
|
RequestFixture |
responseHeader(String name,
String value)
Set a response header value.
|
RequestFixture |
timeout(int timeoutSeconds)
Sets the maximum time to allow the handler under test to produce a result.
|
RequestFixture |
uri(String uri)
The URI of the request.
|
public RequestFixture body(byte[] bytes, String contentType)
Content-Type request header of the given value.
By default the body is empty.
body in interface RequestFixturebytes - the request body in bytescontentType - the content type of the request bodypublic RequestFixture body(String text, String contentType)
Content-Type request header of the given value.
By default the body is empty.
body in interface RequestFixturetext - the request body as a stringcontentType - the content type of the request bodypublic RegistrySpec getRegistry()
Can be used to make objects (e.g. support services) available via context registry lookup.
By default, only a ServerErrorHandler and ClientErrorHandler are in the context registry.
getRegistry in interface RequestFixturepublic HandlingResult handle(Handler handler) throws HandlerTimeoutException
Context based on the state of this fixture.
The return value can be used to examine the effective result of the handler.
A result may be one of the following:
Response.send() methodsContext.render(Object)Context.clientError(int)Context.error(Exception)Context.next() methodsinserted by the handler under test will be invoked.
If the last inserted handler delegates to the next handler, the handling will terminate with a result indicating that the effective result was delegating to the next handler.
This method blocks until a result is achieved, even if the handler performs an asynchronous operation (such as performing blocking IO).
As such, a time limit on the execution is imposed which by default is 5 seconds.
The time limit can be changed via the RequestFixture.timeout(int) method.
If the time limit is reached, a HandlerTimeoutException is thrown.
handle in interface RequestFixturehandler - the handler to testHandlerTimeoutException - if the handler does not produce a result in the time limit defined by this fixturepublic HandlingResult handle(Action<? super Chain> chainAction) throws HandlerTimeoutException
RequestFixture.handle(ratpack.handling.Handler), but for testing a handler chain.handle in interface RequestFixturechainAction - the handler chain to testHandlerTimeoutException - if the handler does not produce a result in the time limit defined by this fixturepublic RequestFixture header(String name, String value)
By default there are no request headers.
header in interface RequestFixturename - the header namevalue - the header valuepublic RequestFixture launchConfig(Path baseDir, Action<? super LaunchConfigBuilder> action) throws Exception
By default the launch config is equivalent to LaunchConfigBuilder.noBaseDir().build().
launchConfig in interface RequestFixturebaseDir - the launch config base diraction - configuration of the launch configException - any thrown by actionpublic RequestFixture launchConfig(Action<? super LaunchConfigBuilder> action) throws Exception
By default the launch config is equivalent to LaunchConfigBuilder.noBaseDir().build().
launchConfig in interface RequestFixtureaction - configuration of the launch configException - any thrown by actionpublic RequestFixture method(String method)
The default method is "GET".
method in interface RequestFixturemethod - the request methodpublic RequestFixture pathBinding(Map<String,String> pathTokens)
By default, there are no path tokens and no path binding.
pathBinding in interface RequestFixturepathTokens - the path tokens to make available to the handler(s) under testpublic RequestFixture pathBinding(String boundTo, String pastBinding, Map<String,String> pathTokens)
By default, there are no path tokens and no path binding.
pathBinding in interface RequestFixturepathTokens - the path tokens and binding to make available to the handler(s) under testpublic RequestFixture registry(Action<? super RegistrySpec> action) throws Exception
registry in interface RequestFixtureaction - a registry specification actionException - any thrown by actionpublic RequestFixture responseHeader(String name, String value)
Can be used to simulate the setting of a response header by an upstream handler.
By default there are no request headers.
responseHeader in interface RequestFixturename - the header namevalue - the header valuepublic RequestFixture timeout(int timeoutSeconds)
As handlers may execute asynchronously, a maximum time limit must be used to guard against never ending handlers.
timeout in interface RequestFixturetimeoutSeconds - the maximum number of seconds to allow the handler(s) under test to produce a resultpublic RequestFixture uri(String uri)
No encoding is performed on the given value. It is expected to be a well formed URI path string (potentially including query and fragment strings)
uri in interface RequestFixtureuri - the URI of the requestpublic final void execute(RequestFixture requestFixture) throws Exception
execute(), using the given requestFixture for delegation.execute in interface Action<RequestFixture>requestFixture - the request fixture to configureException - Any thrown by execute()protected abstract void execute()
throws Exception
RequestFixture DSL for the duration of this method.Exception - and exception thrown while configuring the request fixtureprotected RequestFixture getRequestFixture() throws IllegalStateException
IllegalStateException