public interface GroovyRequestFixture
extends ratpack.test.handling.RequestFixture
RequestFixture.| Modifier and Type | Method and Description |
|---|---|
GroovyRequestFixture |
body(byte[] bytes,
java.lang.String contentType) |
GroovyRequestFixture |
body(java.lang.String text,
java.lang.String contentType) |
static ratpack.test.handling.HandlingResult |
handle(ratpack.func.Action<? super ratpack.handling.Chain> handlers,
groovy.lang.Closure<?> closure)
Unit test a chain of
handlers. |
static ratpack.test.handling.HandlingResult |
handle(ratpack.handling.Handler handler,
groovy.lang.Closure<?> closure)
Unit test a
Handler. |
GroovyRequestFixture |
header(java.lang.CharSequence name,
java.lang.String value) |
GroovyRequestFixture |
localAddress(com.google.common.net.HostAndPort local) |
GroovyRequestFixture |
method(java.lang.String method) |
GroovyRequestFixture |
pathBinding(java.util.Map<java.lang.String,java.lang.String> pathTokens) |
GroovyRequestFixture |
pathBinding(java.lang.String boundTo,
java.lang.String pastBinding,
java.util.Map<java.lang.String,java.lang.String> pathTokens) |
GroovyRequestFixture |
registry(ratpack.func.Action<? super ratpack.registry.RegistrySpec> action) |
GroovyRequestFixture |
registry(groovy.lang.Closure<?> closure)
A closure friendly overload of
registry(Action). |
GroovyRequestFixture |
remoteAddress(com.google.common.net.HostAndPort remote) |
static GroovyRequestFixture |
requestFixture()
Create a Groovy request fixture, for unit testing a
Handler. |
static GroovyRequestFixture |
requestFixture(ratpack.test.handling.RequestFixture requestFixture)
Create a Groovy request fixture, for unit testing a
Handler, by wrapping the given RequestFixture. |
GroovyRequestFixture |
responseHeader(java.lang.CharSequence name,
java.lang.String value) |
GroovyRequestFixture |
serverConfig(ratpack.func.Action<? super ratpack.server.ServerConfigBuilder> action) |
GroovyRequestFixture |
timeout(int timeoutSeconds) |
GroovyRequestFixture |
uri(java.lang.String uri) |
static ratpack.test.handling.HandlingResult handle(ratpack.handling.Handler handler,
@DelegatesTo(value=GroovyRequestFixture.class)
groovy.lang.Closure<?> closure)
throws java.lang.Exception
Handler.
Example:
import ratpack.groovy.handling.GroovyHandler
import ratpack.groovy.handling.GroovyContext
import ratpack.groovy.test.handling.GroovyRequestFixture
class MyHandler extends GroovyHandler {
void handle(GroovyContext context) {
context.with {
def outputHeaderValue = request.headers.get("input-value") + ":bar"
response.headers.set("output-value", outputHeaderValue)
render "received: " + request.path
}
}
}
def result = GroovyRequestFixture.handle(new MyHandler()) {
header "input-value", "foo"
uri "some/path"
}
assert result.rendered(String) == "received: some/path"
assert result.headers.get("output-value") == "foo:bar"
handler - the handler to testclosure - the configuration of the request fixtureratpack.test.handling.HandlerTimeoutException - if the handler takes more than RequestFixture.timeout(int) seconds to send a response or call next() on the contextjava.lang.Exception - any thrown by closurestatic ratpack.test.handling.HandlingResult handle(ratpack.func.Action<? super ratpack.handling.Chain> handlers,
@DelegatesTo(value=GroovyRequestFixture.class)
groovy.lang.Closure<?> closure)
throws java.lang.Exception
handlers.
Example:
import ratpack.groovy.test.handling.GroovyRequestFixture
import ratpack.groovy.Groovy
def handlers = Groovy.chain {
all {
def outputHeaderValue = request.headers.get("input-value") + ":bar"
response.headers.set("output-value", outputHeaderValue)
next()
}
all {
render "received: " + request.path
}
}
def result = GroovyRequestFixture.handle(handlers) {
header "input-value", "foo"
uri "some/path"
}
assert result.rendered(String) == "received: some/path"
assert result.headers.get("output-value") == "foo:bar"
handlers - the handlers to testclosure - the configuration of the request fixtureratpack.test.handling.HandlerTimeoutException - if the handler takes more than RequestFixture.timeout(int) seconds to send a response or call next() on the contextjava.lang.Exception - any thrown by closurestatic GroovyRequestFixture requestFixture()
Handler.requestFixture in interface ratpack.test.handling.RequestFixturestatic GroovyRequestFixture requestFixture(ratpack.test.handling.RequestFixture requestFixture)
Handler, by wrapping the given RequestFixture.requestFixture - The request fixture to wrapGroovyRequestFixture registry(@DelegatesTo(value=ratpack.registry.RegistryBuilder.class,strategy=1) groovy.lang.Closure<?> closure)
registry(Action).closure - the registry configurationregistry(Action)GroovyRequestFixture header(java.lang.CharSequence name, java.lang.String value)
header in interface ratpack.test.handling.RequestFixtureGroovyRequestFixture body(byte[] bytes, java.lang.String contentType)
body in interface ratpack.test.handling.RequestFixtureGroovyRequestFixture body(java.lang.String text, java.lang.String contentType)
body in interface ratpack.test.handling.RequestFixtureGroovyRequestFixture responseHeader(java.lang.CharSequence name, java.lang.String value)
responseHeader in interface ratpack.test.handling.RequestFixtureGroovyRequestFixture method(java.lang.String method)
method in interface ratpack.test.handling.RequestFixtureGroovyRequestFixture uri(java.lang.String uri)
uri in interface ratpack.test.handling.RequestFixtureGroovyRequestFixture timeout(int timeoutSeconds)
timeout in interface ratpack.test.handling.RequestFixtureGroovyRequestFixture registry(ratpack.func.Action<? super ratpack.registry.RegistrySpec> action) throws java.lang.Exception
registry in interface ratpack.test.handling.RequestFixturejava.lang.ExceptionGroovyRequestFixture pathBinding(java.util.Map<java.lang.String,java.lang.String> pathTokens)
pathBinding in interface ratpack.test.handling.RequestFixtureGroovyRequestFixture pathBinding(java.lang.String boundTo, java.lang.String pastBinding, java.util.Map<java.lang.String,java.lang.String> pathTokens)
pathBinding in interface ratpack.test.handling.RequestFixtureGroovyRequestFixture serverConfig(ratpack.func.Action<? super ratpack.server.ServerConfigBuilder> action) throws java.lang.Exception
serverConfig in interface ratpack.test.handling.RequestFixturejava.lang.ExceptionGroovyRequestFixture remoteAddress(com.google.common.net.HostAndPort remote)
remoteAddress in interface ratpack.test.handling.RequestFixtureGroovyRequestFixture localAddress(com.google.common.net.HostAndPort local)
localAddress in interface ratpack.test.handling.RequestFixture