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