-
- All Implemented Interfaces:
-
org.springframework.test.web.client.ResponseCreator
public final class JSONMockServerDSL implements ResponseCreatorDSL class to configure mock requests to a JSONMockServer (wrapper class for Spring's
MockRestServiceServer).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classJSONMockServerDSL.Responsepublic classJSONMockServerDSL.Companion
-
Field Summary
Fields Modifier and Type Field Description private final JSONConfigconfig
-
Constructor Summary
Constructors Constructor Description JSONMockServerDSL(JSONConfig config)
-
Method Summary
Modifier and Type Method Description final JSONConfiggetConfig()final UnitrequestTo(String expectedURI)Match the request URI using a string. final UnitrequestTo(URI expectedURI)Match the URI against another URI. final UnitrequestTo(Function1<String, Boolean> test)Match the URI using a lambda. final UnitrequestTo(Matcher<in String> matcher)Match the URI using a Matcher. final Unitmethod(HttpMethod method)Match the method. final UnitqueryParam(String name, String expectedValues)Match a query parameter. final UnitqueryParam(String name, Function1<String, Boolean> test)Match a query parameter using a lambda. final Unitheader(String name, String expectedValues)Match a request header. final Unitheader(String name, Function1<String, Boolean> test)Match a request header using a lambda. final Unitheader(String name, Matcher<in String> matchers)Match a request header using a Matcher. final Unitaccept(MediaType expectedMediaType)Match the Acceptheader against a specified MediaType.final UnitacceptApplicationJSON()Match the Acceptheader withapplication/json.final UnitcontentType(MediaType expectedMediaType)Match the Content-Typeheader against a specified MediaType.final UnitcontentTypeApplicationJSON()Match the Content-Typeheader withapplication/json.final UnitheaderDoesNotExist(String name)Test that the nominated request header is not present in the request. final UnitrequestContent(String body)Match the request body content against a string. final UnitrequestContent(Function1<String, Boolean> test)Match the request body content using a lambda. final UnitrequestJSON(Function1<JSONExpect, Unit> tests)Match the request body using JSONExpect tests. final UnitrespondJSON(HttpStatus status, HttpHeaders headers, Function1<JSONMockClientRequest, Object> lambda)Specify the response from the request as an object to be serialised to JSON. final UnitrespondJSON(HttpStatus status, HttpHeaders headers, Object result)Specify the response from the request as a fixed object to be serialised to JSON. final Unitrespond(HttpStatus status, HttpHeaders headers, MediaType contentType, String result)Specify the response from the request as a fixed string. final Unitrespond(HttpStatus status, HttpHeaders headers, MediaType contentType, Function1<JSONMockClientRequest, String> lambda)Specify the response from the request as a string. final UnitrespondTextPlain(HttpStatus status, HttpHeaders headers, String result)Specify the response from the request as a fixed string, with the type text/plain.final UnitrespondTextPlain(HttpStatus status, HttpHeaders headers, Function1<JSONMockClientRequest, String> lambda)Specify the response from the request as a string, with the type text/plain.final UnitrespondBytes(HttpStatus status, HttpHeaders headers, MediaType contentType, ByteArray result)Specify the response from the request as a fixed byte array. final UnitrespondBytes(HttpStatus status, HttpHeaders headers, MediaType contentType, Function1<JSONMockClientRequest, ByteArray> lambda)Specify the response from the request as a fixed byte array. ClientHttpResponsecreateResponse(ClientHttpRequest request)Create the ClientHttpResponse for this request, if the response has been set. -
-
Method Detail
-
getConfig
final JSONConfig getConfig()
-
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.
-
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.
-
queryParam
final Unit queryParam(String name, Function1<String, Boolean> test)
Match a query parameter using a lambda.
-
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
final Unit header(String name, Function1<String, Boolean> test)
Match a request header using a lambda.
-
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
Acceptheader against a specified MediaType. AnAcceptheader with multiple values will be considered to match if any of the entries is compatible with the expected type.
-
acceptApplicationJSON
final Unit acceptApplicationJSON()
Match the
Acceptheader withapplication/json.
-
contentType
final Unit contentType(MediaType expectedMediaType)
Match the
Content-Typeheader against a specified MediaType.
-
contentTypeApplicationJSON
final Unit contentTypeApplicationJSON()
Match the
Content-Typeheader withapplication/json.
-
headerDoesNotExist
final Unit headerDoesNotExist(String name)
Test that the nominated request header is not present in the request.
-
requestContent
final Unit requestContent(String body)
Match the request body content against a string.
-
requestContent
final Unit requestContent(Function1<String, Boolean> test)
Match the request body content using a lambda.
-
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,
nullwill be returned, allowing the response to be set using a chainedandRespond()function.
-
-
-
-