use of org.springframework.cloud.contract.spec.internal.BodyMatchers in project spring-cloud-contract by spring-cloud.
the class GenericXmlBodyThen method apply.
@Override
public MethodVisitor<Then> apply(SingleContractMetadata metadata) {
BodyMatchers bodyMatchers = this.bodyParser.responseBodyMatchers(metadata);
Object convertedResponseBody = this.bodyParser.convertResponseBody(metadata);
XmlBodyVerificationBuilder xmlBodyVerificationBuilder = new XmlBodyVerificationBuilder(metadata.getContract(), Optional.of(this.blockBuilder.getLineEnding()));
xmlBodyVerificationBuilder.addXmlResponseBodyCheck(this.blockBuilder, convertedResponseBody, bodyMatchers, this.bodyParser.responseAsString(), true);
return this;
}
use of org.springframework.cloud.contract.spec.internal.BodyMatchers in project spring-cloud-contract by spring-cloud.
the class ContractsToYaml method setOutputBodyMatchers.
protected void setOutputBodyMatchers(DslProperty<?> body, List<YamlContract.BodyTestMatcher> bodyMatchers) {
Object testSideValues = MapConverter.getTestSideValues(body);
JsonPaths paths = new JsonToJsonPathsConverter().transformToJsonPathWithTestsSideValues(body);
paths.stream().filter(m -> m.valueBeforeChecking() instanceof Pattern).forEach((m) -> {
Object element = JsonToJsonPathsConverter.readElement(testSideValues, m.keyBeforeChecking());
YamlContract.BodyTestMatcher bodyTestMatcher = new YamlContract.BodyTestMatcher();
bodyTestMatcher.path = m.keyBeforeChecking();
bodyTestMatcher.type = YamlContract.TestMatcherType.by_regex;
bodyTestMatcher.value = ((Pattern) m.valueBeforeChecking()).pattern();
bodyTestMatcher.regexType = regexType(element);
bodyMatchers.add(bodyTestMatcher);
});
Optional.ofNullable(body).filter(b -> b.getServerValue() instanceof Pattern).ifPresent((b) -> {
YamlContract.BodyTestMatcher bodyTestMatcher = new YamlContract.BodyTestMatcher();
bodyTestMatcher.type = YamlContract.TestMatcherType.by_regex;
bodyTestMatcher.value = ((Pattern) b.getServerValue()).pattern();
bodyMatchers.add(bodyTestMatcher);
});
}
use of org.springframework.cloud.contract.spec.internal.BodyMatchers in project spring-cloud-contract by spring-cloud.
the class XmlBodyVerificationBuilderTest method shouldAddXmlProcessingLines.
@Test
public void shouldAddXmlProcessingLines() {
// Given
XmlBodyVerificationBuilder builder = new XmlBodyVerificationBuilder(new Contract(), Optional.of(";"));
BlockBuilder blockBuilder = new BlockBuilder(" ");
BodyMatchers matchers = new BodyMatchers();
// When
builder.addXmlResponseBodyCheck(blockBuilder, xml, matchers, xml, true);
// Then
String test = blockBuilder.toString();
assertThat(test).contains("DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();").contains("builderFactory.setNamespaceAware(true);").contains("DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();").contains("Document parsedXml = documentBuilder.parse(new InputSource(new StringReader(").contains(xml);
}
use of org.springframework.cloud.contract.spec.internal.BodyMatchers in project spring-cloud-contract by spring-cloud.
the class StubRunnerCamelPredicate method matchViaContent.
private boolean matchViaContent(Contract groovyDsl, Object inputMessage, Object dslBody) {
boolean matches;
ContentType type = ContentUtils.getClientContentType(inputMessage, groovyDsl.getInput().getMessageHeaders());
if (type == ContentType.JSON) {
BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers();
matches = matchesForJsonPayload(groovyDsl, inputMessage, matchers, dslBody);
} else if (dslBody instanceof RegexProperty && inputMessage instanceof String) {
Pattern pattern = ((RegexProperty) dslBody).getPattern();
matches = pattern.matcher((String) inputMessage).matches();
bodyUnmatchedLog(dslBody, matches, pattern);
} else {
matches = dslBody.equals(inputMessage);
bodyUnmatchedLog(dslBody, matches, inputMessage);
}
return matches;
}
use of org.springframework.cloud.contract.spec.internal.BodyMatchers in project spring-cloud-contract by spring-cloud.
the class StubRunnerIntegrationMessageSelector method matchViaContent.
private boolean matchViaContent(Contract groovyDsl, Object inputMessage, Object dslBody) {
boolean matches;
ContentType type = ContentUtils.getClientContentType(inputMessage, groovyDsl.getInput().getMessageHeaders());
if (type == ContentType.JSON) {
BodyMatchers matchers = groovyDsl.getInput().getBodyMatchers();
matches = matchesForJsonPayload(groovyDsl, inputMessage, matchers, dslBody);
} else if (dslBody instanceof RegexProperty && inputMessage instanceof String) {
Pattern pattern = ((RegexProperty) dslBody).getPattern();
matches = pattern.matcher((String) inputMessage).matches();
bodyUnmatchedLog(dslBody, matches, pattern);
} else {
matches = dslBody.equals(inputMessage);
bodyUnmatchedLog(dslBody, matches, inputMessage);
}
return matches;
}
Aggregations