Search in sources :

Example 1 with Response

use of org.springframework.cloud.contract.spec.internal.Response 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;
}
Also used : Response(org.springframework.cloud.contract.spec.internal.Response) Header(org.springframework.cloud.contract.spec.internal.Header) Headers(org.springframework.cloud.contract.spec.internal.Headers) NotToEscapePattern(org.springframework.cloud.contract.spec.internal.NotToEscapePattern)

Example 2 with Response

use of org.springframework.cloud.contract.spec.internal.Response in project spring-cloud-contract by spring-cloud.

the class CustomModeStatusCodeThen method apply.

@Override
public MethodVisitor<Then> apply(SingleContractMetadata metadata) {
    Response response = metadata.getContract().getResponse();
    this.blockBuilder.addIndented(this.comparisonBuilder.assertThat("response.statusCode()", response.getStatus().getServerValue())).addEndingIfNotPresent();
    return this;
}
Also used : Response(org.springframework.cloud.contract.spec.internal.Response)

Example 3 with Response

use of org.springframework.cloud.contract.spec.internal.Response 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();
        }
    }
}
Also used : Response(org.springframework.cloud.contract.spec.internal.Response) Cookie(org.springframework.cloud.contract.spec.internal.Cookie) Cookies(org.springframework.cloud.contract.spec.internal.Cookies) NotToEscapePattern(org.springframework.cloud.contract.spec.internal.NotToEscapePattern)

Example 4 with Response

use of org.springframework.cloud.contract.spec.internal.Response 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);
        }
    }
}
Also used : Response(org.springframework.cloud.contract.spec.internal.Response) Header(org.springframework.cloud.contract.spec.internal.Header) Headers(org.springframework.cloud.contract.spec.internal.Headers) NotToEscapePattern(org.springframework.cloud.contract.spec.internal.NotToEscapePattern)

Example 5 with Response

use of org.springframework.cloud.contract.spec.internal.Response in project spring-cloud-contract by spring-cloud.

the class ContractsToYaml method response.

protected void response(YamlContract yamlContract, Contract contract) {
    if (contract.getResponse() != null) {
        Response contractResponse = contract.getResponse();
        ContentType contentType = evaluateClientSideContentType(contractResponse.getHeaders(), contractResponse.getBody());
        YamlContract.Response response = new YamlContract.Response();
        yamlContract.response = response;
        mapResponseAsync(contractResponse, response);
        mapResponseFixedDelayMilliseconds(contractResponse, response);
        mapResponseStatus(contractResponse, response);
        mapResponseHeaders(contractResponse, response);
        mapResponseCookies(contractResponse, response);
        mapResponseBody(contractResponse, response);
        mapResponseBodyMatchers(contractResponse, response);
        if (XML != contentType) {
            setOutputBodyMatchers(contractResponse.getBody(), yamlContract.response.matchers.body);
        }
        setOutputHeadersMatchers(contractResponse.getHeaders(), yamlContract.response.matchers.headers);
    }
}
Also used : Response(org.springframework.cloud.contract.spec.internal.Response) ContentUtils.evaluateClientSideContentType(org.springframework.cloud.contract.verifier.util.ContentUtils.evaluateClientSideContentType) ContentType(org.springframework.cloud.contract.verifier.util.ContentType)

Aggregations

Response (org.springframework.cloud.contract.spec.internal.Response)15 Headers (org.springframework.cloud.contract.spec.internal.Headers)5 NotToEscapePattern (org.springframework.cloud.contract.spec.internal.NotToEscapePattern)5 Header (org.springframework.cloud.contract.spec.internal.Header)4 DslProperty (org.springframework.cloud.contract.spec.internal.DslProperty)3 ContentType (org.springframework.cloud.contract.verifier.util.ContentType)3 ContentUtils.evaluateClientSideContentType (org.springframework.cloud.contract.verifier.util.ContentUtils.evaluateClientSideContentType)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 Cookies (org.springframework.cloud.contract.spec.internal.Cookies)2 ExecutionProperty (org.springframework.cloud.contract.spec.internal.ExecutionProperty)2 Input (org.springframework.cloud.contract.spec.internal.Input)2 NamedProperty (org.springframework.cloud.contract.spec.internal.NamedProperty)2 DslPart (au.com.dius.pact.consumer.dsl.DslPart)1