Package io.reactiverse.junit5.web
Class TestRequest
java.lang.Object
io.reactiverse.junit5.web.TestRequest
public class TestRequest extends Object
This class is a wrapper around
WebClient
that simplifies the creation of Http requests and the asserts on responses.- Author:
- Francesco Guardiani
-
Method Summary
Modifier and Type Method Description static Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
bodyResponse(io.vertx.core.buffer.Buffer expected, String expectedContentType)
static Consumer<io.vertx.ext.web.client.HttpRequest<io.vertx.core.buffer.Buffer>>
cookie(io.netty.handler.codec.http.QueryStringEncoder encoder)
static Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
emptyResponse()
TestRequest
expect(Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>... asserts)
Add one or more response asserts to the TestRequest.static Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
jsonBodyResponse(Object expected)
static Consumer<io.vertx.ext.web.client.HttpRequest<io.vertx.core.buffer.Buffer>>
queryParam(String key, String value)
static Consumer<io.vertx.ext.web.client.HttpRequest<io.vertx.core.buffer.Buffer>>
requestHeader(String key, String value)
Add an header to the requeststatic Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
responseHeader(String headerName, String headerValue)
io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
send(io.vertx.junit5.VertxTestContext testContext)
Send and complete test context withVertxTestContext.completeNow()
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
send(io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.Checkpoint checkpoint)
Send and flag the provided checkpoint withCheckpoint.flag()
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
send(io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.VertxTestContext.ExecutionBlock onEnd)
Send and executeonEnd
code block wrapped inVertxTestContext.verify(VertxTestContext.ExecutionBlock)
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
sendBuffer(io.vertx.core.buffer.Buffer buf, io.vertx.junit5.VertxTestContext testContext)
Send aBuffer
and complete test context withVertxTestContext.completeNow()
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
sendBuffer(io.vertx.core.buffer.Buffer buf, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.Checkpoint checkpoint)
Send aBuffer
and flag the provided checkpoint withCheckpoint.flag()
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
sendBuffer(io.vertx.core.buffer.Buffer buf, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.VertxTestContext.ExecutionBlock onEnd)
Send aBuffer
and executeonEnd
code block wrapped inVertxTestContext.verify(VertxTestContext.ExecutionBlock)
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
sendJson(Object json, io.vertx.junit5.VertxTestContext testContext)
Send a json and complete test context withVertxTestContext.completeNow()
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
sendJson(Object json, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.Checkpoint checkpoint)
Send a json and flag the provided checkpoint withCheckpoint.flag()
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
sendJson(Object json, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.VertxTestContext.ExecutionBlock onEnd)
Send a json and executeonEnd
code block wrapped inVertxTestContext.verify(VertxTestContext.ExecutionBlock)
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
sendMultipartForm(io.vertx.ext.web.multipart.MultipartForm form, io.vertx.junit5.VertxTestContext testContext)
Send a multipart form and complete test context withVertxTestContext.completeNow()
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
sendMultipartForm(io.vertx.ext.web.multipart.MultipartForm form, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.Checkpoint checkpoint)
Send a multipart form and flag the provided checkpoint withCheckpoint.flag()
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
sendMultipartForm(io.vertx.ext.web.multipart.MultipartForm form, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.VertxTestContext.ExecutionBlock onEnd)
Send a multipart form and executeonEnd
code block wrapped inVertxTestContext.verify(VertxTestContext.ExecutionBlock)
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
sendURLEncodedForm(io.vertx.core.MultiMap form, io.vertx.junit5.VertxTestContext testContext)
Send an URL Encoded form and complete test context withVertxTestContext.completeNow()
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
sendURLEncodedForm(io.vertx.core.MultiMap form, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.Checkpoint checkpoint)
Send an URL Encoded form and flag the provided checkpoint withCheckpoint.flag()
when request is completed and no assertion failsio.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
sendURLEncodedForm(io.vertx.core.MultiMap form, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.VertxTestContext.ExecutionBlock onEnd)
Send an URL Encoded form and executeonEnd
code block wrapped inVertxTestContext.verify(VertxTestContext.ExecutionBlock)
when request is completed and no assertion failsstatic Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
statusCode(int statusCode)
static Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>
statusMessage(String statusMessage)
static TestRequest
testRequest(io.vertx.ext.web.client.HttpRequest<io.vertx.core.buffer.Buffer> request)
WrapsHttpRequest
in a newTestRequest
static TestRequest
testRequest(io.vertx.ext.web.client.WebClient client, io.vertx.core.http.HttpMethod method, String path)
Creates a newTestRequest
object with provided client, method and pathstatic String
urlEncode(String s)
TestRequest
with(Consumer<io.vertx.ext.web.client.HttpRequest<io.vertx.core.buffer.Buffer>>... transformations)
Add one or more transformations to the TestRequest.
Note: this transformations are evaluated when one of the send methods is called
-
Method Details
-
with
@SafeVarargs public final TestRequest with(Consumer<io.vertx.ext.web.client.HttpRequest<io.vertx.core.buffer.Buffer>>... transformations)Add one or more transformations to the TestRequest.
Note: this transformations are evaluated when one of the send methods is called- Parameters:
transformations
-- Returns:
- a reference to this, so the API can be used fluently
-
expect
@SafeVarargs public final TestRequest expect(Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>>... asserts)Add one or more response asserts to the TestRequest.- Parameters:
asserts
-- Returns:
- a reference to this, so the API can be used fluently
-
send
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> send(io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.Checkpoint checkpoint)Send and flag the provided checkpoint withCheckpoint.flag()
when request is completed and no assertion fails- Parameters:
testContext
-checkpoint
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
send
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> send(io.vertx.junit5.VertxTestContext testContext)Send and complete test context withVertxTestContext.completeNow()
when request is completed and no assertion fails- Parameters:
testContext
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
send
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> send(io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.VertxTestContext.ExecutionBlock onEnd)Send and executeonEnd
code block wrapped inVertxTestContext.verify(VertxTestContext.ExecutionBlock)
when request is completed and no assertion fails- Parameters:
testContext
-onEnd
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
sendJson
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> sendJson(Object json, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.Checkpoint checkpoint)Send a json and flag the provided checkpoint withCheckpoint.flag()
when request is completed and no assertion fails- Parameters:
json
-testContext
-checkpoint
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
sendJson
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> sendJson(Object json, io.vertx.junit5.VertxTestContext testContext)Send a json and complete test context withVertxTestContext.completeNow()
when request is completed and no assertion fails- Parameters:
json
-testContext
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
sendJson
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> sendJson(Object json, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.VertxTestContext.ExecutionBlock onEnd)Send a json and executeonEnd
code block wrapped inVertxTestContext.verify(VertxTestContext.ExecutionBlock)
when request is completed and no assertion fails- Parameters:
json
-testContext
-onEnd
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
sendBuffer
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> sendBuffer(io.vertx.core.buffer.Buffer buf, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.Checkpoint checkpoint)Send aBuffer
and flag the provided checkpoint withCheckpoint.flag()
when request is completed and no assertion fails- Parameters:
buf
-testContext
-checkpoint
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
sendBuffer
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> sendBuffer(io.vertx.core.buffer.Buffer buf, io.vertx.junit5.VertxTestContext testContext)Send aBuffer
and complete test context withVertxTestContext.completeNow()
when request is completed and no assertion fails- Parameters:
buf
-testContext
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
sendBuffer
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> sendBuffer(io.vertx.core.buffer.Buffer buf, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.VertxTestContext.ExecutionBlock onEnd)Send aBuffer
and executeonEnd
code block wrapped inVertxTestContext.verify(VertxTestContext.ExecutionBlock)
when request is completed and no assertion fails- Parameters:
buf
-testContext
-onEnd
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
sendURLEncodedForm
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> sendURLEncodedForm(io.vertx.core.MultiMap form, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.Checkpoint checkpoint)Send an URL Encoded form and flag the provided checkpoint withCheckpoint.flag()
when request is completed and no assertion fails- Parameters:
form
-testContext
-checkpoint
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
sendURLEncodedForm
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> sendURLEncodedForm(io.vertx.core.MultiMap form, io.vertx.junit5.VertxTestContext testContext)Send an URL Encoded form and complete test context withVertxTestContext.completeNow()
when request is completed and no assertion fails- Parameters:
form
-testContext
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
sendURLEncodedForm
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> sendURLEncodedForm(io.vertx.core.MultiMap form, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.VertxTestContext.ExecutionBlock onEnd)Send an URL Encoded form and executeonEnd
code block wrapped inVertxTestContext.verify(VertxTestContext.ExecutionBlock)
when request is completed and no assertion fails- Parameters:
form
-testContext
-onEnd
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
sendMultipartForm
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> sendMultipartForm(io.vertx.ext.web.multipart.MultipartForm form, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.Checkpoint checkpoint)Send a multipart form and flag the provided checkpoint withCheckpoint.flag()
when request is completed and no assertion fails- Parameters:
form
-testContext
-checkpoint
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
sendMultipartForm
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> sendMultipartForm(io.vertx.ext.web.multipart.MultipartForm form, io.vertx.junit5.VertxTestContext testContext)Send a multipart form and complete test context withVertxTestContext.completeNow()
when request is completed and no assertion fails- Parameters:
form
-testContext
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
sendMultipartForm
public io.vertx.core.Future<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> sendMultipartForm(io.vertx.ext.web.multipart.MultipartForm form, io.vertx.junit5.VertxTestContext testContext, io.vertx.junit5.VertxTestContext.ExecutionBlock onEnd)Send a multipart form and executeonEnd
code block wrapped inVertxTestContext.verify(VertxTestContext.ExecutionBlock)
when request is completed and no assertion fails- Parameters:
form
-testContext
-onEnd
-- Returns:
- a future that will be completed when the response is ready and no response assertion fails
-
testRequest
public static TestRequest testRequest(io.vertx.ext.web.client.WebClient client, io.vertx.core.http.HttpMethod method, String path)Creates a newTestRequest
object with provided client, method and path- Parameters:
client
-method
-path
-- Returns:
-
testRequest
public static TestRequest testRequest(io.vertx.ext.web.client.HttpRequest<io.vertx.core.buffer.Buffer> request)WrapsHttpRequest
in a newTestRequest
- Parameters:
request
-- Returns:
-
requestHeader
public static Consumer<io.vertx.ext.web.client.HttpRequest<io.vertx.core.buffer.Buffer>> requestHeader(String key, String value)Add an header to the request- Parameters:
key
-value
-- Returns:
-
cookie
public static Consumer<io.vertx.ext.web.client.HttpRequest<io.vertx.core.buffer.Buffer>> cookie(io.netty.handler.codec.http.QueryStringEncoder encoder)- Parameters:
encoder
-- Returns:
-
queryParam
-
statusCode
public static Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> statusCode(int statusCode) -
statusMessage
-
jsonBodyResponse
-
bodyResponse
-
responseHeader
-
emptyResponse
public static Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> emptyResponse() -
urlEncode
-