Search in sources :

Example 1 with Url

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

the class ContractsToYaml method request.

protected void request(Contract contract, YamlContract yamlContract) {
    Request request = contract.getRequest();
    if (request != null) {
        ContentType requestContentType = evaluateClientSideContentType(request.getHeaders(), request.getBody());
        yamlContract.request = new YamlContract.Request();
        mapRequestMethod(yamlContract.request, request);
        mapRequestUrl(yamlContract.request, request);
        mapRequestUrlPath(yamlContract.request, request);
        mapRequestMatchers(yamlContract.request);
        Url requestUrl = Optional.ofNullable(request.getUrl()).orElse(request.getUrlPath());
        if (requestUrl.getQueryParameters() != null) {
            mapRequestQueryParameters(yamlContract.request, requestUrl);
            mapRequestMatchersQueryParameters(yamlContract.request, requestUrl);
        }
        mapRequestHeaders(yamlContract.request, request);
        mapRequestCookies(yamlContract.request, request);
        mapRequestBody(yamlContract.request, request);
        mapRequestMultipart(yamlContract.request, request);
        mapRequestMatchersBody(yamlContract.request, request);
        mapRequestMatchersUrl(yamlContract.request, request);
        mapRequestMatchersMultipart(yamlContract.request, request);
        // TODO: Cookie matchers - including absent
        if (XML != requestContentType) {
            setInputBodyMatchers(request.getBody(), yamlContract.request.matchers.body);
        }
        setInputHeadersMatchers(request.getHeaders(), yamlContract.request.matchers.headers);
    }
}
Also used : ContentUtils.evaluateClientSideContentType(org.springframework.cloud.contract.verifier.util.ContentUtils.evaluateClientSideContentType) ContentType(org.springframework.cloud.contract.verifier.util.ContentType) Request(org.springframework.cloud.contract.spec.internal.Request) Url(org.springframework.cloud.contract.spec.internal.Url)

Example 2 with Url

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

the class WireMockRequestStubStrategy method appendQueryParameters.

private void appendQueryParameters(RequestPatternBuilder requestPattern) {
    QueryParameters queryParameters = Optional.ofNullable(request).map(Request::getUrlPath).map(Url::getQueryParameters).orElseGet(() -> Optional.ofNullable(request).map(Request::getUrl).map(Url::getQueryParameters).orElse(null));
    Optional.ofNullable(queryParameters).map(QueryParameters::getParameters).ifPresent(parameters -> parameters.forEach(parameter -> requestPattern.withQueryParam(parameter.getName(), (StringValuePattern) convertToValuePattern(parameter.getClientValue()))));
}
Also used : Arrays(java.util.Arrays) JsonPaths(org.springframework.cloud.contract.verifier.util.JsonPaths) XmlToXPathsConverter.retrieveValue(org.springframework.cloud.contract.verifier.util.xml.XmlToXPathsConverter.retrieveValue) JsonToJsonPathsConverter(org.springframework.cloud.contract.verifier.util.JsonToJsonPathsConverter) YamlContract(org.springframework.cloud.contract.verifier.converter.YamlContract) SingleContractMetadata(org.springframework.cloud.contract.verifier.file.SingleContractMetadata) MatchingType(org.springframework.cloud.contract.spec.internal.MatchingType) RequestPattern(com.github.tomakehurst.wiremock.matching.RequestPattern) FromFileProperty(org.springframework.cloud.contract.spec.internal.FromFileProperty) BodyMatcher(org.springframework.cloud.contract.spec.internal.BodyMatcher) RegexpBuilders.buildGStringRegexpForStubSide(org.springframework.cloud.contract.verifier.util.RegexpBuilders.buildGStringRegexpForStubSide) QueryParameters(org.springframework.cloud.contract.spec.internal.QueryParameters) YamlContractConverter(org.springframework.cloud.contract.verifier.converter.YamlContractConverter) Contract(org.springframework.cloud.contract.spec.Contract) Map(java.util.Map) BodyMatchers(org.springframework.cloud.contract.spec.internal.BodyMatchers) FORM(org.springframework.cloud.contract.verifier.util.ContentType.FORM) MapConverter(org.springframework.cloud.contract.verifier.util.MapConverter) DslProperty(org.springframework.cloud.contract.spec.internal.DslProperty) ContentUtils(org.springframework.cloud.contract.verifier.util.ContentUtils) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) RegexpBuilders.buildJSONRegexpMatch(org.springframework.cloud.contract.verifier.util.RegexpBuilders.buildJSONRegexpMatch) RequestPatternBuilder(com.github.tomakehurst.wiremock.matching.RequestPatternBuilder) GString(groovy.lang.GString) ClientDslProperty(org.springframework.cloud.contract.spec.internal.ClientDslProperty) ContentType(org.springframework.cloud.contract.verifier.util.ContentType) List(java.util.List) StringValuePattern(com.github.tomakehurst.wiremock.matching.StringValuePattern) PathBodyMatcher(org.springframework.cloud.contract.spec.internal.PathBodyMatcher) OptionalProperty(org.springframework.cloud.contract.spec.internal.OptionalProperty) MatchingStrategy(org.springframework.cloud.contract.spec.internal.MatchingStrategy) CollectionUtils(org.springframework.util.CollectionUtils) Optional(java.util.Optional) ContentPattern(com.github.tomakehurst.wiremock.matching.ContentPattern) Pattern(java.util.regex.Pattern) EQUALITY(org.springframework.cloud.contract.spec.internal.MatchingType.EQUALITY) ContentUtils.getEqualsTypeFromContentType(org.springframework.cloud.contract.verifier.util.ContentUtils.getEqualsTypeFromContentType) Request(org.springframework.cloud.contract.spec.internal.Request) Function(java.util.function.Function) WireMock(com.github.tomakehurst.wiremock.client.WireMock) HashSet(java.util.HashSet) NamedProperty(org.springframework.cloud.contract.spec.internal.NamedProperty) UrlPattern(com.github.tomakehurst.wiremock.matching.UrlPattern) Body(org.springframework.cloud.contract.spec.internal.Body) Url(org.springframework.cloud.contract.spec.internal.Url) XmlToXPathsConverter(org.springframework.cloud.contract.verifier.util.xml.XmlToXPathsConverter) Parameters(com.github.tomakehurst.wiremock.extension.Parameters) Iterator(java.util.Iterator) JSON(org.springframework.cloud.contract.verifier.util.ContentType.JSON) MethodBufferingJsonVerifiable(org.springframework.cloud.contract.verifier.util.MethodBufferingJsonVerifiable) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StringEscapeUtils(org.apache.commons.text.StringEscapeUtils) ContractVerifierMetadata(org.springframework.cloud.contract.verifier.dsl.ContractVerifierMetadata) RegexProperty(org.springframework.cloud.contract.spec.internal.RegexProperty) RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) RegexPatterns(org.springframework.cloud.contract.spec.internal.RegexPatterns) Collections(java.util.Collections) BINARY_EQUAL_TO(org.springframework.cloud.contract.spec.internal.MatchingStrategy.Type.BINARY_EQUAL_TO) StringUtils(org.springframework.util.StringUtils) Request(org.springframework.cloud.contract.spec.internal.Request) QueryParameters(org.springframework.cloud.contract.spec.internal.QueryParameters) Url(org.springframework.cloud.contract.spec.internal.Url)

