Search in sources :

Example 1 with NotToEscapePattern

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;
}
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 NotToEscapePattern

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();
        }
    }
}
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 3 with NotToEscapePattern

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);
        }
    }
}
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 4 with NotToEscapePattern

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);
        }
    }));
}
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) NotToEscapePattern(org.springframework.cloud.contract.spec.internal.NotToEscapePattern) Pattern(java.util.regex.Pattern) RegexProperty(org.springframework.cloud.contract.spec.internal.RegexProperty) NotToEscapePattern(org.springframework.cloud.contract.spec.internal.NotToEscapePattern) ExecutionProperty(org.springframework.cloud.contract.spec.internal.ExecutionProperty)

Example 5 with NotToEscapePattern

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;
}
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)

Aggregations

NotToEscapePattern (org.springframework.cloud.contract.spec.internal.NotToEscapePattern)6 Response (org.springframework.cloud.contract.spec.internal.Response)5 Headers (org.springframework.cloud.contract.spec.internal.Headers)4 Header (org.springframework.cloud.contract.spec.internal.Header)3 Cookies (org.springframework.cloud.contract.spec.internal.Cookies)2 OutputMessage (org.springframework.cloud.contract.spec.internal.OutputMessage)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Contract (org.springframework.cloud.contract.spec.Contract)1 BodyMatchers (org.springframework.cloud.contract.spec.internal.BodyMatchers)1 Cookie (org.springframework.cloud.contract.spec.internal.Cookie)1 DslProperty (org.springframework.cloud.contract.spec.internal.DslProperty)1 ExecutionProperty (org.springframework.cloud.contract.spec.internal.ExecutionProperty)1 FromFileProperty (org.springframework.cloud.contract.spec.internal.FromFileProperty)1