Search in sources :

Example 1 with PactDslRequestWithPath

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();
}
Also used : PactDslWithProvider(au.com.dius.pact.consumer.dsl.PactDslWithProvider) Contract(org.springframework.cloud.contract.spec.Contract) PactDslResponse(au.com.dius.pact.consumer.dsl.PactDslResponse) PactDslRequestWithPath(au.com.dius.pact.consumer.dsl.PactDslRequestWithPath)

Example 2 with PactDslRequestWithPath

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;
}
Also used : DslProperty(org.springframework.cloud.contract.spec.internal.DslProperty) Request(org.springframework.cloud.contract.spec.internal.Request) DslPart(au.com.dius.pact.consumer.dsl.DslPart) PactDslRequestWithPath(au.com.dius.pact.consumer.dsl.PactDslRequestWithPath)

Example 3 with PactDslRequestWithPath

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;
}
Also used : PactDslWithState(au.com.dius.pact.consumer.dsl.PactDslWithState) Request(org.springframework.cloud.contract.spec.internal.Request) PactDslRequestWithPath(au.com.dius.pact.consumer.dsl.PactDslRequestWithPath)

Example 4 with PactDslRequestWithPath

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;
}
Also used : DslProperty(org.springframework.cloud.contract.spec.internal.DslProperty) Request(org.springframework.cloud.contract.spec.internal.Request) DslPart(au.com.dius.pact.consumer.dsl.DslPart) PactDslRequestWithPath(au.com.dius.pact.consumer.dsl.PactDslRequestWithPath)

Aggregations

PactDslRequestWithPath (au.com.dius.pact.consumer.dsl.PactDslRequestWithPath)4 Request (org.springframework.cloud.contract.spec.internal.Request)3 DslPart (au.com.dius.pact.consumer.dsl.DslPart)2 DslProperty (org.springframework.cloud.contract.spec.internal.DslProperty)2 PactDslResponse (au.com.dius.pact.consumer.dsl.PactDslResponse)1 PactDslWithProvider (au.com.dius.pact.consumer.dsl.PactDslWithProvider)1 PactDslWithState (au.com.dius.pact.consumer.dsl.PactDslWithState)1 Contract (org.springframework.cloud.contract.spec.Contract)1