Example 3 with Url

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

the class MockMvcQueryParamsWhen method accept.

@Override
public boolean accept(SingleContractMetadata metadata) {
    Request request = metadata.getContract().getRequest();
    Url url = getUrl(request);
    return url.getQueryParameters() != null;
}
Also used : Request(org.springframework.cloud.contract.spec.internal.Request) Url(org.springframework.cloud.contract.spec.internal.Url)

Example 4 with Url

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

the class CustomModeQueryParamsGiven method apply.

@Override
public MethodVisitor<Given> apply(SingleContractMetadata metadata) {
    Request request = metadata.getContract().getRequest();
    Url url = getUrl(request);
    addQueryParameters(url);
    return this;
}
Also used : Request(org.springframework.cloud.contract.spec.internal.Request) Url(org.springframework.cloud.contract.spec.internal.Url)

Example 5 with Url

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

the class MockMvcQueryParamsWhen method apply.

@Override
public MethodVisitor<When> apply(SingleContractMetadata metadata) {
    Request request = metadata.getContract().getRequest();
    Url url = getUrl(request);
    addQueryParameters(url);
    return this;
}
Also used : Request(org.springframework.cloud.contract.spec.internal.Request) Url(org.springframework.cloud.contract.spec.internal.Url)

Aggregations

Url (org.springframework.cloud.contract.spec.internal.Url)8 Request (org.springframework.cloud.contract.spec.internal.Request)7 List (java.util.List)3 ContentType (org.springframework.cloud.contract.verifier.util.ContentType)3 GString (groovy.lang.GString)2 Collection (java.util.Collection)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 BodyMatchers (org.springframework.cloud.contract.spec.internal.BodyMatchers)2 DslProperty (org.springframework.cloud.contract.spec.internal.DslProperty)2 FromFileProperty (org.springframework.cloud.contract.spec.internal.FromFileProperty)2 MatchingStrategy (org.springframework.cloud.contract.spec.internal.MatchingStrategy)2 MatchingType (org.springframework.cloud.contract.spec.internal.MatchingType)2 NamedProperty (org.springframework.cloud.contract.spec.internal.NamedProperty)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 WireMock (com.github.tomakehurst.wiremock.client.WireMock)1