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 request
    static 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 with VertxTestContext.completeNow() when request is completed and no assertion fails
    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 with Checkpoint.flag() when request is completed and no assertion fails
    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 execute onEnd code block wrapped in VertxTestContext.verify(VertxTestContext.ExecutionBlock) when request is completed and no assertion fails
    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 a Buffer and complete test context with VertxTestContext.completeNow() when request is completed and no assertion fails
    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 a Buffer and flag the provided checkpoint with Checkpoint.flag() when request is completed and no assertion fails
    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 a Buffer and execute onEnd code block wrapped in VertxTestContext.verify(VertxTestContext.ExecutionBlock) when request is completed and no assertion fails
    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 with VertxTestContext.completeNow() when request is completed and no assertion fails
    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 with Checkpoint.flag() when request is completed and no assertion fails
    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 execute onEnd code block wrapped in VertxTestContext.verify(VertxTestContext.ExecutionBlock) when request is completed and no assertion fails
    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 with VertxTestContext.completeNow() when request is completed and no assertion fails
    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 with Checkpoint.flag() when request is completed and no assertion fails
    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 execute onEnd code block wrapped in VertxTestContext.verify(VertxTestContext.ExecutionBlock) when request is completed and no assertion fails
    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 with VertxTestContext.completeNow() when request is completed and no assertion fails
    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 with Checkpoint.flag() when request is completed and no assertion fails
    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 execute onEnd code block wrapped in VertxTestContext.verify(VertxTestContext.ExecutionBlock) when request is completed and no assertion fails
    static 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)
    Wraps HttpRequest in a new TestRequest
    static TestRequest testRequest​(io.vertx.ext.web.client.WebClient client, io.vertx.core.http.HttpMethod method, String path)
    Creates a new TestRequest object with provided client, method and path
    static 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 with Checkpoint.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 with VertxTestContext.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 execute onEnd code block wrapped in VertxTestContext.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 with Checkpoint.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 with VertxTestContext.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 execute onEnd code block wrapped in VertxTestContext.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 a Buffer and flag the provided checkpoint with Checkpoint.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 a Buffer and complete test context with VertxTestContext.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 a Buffer and execute onEnd code block wrapped in VertxTestContext.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 with Checkpoint.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 with VertxTestContext.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 execute onEnd code block wrapped in VertxTestContext.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 with Checkpoint.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 with VertxTestContext.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 execute onEnd code block wrapped in VertxTestContext.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 new TestRequest 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)
      Wraps HttpRequest in a new TestRequest
      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

      public static Consumer<io.vertx.ext.web.client.HttpRequest<io.vertx.core.buffer.Buffer>> queryParam​(String key, String value)
    • statusCode

      public static Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> statusCode​(int statusCode)
    • statusMessage

      public static Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> statusMessage​(String statusMessage)
    • jsonBodyResponse

      public static Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> jsonBodyResponse​(Object expected)
    • bodyResponse

      public static Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> bodyResponse​(io.vertx.core.buffer.Buffer expected, String expectedContentType)
    • responseHeader

      public static Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> responseHeader​(String headerName, String headerValue)
    • emptyResponse

      public static Consumer<io.vertx.ext.web.client.HttpResponse<io.vertx.core.buffer.Buffer>> emptyResponse()
    • urlEncode

      public static String urlEncode​(String s)