use of org.springframework.cloud.contract.spec.internal.Headers in project spring-cloud-contract by spring-cloud.
the class CustomModeHeadersThen method apply.
@Override
public MethodVisitor<Then> apply(SingleContractMetadata metadata) {
Response response = metadata.getContract().getResponse();
Headers headers = response.getHeaders();
Iterator<Header> iterator = headers.getEntries().iterator();
while (iterator.hasNext()) {
Header header = iterator.next();
String text = processHeaderElement(header.getName(), header.getServerValue() instanceof NotToEscapePattern ? header.getServerValue() : MapConverter.getTestSideValues(header.getServerValue()));
if (iterator.hasNext()) {
this.blockBuilder.addLineWithEnding(text);
} else {
this.blockBuilder.addIndented(text);
}
}
this.blockBuilder.addEndingIfNotPresent();
return this;
}
use of org.springframework.cloud.contract.spec.internal.Headers in project spring-cloud-contract by spring-cloud.
the class JaxRsResponseHeadersThen method validateResponseHeadersBlock.
private void validateResponseHeadersBlock(SingleContractMetadata metadata) {
Response response = metadata.getContract().getResponse();
Headers headers = response.getHeaders();
Iterator<Header> iterator = headers.getEntries().iterator();
while (iterator.hasNext()) {
Header header = iterator.next();
String text = processHeaderElement(header.getName(), header.getServerValue() instanceof NotToEscapePattern ? header.getServerValue() : MapConverter.getTestSideValues(header.getServerValue()));
if (iterator.hasNext()) {
this.blockBuilder.addLineWithEnding(text);
} else {
this.blockBuilder.addIndented(text);
}
}
}
use of org.springframework.cloud.contract.spec.internal.Headers in project spring-cloud-contract by spring-cloud.
the class ContractsToYaml method setOutputHeadersMatchers.
protected void setOutputHeadersMatchers(Headers headers, List<YamlContract.TestHeaderMatcher> headerMatchers) {
Optional.ofNullable(headers).map(Headers::asTestSideMap).ifPresent(testSideMap -> testSideMap.forEach((key, value) -> {
if (value instanceof RegexProperty || value instanceof Pattern) {
RegexProperty property = new RegexProperty(value);
YamlContract.TestHeaderMatcher testHeaderMatcher = new YamlContract.TestHeaderMatcher();
testHeaderMatcher.key = key;
testHeaderMatcher.regex = property.pattern();
testHeaderMatcher.regexType = regexType(property.clazz());
headerMatchers.add(testHeaderMatcher);
} else if (value instanceof ExecutionProperty) {
YamlContract.TestHeaderMatcher testHeaderMatcher = new YamlContract.TestHeaderMatcher();
testHeaderMatcher.key = key;
testHeaderMatcher.command = ((ExecutionProperty) value).getExecutionCommand();
headerMatchers.add(testHeaderMatcher);
} else if (value instanceof NotToEscapePattern) {
YamlContract.TestHeaderMatcher testHeaderMatcher = new YamlContract.TestHeaderMatcher();
testHeaderMatcher.key = key;
testHeaderMatcher.regex = (((NotToEscapePattern) value).getServerValue()).pattern();
headerMatchers.add(testHeaderMatcher);
}
}));
}
use of org.springframework.cloud.contract.spec.internal.Headers in project spring-cloud-contract by spring-cloud.
the class RestAssuredHeadersThen method apply.
@Override
public MethodVisitor<Then> apply(SingleContractMetadata metadata) {
Response response = metadata.getContract().getResponse();
Headers headers = response.getHeaders();
Iterator<Header> iterator = headers.getEntries().iterator();
while (iterator.hasNext()) {
Header header = iterator.next();
String text = processHeaderElement(header.getName(), header.getServerValue() instanceof NotToEscapePattern ? header.getServerValue() : MapConverter.getTestSideValues(header.getServerValue()));
if (iterator.hasNext()) {
this.blockBuilder.addLineWithEnding(text);
} else {
this.blockBuilder.addIndented(text);
}
}
this.blockBuilder.addEndingIfNotPresent();
return this;
}
use of org.springframework.cloud.contract.spec.internal.Headers in project spring-cloud-contract by spring-cloud.
the class MessagingSCContractCreator method convertFrom.
Collection<Contract> convertFrom(MessagePact pact) {
return pact.getMessages().stream().map(message -> Contract.make(contract -> {
contract.label(message.getDescription());
if (!message.getProviderStates().isEmpty()) {
contract.input(i -> i.triggeredBy(this.getTriggeredBy(message)));
}
contract.outputMessage((outputMessage) -> {
if (message.getContents().isPresent()) {
outputMessage.body(BodyConverter.toSCCBody(message));
Category bodyRules = message.getMatchingRules().rulesForCategory("body");
if (bodyRules != null && !bodyRules.getMatchingRules().isEmpty()) {
outputMessage.bodyMatchers((responseBodyMatchers) -> outputMessageBodyMatchers(message, bodyRules, responseBodyMatchers));
}
}
if (!message.getMetaData().isEmpty()) {
outputMessage.headers((headers) -> outputMessageHeaders(message, headers));
}
String dest = findDestination(message);
if (StringUtils.isNotBlank(dest)) {
outputMessage.sentTo(dest);
}
});
})).collect(Collectors.toList());
}
Aggregations