Updates the parsing of a json body containing a regex in the body
This commit is contained in:
@@ -93,14 +93,15 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
|
||||
}
|
||||
boolean bodyHasMatchingStrategy = request.body.clientValue instanceof MatchingStrategy
|
||||
MatchingStrategy matchingStrategy = getMatchingStrategyFromBody(request.body)
|
||||
Object clientSideBody = MapConverter.transformToClientValues(request.body)
|
||||
if (contentType == ContentType.JSON) {
|
||||
def originalBody = matchingStrategy?.clientValue
|
||||
if (bodyHasMatchingStrategy) {
|
||||
requestPattern.withRequestBody(
|
||||
convertToValuePattern(matchingStrategy))
|
||||
} else if (containsPattern(request?.body)) {
|
||||
} else if (clientSideBody instanceof Pattern || clientSideBody instanceof RegexProperty) {
|
||||
requestPattern.withRequestBody(
|
||||
convertToValuePattern(appendBodyRegexpMatchPattern(request.body)))
|
||||
convertToValuePattern(appendBodyRegexpMatchPattern(request.body, contentType)))
|
||||
} else {
|
||||
def body = JsonToJsonPathsConverter.
|
||||
removeMatchingJsonPaths(originalBody, request.bodyMatchers)
|
||||
@@ -399,13 +400,14 @@ class WireMockRequestStubStrategy extends BaseWireMockStubStrategy {
|
||||
}
|
||||
|
||||
private MatchingStrategy appendBodyRegexpMatchPattern(Object value, ContentType contentType) {
|
||||
Object clientValue = MapConverter.transformToClientValues(value)
|
||||
switch (contentType) {
|
||||
case ContentType.JSON:
|
||||
return new MatchingStrategy(
|
||||
buildJSONRegexpMatch(value), MatchingStrategy.Type.MATCHING)
|
||||
buildJSONRegexpMatch(clientValue), MatchingStrategy.Type.MATCHING)
|
||||
case ContentType.UNKNOWN:
|
||||
return new MatchingStrategy(
|
||||
buildGStringRegexpForStubSide(value), MatchingStrategy.Type.MATCHING)
|
||||
buildGStringRegexpForStubSide(clientValue), MatchingStrategy.Type.MATCHING)
|
||||
case ContentType.XML:
|
||||
throw new IllegalStateException("XML pattern matching is not implemented yet")
|
||||
}
|
||||
|
||||
@@ -177,8 +177,7 @@ public class WireMockSnippetTests {
|
||||
|
||||
@Test
|
||||
public void should_accept_query_params() throws IOException {
|
||||
this.operation = operation(requestGetWithQueryParam(), response(),
|
||||
this.context);
|
||||
this.operation = operation(requestGetWithQueryParam(), response(), this.context);
|
||||
WireMockSnippet snippet = new WireMockSnippet();
|
||||
|
||||
snippet.document(this.operation);
|
||||
@@ -188,9 +187,8 @@ public class WireMockSnippetTests {
|
||||
StubMapping stubMapping = WireMockStubMapping
|
||||
.buildFrom(new String(Files.readAllBytes(stub.toPath())));
|
||||
assertThat(stubMapping.getRequest().getUrlPath()).isEqualTo("/bar");
|
||||
assertThat(stubMapping.getRequest()
|
||||
.getQueryParameters())
|
||||
.containsOnly(Assertions.entry("myParam", MultiValuePattern.of(equalTo(("myValue")))));
|
||||
assertThat(stubMapping.getRequest().getQueryParameters()).containsOnly(
|
||||
Assertions.entry("myParam", MultiValuePattern.of(equalTo(("myValue")))));
|
||||
}
|
||||
|
||||
private Operation operation(OperationRequest request, OperationResponse response,
|
||||
|
||||
Reference in New Issue
Block a user