Search in sources :

Example 1 with Cookie

use of org.springframework.cloud.contract.spec.internal.Cookie 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 2 with Cookie

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

the class JaxRsRequestCookiesWhen method appendCookies.

private void appendCookies(Request request) {
    Iterator<Cookie> iterator = request.getCookies().getEntries().stream().filter(cookie -> !cookieOfAbsentType(cookie)).iterator();
    while (iterator.hasNext()) {
        Cookie cookie = iterator.next();
        String value = ".cookie(" + this.bodyParser.quotedShortText(cookie.getKey()) + ", " + this.bodyParser.quotedShortText(MapConverter.getTestSideValuesForNonBody(cookie.getServerValue())) + ")";
        if (iterator.hasNext()) {
            this.blockBuilder.addLine(value);
        } else {
            this.blockBuilder.addIndented(value);
        }
    }
}
Also used : Cookie(org.springframework.cloud.contract.spec.internal.Cookie) Iterator(java.util.Iterator) MatchingStrategy(org.springframework.cloud.contract.spec.internal.MatchingStrategy) Set(java.util.Set) Cookie(org.springframework.cloud.contract.spec.internal.Cookie) SingleContractMetadata(org.springframework.cloud.contract.verifier.file.SingleContractMetadata) Request(org.springframework.cloud.contract.spec.internal.Request) MapConverter(org.springframework.cloud.contract.verifier.util.MapConverter)

Aggregations

Cookie (org.springframework.cloud.contract.spec.internal.Cookie)2 Iterator (java.util.Iterator)1 Set (java.util.Set)1 Cookies (org.springframework.cloud.contract.spec.internal.Cookies)1 MatchingStrategy (org.springframework.cloud.contract.spec.internal.MatchingStrategy)1 NotToEscapePattern (org.springframework.cloud.contract.spec.internal.NotToEscapePattern)1 Request (org.springframework.cloud.contract.spec.internal.Request)1 Response (org.springframework.cloud.contract.spec.internal.Response)1 SingleContractMetadata (org.springframework.cloud.contract.verifier.file.SingleContractMetadata)1 MapConverter (org.springframework.cloud.contract.verifier.util.MapConverter)1