use of org.springframework.cloud.contract.spec.internal.NotToEscapePattern 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.NotToEscapePattern in project spring-cloud-contract by spring-cloud.
the class CookieElementProcessor method processCookies.
default void processCookies(SingleContractMetadata metadata) {
Response response = metadata.getContract().getResponse();
Cookies cookies = response.getCookies();
Iterator<Cookie> iterator = cookies.getEntries().iterator();
while (iterator.hasNext()) {
Cookie cookie = iterator.next();
String text = processCookieElement(cookie.getKey(), cookie.getServerValue() instanceof NotToEscapePattern ? cookie.getServerValue() : MapConverter.getTestSideValues(cookie.getServerValue()));
if (iterator.hasNext()) {
blockBuilder().addLine(text).addEndingIfNotPresent();
} else {
blockBuilder().addIndented(text).addEndingIfNotPresent();
}
}
}
use of org.springframework.cloud.contract.spec.internal.NotToEscapePattern 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.NotToEscapePattern 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.NotToEscapePattern 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;
}
Aggregations