use of org.springframework.cloud.contract.spec.internal.Input in project spring-cloud-contract by spring-cloud.
the class Contract method input.
/**
* The input part of the contract.
* @param consumer function to manipulate the input
*/
public void input(Consumer<Input> consumer) {
this.input = new Input();
consumer.accept(this.input);
}
use of org.springframework.cloud.contract.spec.internal.Input in project spring-cloud-contract by spring-cloud.
the class MessagingHeadersGiven method apply.
@Override
public MethodVisitor<Given> apply(SingleContractMetadata metadata) {
Input inputMessage = metadata.getContract().getInput();
this.blockBuilder.startBlock().addIndented(", headers()").startBlock();
inputMessage.getMessageHeaders().executeForEachHeader(header -> {
this.blockBuilder.addEmptyLine().addIndented(getHeaderString(header));
});
this.blockBuilder.endBlock();
return this;
}
use of org.springframework.cloud.contract.spec.internal.Input in project spring-cloud-contract by spring-cloud.
the class Contract method input.
/**
* The input part of the contract.
* @param consumer function to manipulate the input
*/
public void input(@DelegatesTo(Input.class) Closure consumer) {
this.input = new Input();
consumer.setDelegate(this.input);
consumer.call();
}
use of org.springframework.cloud.contract.spec.internal.Input in project spring-cloud-contract by spring-cloud.
the class MessagingBodyGiven method appendBodyGiven.
private void appendBodyGiven(SingleContractMetadata metadata) {
ContentType contentType = metadata.getInputTestContentType();
Input inputMessage = metadata.getContract().getInput();
Object bodyValue = this.bodyParser.extractServerValueFromBody(contentType, inputMessage.getMessageBody().getServerValue());
if (bodyValue instanceof FromFileProperty) {
FromFileProperty fileProperty = (FromFileProperty) bodyValue;
String byteText = fileProperty.isByte() ? this.bodyReader.readBytesFromFileString(metadata, fileProperty, CommunicationType.REQUEST) : this.bodyParser.quotedLongText(this.bodyReader.readStringFromFileString(metadata, fileProperty, CommunicationType.REQUEST));
this.blockBuilder.addIndented(byteText);
} else {
String text = this.bodyParser.convertToJsonString(bodyValue);
this.blockBuilder.addIndented(this.bodyParser.quotedEscapedLongText(text));
}
}
use of org.springframework.cloud.contract.spec.internal.Input in project spring-cloud-contract by spring-cloud.
the class ContractsToYaml method input.
protected void input(Contract contract, YamlContract yamlContract) {
Input input = contract.getInput();
if (input != null) {
ContentType contentType = evaluateClientSideContentType(input.getMessageHeaders(), input.getMessageBody());
yamlContract.input = new YamlContract.Input();
yamlContract.input.assertThat = Optional.ofNullable(input.getAssertThat()).map(assertThat -> MapConverter.getTestSideValues(assertThat.toString(), MapConverter.JSON_PARSING_FUNCTION).toString()).orElse(null);
yamlContract.input.triggeredBy = Optional.ofNullable(input.getTriggeredBy()).map(triggeredBy -> MapConverter.getTestSideValues(triggeredBy.toString(), MapConverter.JSON_PARSING_FUNCTION).toString()).orElse(null);
yamlContract.input.messageHeaders = input.getMessageHeaders().asTestSideMap();
yamlContract.input.messageBody = MapConverter.getTestSideValues(input.getMessageBody(), MapConverter.JSON_PARSING_FUNCTION);
yamlContract.input.messageFrom = Optional.ofNullable(input.getMessageFrom()).map(messageFrom -> MapConverter.getTestSideValues(messageFrom, MapConverter.JSON_PARSING_FUNCTION).toString()).orElse(null);
Optional.ofNullable(input.getBodyMatchers()).map(BodyMatchers::matchers).ifPresent(bodyMatchers -> bodyMatchers.forEach(bodyMatcher -> {
YamlContract.BodyStubMatcher bodyStubMatcher = new YamlContract.BodyStubMatcher();
bodyStubMatcher.path = bodyMatcher.path();
bodyStubMatcher.type = stubMatcherType(bodyMatcher.matchingType());
bodyStubMatcher.value = Optional.ofNullable(bodyMatcher.value()).map(Object::toString).orElse(null);
yamlContract.input.matchers.body.add(bodyStubMatcher);
}));
if (XML != contentType) {
setInputBodyMatchers(input.getMessageBody(), yamlContract.input.matchers.body);
}
setInputHeadersMatchers(input.getMessageHeaders(), yamlContract.input.matchers.headers);
}
}
Aggregations