Search in sources :

Example 1 with Input

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);
}
Also used : Input(org.springframework.cloud.contract.spec.internal.Input)

Example 2 with 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;
}
Also used : Input(org.springframework.cloud.contract.spec.internal.Input)

Example 3 with Input

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();
}
Also used : Input(org.springframework.cloud.contract.spec.internal.Input)

Example 4 with Input

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));
    }
}
Also used : Input(org.springframework.cloud.contract.spec.internal.Input) ContentType(org.springframework.cloud.contract.verifier.util.ContentType) FromFileProperty(org.springframework.cloud.contract.spec.internal.FromFileProperty)

Example 5 with Input

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);
    }
}
Also used : JsonPaths(org.springframework.cloud.contract.verifier.util.JsonPaths) JsonToJsonPathsConverter(org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter) HashMap(java.util.HashMap) ContentUtils.evaluateClientSideContentType(org.springframework.cloud.contract.verifier.util.ContentUtils.evaluateClientSideContentType) Request(org.springframework.cloud.contract.spec.internal.Request) XML(org.springframework.cloud.contract.verifier.util.ContentType.XML) OutputMessage(org.springframework.cloud.contract.spec.internal.OutputMessage) MatchingType(org.springframework.cloud.contract.spec.internal.MatchingType) FromFileProperty(org.springframework.cloud.contract.spec.internal.FromFileProperty) NamedProperty(org.springframework.cloud.contract.spec.internal.NamedProperty) Contract(org.springframework.cloud.contract.spec.Contract) Map(java.util.Map) Cookies(org.springframework.cloud.contract.spec.internal.Cookies) BodyMatchers(org.springframework.cloud.contract.spec.internal.BodyMatchers) Url(org.springframework.cloud.contract.spec.internal.Url) Input(org.springframework.cloud.contract.spec.internal.Input) MapConverter(org.springframework.cloud.contract.verifier.util.MapConverter) Multipart(org.springframework.cloud.contract.spec.internal.Multipart) DslProperty(org.springframework.cloud.contract.spec.internal.DslProperty) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ExecutionProperty(org.springframework.cloud.contract.spec.internal.ExecutionProperty) ContentType(org.springframework.cloud.contract.verifier.util.ContentType) List(java.util.List) NotToEscapePattern(org.springframework.cloud.contract.spec.internal.NotToEscapePattern) MatchingStrategy(org.springframework.cloud.contract.spec.internal.MatchingStrategy) RegexProperty(org.springframework.cloud.contract.spec.internal.RegexProperty) QueryParameter(org.springframework.cloud.contract.spec.internal.QueryParameter) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Response(org.springframework.cloud.contract.spec.internal.Response) Headers(org.springframework.cloud.contract.spec.internal.Headers) Input(org.springframework.cloud.contract.spec.internal.Input) ContentUtils.evaluateClientSideContentType(org.springframework.cloud.contract.verifier.util.ContentUtils.evaluateClientSideContentType) ContentType(org.springframework.cloud.contract.verifier.util.ContentType)

Aggregations

Input (org.springframework.cloud.contract.spec.internal.Input)6 ContentType (org.springframework.cloud.contract.verifier.util.ContentType)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Pattern (java.util.regex.Pattern)2 Collectors (java.util.stream.Collectors)2 Contract (org.springframework.cloud.contract.spec.Contract)2 DslProperty (org.springframework.cloud.contract.spec.internal.DslProperty)2 ExecutionProperty (org.springframework.cloud.contract.spec.internal.ExecutionProperty)2 FromFileProperty (org.springframework.cloud.contract.spec.internal.FromFileProperty)2 Headers (org.springframework.cloud.contract.spec.internal.Headers)2 NamedProperty (org.springframework.cloud.contract.spec.internal.NamedProperty)2 OutputMessage (org.springframework.cloud.contract.spec.internal.OutputMessage)2 Request (org.springframework.cloud.contract.spec.internal.Request)2 Response (org.springframework.cloud.contract.spec.internal.Response)2 XML (org.springframework.cloud.contract.verifier.util.ContentType.XML)2 ContentUtils.evaluateClientSideContentType (org.springframework.cloud.contract.verifier.util.ContentUtils.evaluateClientSideContentType)2