use of org.springframework.cloud.contract.spec.internal.BodyMatcher in project spring-cloud-contract by spring-cloud.
the class XmlBodyVerificationBuilder method addXmlResponseBodyCheck.
void addXmlResponseBodyCheck(BlockBuilder blockBuilder, Object responseBody, BodyMatchers bodyMatchers, String responseString, boolean shouldCommentOutBDDBlocks) {
addXmlProcessingLines(blockBuilder, responseString);
Object processedBody = XmlToXPathsConverter.removeMatchingXPaths(responseBody, bodyMatchers);
List<BodyMatcher> matchers = new XmlToXPathsConverter().mapToMatchers(processedBody);
if (bodyMatchers != null && bodyMatchers.hasMatchers()) {
matchers.addAll(bodyMatchers.matchers());
}
addBodyMatchingBlock(matchers, blockBuilder, responseBody, shouldCommentOutBDDBlocks);
}
use of org.springframework.cloud.contract.spec.internal.BodyMatcher in project spring-cloud-contract by spring-cloud.
the class StubRunnerJmsMessageSelector method matchesForJsonPayload.
private boolean matchesForJsonPayload(Contract groovyDsl, Object inputMessage, BodyMatchers matchers, Object dslBody) {
Object matchingInputMessage = JsonToJsonPathsConverter.removeMatchingJsonPaths(dslBody, matchers);
JsonPaths jsonPaths = JsonToJsonPathsConverter.transformToJsonPathWithStubsSideValuesAndNoArraySizeCheck(matchingInputMessage);
DocumentContext parsedJson;
try {
parsedJson = JsonPath.parse(this.objectMapper.writeValueAsString(inputMessage));
} catch (JsonProcessingException e) {
throw new IllegalStateException("Cannot serialize to JSON", e);
}
List<String> unmatchedJsonPath = new ArrayList<>();
boolean matches = true;
for (MethodBufferingJsonVerifiable path : jsonPaths) {
matches &= matchesJsonPath(unmatchedJsonPath, parsedJson, path.jsonPath());
}
if (matchers != null && matchers.hasMatchers()) {
for (BodyMatcher matcher : matchers.matchers()) {
String jsonPath = JsonToJsonPathsConverter.convertJsonPathAndRegexToAJsonPath(matcher, dslBody);
matches &= matchesJsonPath(unmatchedJsonPath, parsedJson, jsonPath);
}
}
if (!unmatchedJsonPath.isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("Contract [" + groovyDsl + "] didn't match the body due to " + unmatchedJsonPath);
}
}
return matches;
}
use of org.springframework.cloud.contract.spec.internal.BodyMatcher in project spring-cloud-contract by spring-cloud.
the class StubRunnerCamelPredicate method matchesForJsonPayload.
private boolean matchesForJsonPayload(Contract groovyDsl, Object inputMessage, BodyMatchers matchers, Object dslBody) {
Object matchingInputMessage = JsonToJsonPathsConverter.removeMatchingJsonPaths(dslBody, matchers);
JsonPaths jsonPaths = JsonToJsonPathsConverter.transformToJsonPathWithStubsSideValuesAndNoArraySizeCheck(matchingInputMessage);
DocumentContext parsedJson;
try {
parsedJson = JsonPath.parse(this.objectMapper.writeValueAsString(inputMessage));
} catch (JsonProcessingException e) {
throw new IllegalStateException("Cannot serialize to JSON", e);
}
List<String> unmatchedJsonPath = new ArrayList<>();
boolean matches = true;
for (MethodBufferingJsonVerifiable path : jsonPaths) {
matches &= matchesJsonPath(unmatchedJsonPath, parsedJson, path.jsonPath());
}
if (matchers != null && matchers.hasMatchers()) {
for (BodyMatcher matcher : matchers.matchers()) {
String jsonPath = JsonToJsonPathsConverter.convertJsonPathAndRegexToAJsonPath(matcher, dslBody);
matches &= matchesJsonPath(unmatchedJsonPath, parsedJson, jsonPath);
}
}
if (!unmatchedJsonPath.isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("Contract [" + groovyDsl + "] didn't match the body due to " + unmatchedJsonPath);
}
}
return matches;
}
use of org.springframework.cloud.contract.spec.internal.BodyMatcher in project spring-cloud-contract by spring-cloud.
the class StubRunnerIntegrationMessageSelector method matchesForJsonPayload.
private boolean matchesForJsonPayload(Contract groovyDsl, Object inputMessage, BodyMatchers matchers, Object dslBody) {
Object matchingInputMessage = JsonToJsonPathsConverter.removeMatchingJsonPaths(dslBody, matchers);
JsonPaths jsonPaths = JsonToJsonPathsConverter.transformToJsonPathWithStubsSideValuesAndNoArraySizeCheck(matchingInputMessage);
DocumentContext parsedJson;
try {
parsedJson = JsonPath.parse(this.objectMapper.writeValueAsString(inputMessage));
} catch (JsonProcessingException e) {
throw new IllegalStateException("Cannot serialize to JSON", e);
}
List<String> unmatchedJsonPath = new ArrayList<>();
boolean matches = true;
for (MethodBufferingJsonVerifiable path : jsonPaths) {
matches &= matchesJsonPath(unmatchedJsonPath, parsedJson, path.jsonPath());
}
if (matchers != null && matchers.hasMatchers()) {
for (BodyMatcher matcher : matchers.matchers()) {
String jsonPath = JsonToJsonPathsConverter.convertJsonPathAndRegexToAJsonPath(matcher, dslBody);
matches &= matchesJsonPath(unmatchedJsonPath, parsedJson, jsonPath);
}
}
if (!unmatchedJsonPath.isEmpty()) {
if (log.isDebugEnabled()) {
log.debug("Contract [" + groovyDsl + "] didn't match the body due to " + unmatchedJsonPath);
}
}
return matches;
}
use of org.springframework.cloud.contract.spec.internal.BodyMatcher in project eventuate-tram-core by eventuate-tram.
the class EventuateTramRoutesConfigurer method satisfies.
private boolean satisfies(Message message, Contract groovyDsl) {
if (!headersMatch(message, groovyDsl)) {
logger.info("Headers don't match {} {} ", groovyDsl.getLabel(), message);
return false;
}
BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers();
Object dslBody = MapConverter.getStubSideValues(groovyDsl.getInput().getMessageBody());
Object matchingInputMessage = JsonToJsonPathsConverter.removeMatchingJsonPaths(dslBody, matchers);
JsonPaths jsonPaths = JsonToJsonPathsConverter.transformToJsonPathWithStubsSideValuesAndNoArraySizeCheck(matchingInputMessage);
DocumentContext parsedJson = JsonPath.parse(message.getPayload());
boolean matches = true;
for (MethodBufferingJsonVerifiable path : jsonPaths) {
matches &= matchesJsonPath(parsedJson, path.jsonPath());
}
logger.info("jsonPaths match {} {} {} ", groovyDsl.getLabel(), matches, message);
if (matchers != null && matchers.hasMatchers()) {
for (BodyMatcher matcher : matchers.jsonPathMatchers()) {
String jsonPath = JsonToJsonPathsConverter.convertJsonPathAndRegexToAJsonPath(matcher, dslBody);
matches &= matchesJsonPath(parsedJson, jsonPath);
}
}
logger.info("matchers {} {} {} ", groovyDsl.getLabel(), matches, message);
return matches;
}
Aggregations