use of org.springframework.cloud.contract.spec.internal.PathBodyMatcher in project spring-cloud-contract by spring-cloud.
the class WireMockRequestStubStrategy method addWireMockStubMatchingSection.
private static void addWireMockStubMatchingSection(BodyMatcher matcher, RequestPatternBuilder requestPattern, Object body) {
Set<MatchingType> matchingTypesUnsupportedForRequest = new HashSet<>(Arrays.asList(MatchingType.NULL, MatchingType.COMMAND, MatchingType.TYPE));
if (!(matcher instanceof PathBodyMatcher)) {
throw new IllegalArgumentException("Only jsonPath and XPath matchers can be processed.");
}
String retrievedValue = Optional.ofNullable(matcher.value()).map(Object::toString).orElseGet(() -> {
if (matchingTypesUnsupportedForRequest.contains(matcher.matchingType())) {
throw new IllegalArgumentException("Null, Command and Type matchers are not supported in requests.");
}
if (EQUALITY == matcher.matchingType()) {
return retrieveValue(matcher, body);
} else {
return "";
}
});
PathBodyMatcher pathMatcher = (PathBodyMatcher) matcher;
requestPattern.withRequestBody(WireMock.matchingXPath(pathMatcher.path(), XPathBodyMatcherToWireMockValuePatternConverter.mapToPattern(pathMatcher.matchingType(), String.valueOf(retrievedValue))));
}
Aggregations