public abstract class GroovyUnitTest extends Object
| Constructor and Description |
|---|
GroovyUnitTest() |
| Modifier and Type | Method and Description |
|---|---|
static GroovyInvocationBuilder |
invocationBuilder()
Create a Groovy invocation builder, for unit testing a
Handler. |
static GroovyInvocationBuilder |
invocationBuilder(InvocationBuilder invocationBuilder)
Create a Groovy invocation builder, for unit testing a
Handler, by wrapping the given InvocationBuilder. |
static Invocation |
invoke(Handler handler,
Closure<?> closure)
Unit test a
Handler. |
public static Invocation invoke(Handler handler, @DelegatesTo(value=GroovyInvocationBuilder.class) Closure<?> closure) throws InvocationTimeoutException
Handler.
Example:
import ratpack.handling.*
import static ratpack.groovy.test.GroovyUnitTest.invoke
class MyHandler implements Handler {
void handle(Context context) {
context.with {
def outputHeaderValue = request.headers.get("input-value") + ":bar"
response.headers.set("output-value", outputHeaderValue)
render "received: " + request.path
}
}
}
// The following code unit tests MyHandler, typically it would be written inside a test framework.
def invocation = invoke(new MyHandler()) {
header "input-value", "foo"
uri "some/path"
}
assert invocation.rendered(String) == "received: some/path"
assert invocation.headers.get("output-value") == "foo:bar"
handler - The handler to unit testclosure - The closure that configures the invocation builderInvocationTimeoutException - if the handler takes more than InvocationBuilder.timeout(int) seconds to send a response or call next() on the contextpublic static GroovyInvocationBuilder invocationBuilder()
Handler.public static GroovyInvocationBuilder invocationBuilder(InvocationBuilder invocationBuilder)
Handler, by wrapping the given InvocationBuilder.