public abstract class GroovyUnitTest extends Object
| Modifier and Type | Method and Description |
|---|---|
static HandlingResult |
handle(Action<? super Chain> handlers,
Closure<?> closure)
Unit test a chain of
handlers. |
static HandlingResult |
handle(Handler handler,
Closure<?> closure)
Unit test a
Handler. |
static GroovyRequestFixture |
requestFixture()
Create a Groovy request fixture, for unit testing a
Handler. |
static GroovyRequestFixture |
requestFixture(RequestFixture requestFixture)
Create a Groovy request fixture, for unit testing a
Handler, by wrapping the given RequestFixture. |
public static HandlingResult handle(Handler handler, @DelegatesTo(value=GroovyRequestFixture.class) Closure<?> closure) throws HandlerTimeoutException
Handler.
Example:
import ratpack.groovy.handling.GroovyHandler
import ratpack.groovy.handling.GroovyContext
import ratpack.groovy.test.GroovyUnitTest
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 = GroovyUnitTest.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 fixtureHandlerTimeoutException - if the handler takes more than RequestFixture.timeout(int) seconds to send a response or call next() on the contextpublic static HandlingResult handle(Action<? super Chain> handlers, @DelegatesTo(value=GroovyRequestFixture.class) Closure<?> closure) throws HandlerTimeoutException
handlers.
Example:
import ratpack.groovy.handling.GroovyChainAction
import ratpack.groovy.test.GroovyUnitTest
class MyHandlers extends GroovyChainAction {
protected void execute() {
handler {
def outputHeaderValue = request.headers.get("input-value") + ":bar"
response.headers.set("output-value", outputHeaderValue)
next()
}
handler {
render "received: " + request.path
}
}
}
def result = GroovyUnitTest.handle(new MyHandlers()) {
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 fixtureHandlerTimeoutException - if the handler takes more than RequestFixture.timeout(int) seconds to send a response or call next() on the contextpublic static GroovyRequestFixture requestFixture()
Handler.public static GroovyRequestFixture requestFixture(RequestFixture requestFixture)
Handler, by wrapping the given RequestFixture.