use of au.com.dius.pact.consumer.dsl.PactDslRequestWithPath in project spring-cloud-contract by spring-cloud.
the class RequestResponsePactCreator method createFromContract.
RequestResponsePact createFromContract(List<Contract> contracts) {
if (CollectionUtils.isEmpty(contracts)) {
return null;
}
Names names = NamingUtil.name(contracts.get(0));
PactDslWithProvider pactDslWithProvider = ConsumerPactBuilder.consumer(names.getConsumer()).hasPactWith(names.getProducer());
PactDslResponse pactDslResponse = null;
for (Contract contract : contracts) {
assertNoExecutionProperty(contract);
PactDslRequestWithPath pactDslRequest = pactDslResponse != null ? createPactDslRequestWithPath(contract, pactDslResponse) : createPactDslRequestWithPath(contract, pactDslWithProvider);
pactDslResponse = createPactDslResponse(contract, pactDslRequest);
}
return pactDslResponse.toPact();
}
use of au.com.dius.pact.consumer.dsl.PactDslRequestWithPath in project spring-cloud-contract by spring-cloud.
the class RequestResponsePactCreator method createPactDslRequestWithPath.
private PactDslRequestWithPath createPactDslRequestWithPath(Contract contract, PactDslWithProvider pactDslWithProvider) {
PactDslRequestWithPath pactDslRequest = getPactDslRequest(contract, getPactDslWithStateFunction(pactDslWithProvider), getPactDslRequestWithPathBiFunction(pactDslWithProvider));
Request request = contract.getRequest();
final PactDslRequestWithPath finalPactDslRequest = pactDslRequest;
if (request.getHeaders() != null) {
request.getHeaders().getEntries().forEach(h -> processHeader(finalPactDslRequest, h));
}
if (request.getBody() != null) {
DslPart pactRequestBody = BodyConverter.toPactBody(request.getBody(), DslProperty::getServerValue);
if (request.getBodyMatchers() != null) {
pactRequestBody.setMatchers(MatchingRulesConverter.matchingRulesForBody(request.getBodyMatchers()));
}
pactRequestBody.setGenerators(ValueGeneratorConverter.extract(request.getBody(), DslProperty::getClientValue));
pactDslRequest = pactDslRequest.body(pactRequestBody);
}
return pactDslRequest;
}
use of au.com.dius.pact.consumer.dsl.PactDslRequestWithPath in project spring-cloud-contract by spring-cloud.
the class RequestResponsePactCreator method getPactDslRequest.
private PactDslRequestWithPath getPactDslRequest(Contract contract, Function<PactMetaData.ProviderStateMetadata, PactDslWithState> pactDslWithStateFunction, BiFunction<String, Request, PactDslRequestWithPath> pactDslRequestWithPathBiFunction) {
PactDslWithState pactDslWithState = getPactDslWithState(contract, pactDslWithStateFunction);
String description = StringUtils.isNotBlank(contract.getDescription()) ? contract.getDescription() : "";
Request request = contract.getRequest();
PactDslRequestWithPath pactDslRequest;
if (pactDslWithState != null) {
pactDslRequest = pactDslWithState.uponReceiving(description).path(url(request)).method(request.getMethod().getServerValue().toString());
} else {
pactDslRequest = pactDslRequestWithPathBiFunction.apply(description, request);
}
String query = query(request);
if (StringUtils.isNotBlank(query)) {
pactDslRequest = pactDslRequest.encodedQuery(query);
}
return pactDslRequest;
}
use of au.com.dius.pact.consumer.dsl.PactDslRequestWithPath in project spring-cloud-contract by spring-cloud.
the class RequestResponsePactCreator method createPactDslRequestWithPath.
private PactDslRequestWithPath createPactDslRequestWithPath(Contract contract, PactDslResponse pactDslResponse) {
PactDslRequestWithPath pactDslRequest = getPactDslRequest(contract, getPactDslWithStateFunction(pactDslResponse), getPactDslRequestWithPathBiFunction(pactDslResponse));
Request request = contract.getRequest();
final PactDslRequestWithPath finalPactDslRequest = pactDslRequest;
if (request.getHeaders() != null) {
request.getHeaders().getEntries().forEach(h -> processHeader(finalPactDslRequest, h));
}
if (request.getCookies() != null) {
pactDslRequest = processCookies(finalPactDslRequest, request.getCookies());
}
if (request.getBody() != null) {
DslPart pactRequestBody = BodyConverter.toPactBody(request.getBody(), DslProperty::getClientValue);
if (request.getBodyMatchers() != null) {
pactRequestBody.setMatchers(MatchingRulesConverter.matchingRulesForBody(request.getBodyMatchers()));
}
pactRequestBody.setGenerators(ValueGeneratorConverter.extract(request.getBody(), DslProperty::getClientValue));
pactDslRequest = pactDslRequest.body(pactRequestBody);
}
return pactDslRequest;
}
Aggregations