Package 

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).

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final JSONConfig config
    • Constructor Summary

      Constructors 
      Constructor Description
      JSONMockServerDSL(JSONConfig config)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final JSONConfig getConfig()
      final Unit requestTo(String expectedURI) Match the request URI using a string.
      final Unit requestTo(URI expectedURI) Match the URI against another URI.
      final Unit requestTo(Function1<String, Boolean> test) Match the URI using a lambda.
      final Unit requestTo(Matcher<in String> matcher) Match the URI using a Matcher.
      final Unit method(HttpMethod method) Match the method.
      final Unit queryParam(String name, String expectedValues) Match a query parameter.
      final Unit queryParam(String name, Function1<String, Boolean> test) Match a query parameter using a lambda.
      final Unit header(String name, String expectedValues) Match a request header.
      final Unit header(String name, Function1<String, Boolean> test) Match a request header using a lambda.
      final Unit header(String name, Matcher<in String> matchers) Match a request header using a Matcher.
      final Unit accept(MediaType expectedMediaType) Match the Accept header against a specified MediaType.
      final Unit acceptApplicationJSON() Match the Accept header with application/json.
      final Unit contentType(MediaType expectedMediaType) Match the Content-Type header against a specified MediaType.
      final Unit contentTypeApplicationJSON() Match the Content-Type header with application/json.
      final Unit headerDoesNotExist(String name) Test that the nominated request header is not present in the request.
      final Unit requestContent(String body) Match the request body content against a string.
      final Unit requestContent(Function1<String, Boolean> test) Match the request body content using a lambda.
      final Unit requestJSON(Function1<JSONExpect, Unit> tests) Match the request body using JSONExpect tests.
      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.
      final Unit respondJSON(HttpStatus status, HttpHeaders headers, Object result) Specify the response from the request as a fixed object to be serialised to JSON.
      final Unit respond(HttpStatus status, HttpHeaders headers, MediaType contentType, String result) Specify the response from the request as a fixed string.
      final Unit respond(HttpStatus status, HttpHeaders headers, MediaType contentType, Function1<JSONMockClientRequest, String> lambda) Specify the response from the request as a string.
      final Unit respondTextPlain(HttpStatus status, HttpHeaders headers, String result) Specify the response from the request as a fixed string, with the type text/plain.
      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.
      final Unit respondBytes(HttpStatus status, HttpHeaders headers, MediaType contentType, ByteArray result) Specify the response from the request as a fixed byte array.
      final Unit respondBytes(HttpStatus status, HttpHeaders headers, MediaType contentType, Function1<JSONMockClientRequest, ByteArray> lambda) Specify the response from the request as a fixed byte array.
      ClientHttpResponse createResponse(ClientHttpRequest request) Create the ClientHttpResponse for this request, if the response has been set.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.