Search in sources :

Example 1 with QueryParameters

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

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

the class RequestResponsePactCreator method query.

private String query(Request request) {
    final StringBuilder query = new StringBuilder();
    QueryParameters params = queryParams(request);
    if (params != null) {
        AtomicInteger index = new AtomicInteger();
        params.getParameters().forEach(p -> {
            query.append(p.getName()).append('=').append(p.getServerValue());
            if (index.incrementAndGet() < params.getParameters().size()) {
                query.append('&');
            }
        });
    }
    return query.toString();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryParameters(org.springframework.cloud.contract.spec.internal.QueryParameters)

Example 3 with QueryParameters

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

the class Path method from.

public static TestSideRequestTemplateModel from(final Request request) {
    Url urlPath = request.getUrl() != null ? request.getUrl() : request.getUrlPath();
    String url = MapConverter.getTestSideValues(urlPath).toString();
    Path paths = new Path(buildPathsFromUrl(url));
    QueryParameters queryParameters = urlPath.getQueryParameters();
    Map<String, List<Object>> query = query(queryParameters);
    boolean queryParamsPresent = query == null || query.isEmpty();
    String fullUrl = fullUrl(url, query, queryParamsPresent);
    boolean headersEntriesPresent = request.getHeaders() != null && !request.getHeaders().getEntries().isEmpty();
    Map<String, List<String>> headers = headers(request, headersEntriesPresent);
    String escapedBody = trimmedAndEscapedBody(request.getBody());
    String body = getBodyAsRawJson(request.getBody());
    return new TestSideRequestTemplateModel(fullUrl, query, paths, headers, body, escapedBody);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) GString(groovy.lang.GString) QueryParameters(org.springframework.cloud.contract.spec.internal.QueryParameters) Url(org.springframework.cloud.contract.spec.internal.Url)

Aggregations

QueryParameters (org.springframework.cloud.contract.spec.internal.QueryParameters)3 GString (groovy.lang.GString)2 List (java.util.List)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 WireMock (com.github.tomakehurst.wiremock.client.WireMock)1 Parameters (com.github.tomakehurst.wiremock.extension.Parameters)1 RequestMethod (com.github.tomakehurst.wiremock.http.RequestMethod)1 ContentPattern (com.github.tomakehurst.wiremock.matching.ContentPattern)1 RequestPattern (com.github.tomakehurst.wiremock.matching.RequestPattern)1 RequestPatternBuilder (com.github.tomakehurst.wiremock.matching.RequestPatternBuilder)1 StringValuePattern (com.github.tomakehurst.wiremock.matching.StringValuePattern)1 UrlPattern (com.github.tomakehurst.wiremock.matching.UrlPattern)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1