use of org.springframework.cloud.contract.spec.internal.Header in project spring-cloud-contract by spring-cloud.
the class JaxRsRequestHeadersWhen method appendHeaders.
private void appendHeaders(Request request) {
Iterator<Header> iterator = request.getHeaders().getEntries().stream().filter(header -> !headerToIgnore(header)).iterator();
while (iterator.hasNext()) {
Header header = iterator.next();
String text = ".header(\"" + header.getName() + "\", " + headerValue(header) + ")";
if (iterator.hasNext()) {
this.blockBuilder.addLine(text);
} else {
this.blockBuilder.addIndented(text);
}
}
}
use of org.springframework.cloud.contract.spec.internal.Header 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.Header 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.Header 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.Header in project spring-cloud-contract by spring-cloud.
the class StubRunnerJmsMessageSelector method headersMatch.
private List<String> headersMatch(Message message, Contract groovyDsl) {
List<String> unmatchedHeaders = new ArrayList<>();
Map<String, Object> headers = StubRunnerJmsAccessor.getHeaders(message);
for (Header it : groovyDsl.getInput().getMessageHeaders().getEntries()) {
String name = it.getName();
Object value = it.getClientValue();
Object valueInHeader = headers.get(name);
boolean matches;
if (value instanceof RegexProperty) {
Pattern pattern = ((RegexProperty) value).getPattern();
matches = pattern.matcher(valueInHeader.toString()).matches();
} else {
matches = valueInHeader != null && valueInHeader.toString().equals(value.toString());
}
if (!matches) {
unmatchedHeaders.add("Header with name [" + name + "] was supposed to " + unmatchedText(value) + " but the value is [" + (valueInHeader != null ? valueInHeader.toString() : "null") + "]");
}
}
return unmatchedHeaders;
}
Aggregations