Class JSONMockServerDSL

  • All Implemented Interfaces:
    org.springframework.test.web.client.ResponseCreator

    
    public final class JSONMockServerDSL
     implements ResponseCreator
                        

    DSL class to configure mock requests to a JSONMockServer (wrapper class for Spring's MockRestServiceServer).

    • Constructor Detail

      • JSONMockServerDSL

        JSONMockServerDSL(JSONConfig config)
    • Method Detail

      • requestTo

         final Unit requestTo(URI expectedURI)

        Match the URI against another URI.

      • requestTo

        @Deprecated(message = "The use of Matcher will be removed in a future version", replaceWith = @ReplaceWith(imports = {}, expression = "requestTo { test(it) }")) final Unit requestTo(Matcher<in String> matcher)

        Match the URI using a Matcher.

      • method

         final Unit method(HttpMethod method)

        Match the method.

      • queryParam

         final Unit queryParam(String name, String expectedValues)

        Match a query parameter. A query parameter with multiple values will be matched against a set of values.

      • header

         final Unit header(String name, String expectedValues)

        Match a request header. A header with multiple values will be matched against a set of values.

      • header

        @Deprecated(message = "The use of Matcher will be removed in a future version", replaceWith = @ReplaceWith(imports = {}, expression = "header(name) { test(it) }")) final Unit header(String name, Matcher<in String> matchers)

        Match a request header using a Matcher.

      • accept

         final Unit accept(MediaType expectedMediaType)

        Match the Accept header against a specified MediaType. An Accept header with multiple values will be considered to match if any of the entries is compatible with the expected type.

      • contentType

         final Unit contentType(MediaType expectedMediaType)

        Match the Content-Type header against a specified MediaType.

      • requestJSON

         final Unit requestJSON(Function1<JSONExpect, Unit> tests)

        Match the request body using JSONExpect tests.

      • respondJSON

         final Unit respondJSON(HttpStatus status, HttpHeaders headers, Function1<JSONMockClientRequest, Object> lambda)

        Specify the response from the request as an object to be serialised to JSON. The object will be created dynamically, and the lambda that creates it will have access to the request variables.

      • respondJSON

         final Unit respondJSON(HttpStatus status, HttpHeaders headers, Object result)

        Specify the response from the request as a fixed object to be serialised to JSON.

      • respond

         final Unit respond(HttpStatus status, HttpHeaders headers, MediaType contentType, String result)

        Specify the response from the request as a fixed string.

      • respond

         final Unit respond(HttpStatus status, HttpHeaders headers, MediaType contentType, Function1<JSONMockClientRequest, String> lambda)

        Specify the response from the request as a string. The string will be created dynamically, and the lambda that creates it will have access to the request variables.

      • respondTextPlain

         final Unit respondTextPlain(HttpStatus status, HttpHeaders headers, String result)

        Specify the response from the request as a fixed string, with the type text/plain.

      • respondTextPlain

         final Unit respondTextPlain(HttpStatus status, HttpHeaders headers, Function1<JSONMockClientRequest, String> lambda)

        Specify the response from the request as a string, with the type text/plain. The string will be created dynamically, and the lambda that creates it will have access to the request variables.

      • respondBytes

         final Unit respondBytes(HttpStatus status, HttpHeaders headers, MediaType contentType, ByteArray result)

        Specify the response from the request as a fixed byte array.

      • respondBytes

         final Unit respondBytes(HttpStatus status, HttpHeaders headers, MediaType contentType, Function1<JSONMockClientRequest, ByteArray> lambda)

        Specify the response from the request as a fixed byte array. The byte array will be created dynamically, and the lambda that creates it will have access to the request variables.

      • createResponse

         ClientHttpResponse createResponse(ClientHttpRequest request)

        Create the ClientHttpResponse for this request, if the response has been set. If not, null will be returned, allowing the response to be set using a chained andRespond() function.