Allows for mocking and testing usages of AsyncHttpBuilder in application code
Below is an example:
TestAsyncHttpBuilder client = new TestAsyncHttpBuilder()
client.expect {
uri '/foo/bar'
method "POST"
contentType 'application/json'
json {
title "Ping"
}
}.respond {
created()
json {
title "Pong"
}
}
Promise p = client.post("https://localhost:8080/foo/bar") {
contentType 'application/json'
json {
title "Ping"
}
}
assert client.verify()
| Modifiers | Name | Description |
|---|---|---|
static class |
TestAsyncHttpBuilder.MockResponseBuilder |
Allows construction of a mock response |
| Fields inherited from class | Fields |
|---|---|
class AsyncHttpBuilder |
bootstrap, group |
| Type | Name and description |
|---|---|
java.util.LinkedList<io.netty.handler.codec.http.HttpRequest> |
expectedRequests |
java.util.LinkedList<io.netty.handler.codec.http.HttpResponse> |
expectedResponses |
io.netty.channel.embedded.EmbeddedChannel |
mockChannel |
| Constructor and description |
|---|
TestAsyncHttpBuilder
(Configuration configuration = new DefaultConfiguration(codecClass: (Class) |
| Type | Name and description |
|---|---|
protected NettyPromise<HttpClientResponse> |
buildPromise(io.netty.util.concurrent.Promise promise) |
protected io.netty.channel.ChannelFuture |
doConnect(io.netty.bootstrap.Bootstrap bootstrap, java.lang.String host, int port) |
TestAsyncHttpBuilder.MockResponseBuilder |
expect(groovy.lang.Closure expectedRequest)Adds a new request expectation |
TestAsyncHttpBuilder |
respond(groovy.lang.Closure callable)Adds a response to be produced |
boolean |
verify()Verifies the expected requests were produced |
protected void |
verifyRequest(io.netty.handler.codec.http.HttpRequest expected, io.netty.handler.codec.http.HttpRequest actual) |
protected void |
writeResponse() |
| Methods inherited from class | Name |
|---|---|
class AsyncHttpBuilder |
buildPromise, buildSslContext, buildSslContext, delete, doConnect, doConnect, doConnect, doRequest, get, head, newPromise, options, patch, post, put |
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Adds a new request expectation
expectedRequest - The expected requestAdds a response to be produced
callable - The callable that defines the responseVerifies the expected requests were produced
Groovy Documentation