Search in sources :

Example 1 with PactDslWithProvider

use of au.com.dius.pact.consumer.dsl.PactDslWithProvider in project pact-jvm by DiUS.

the class BaseProviderRule method conformsToSignature.

/**
   * validates method signature as described at {@link Pact}
   */
private boolean conformsToSignature(Method m) {
    Pact pact = m.getAnnotation(Pact.class);
    boolean conforms = pact != null && RequestResponsePact.class.isAssignableFrom(m.getReturnType()) && m.getParameterTypes().length == 1 && m.getParameterTypes()[0].isAssignableFrom(PactDslWithProvider.class);
    if (!conforms && pact != null) {
        throw new UnsupportedOperationException("Method " + m.getName() + " does not conform required method signature 'public RequestResponsePact xxx(PactDslWithProvider builder)'");
    }
    return conforms;
}
Also used : RequestResponsePact(au.com.dius.pact.model.RequestResponsePact) RequestResponsePact(au.com.dius.pact.model.RequestResponsePact) PactDslWithProvider(au.com.dius.pact.consumer.dsl.PactDslWithProvider)

Example 2 with PactDslWithProvider

use of au.com.dius.pact.consumer.dsl.PactDslWithProvider in project pact-jvm by DiUS.

the class PactProviderRule method evaluatePactVerifications.

private void evaluatePactVerifications(PactVerifications pactVerifications, Statement base) throws Throwable {
    Optional<PactVerification> possiblePactVerification = findPactVerification(pactVerifications);
    if (!possiblePactVerification.isPresent()) {
        base.evaluate();
        return;
    }
    PactVerification pactVerification = possiblePactVerification.get();
    Optional<Method> possiblePactMethod = findPactMethod(pactVerification);
    if (!possiblePactMethod.isPresent()) {
        throw new UnsupportedOperationException("Could not find method with @Pact for the provider " + provider);
    }
    Method method = possiblePactMethod.get();
    Pact pact = method.getAnnotation(Pact.class);
    PactDslWithProvider dslBuilder = ConsumerPactBuilder.consumer(pact.consumer()).hasPactWith(provider);
    PactFragment pactFragment;
    try {
        pactFragment = (PactFragment) method.invoke(target, dslBuilder);
    } catch (Exception e) {
        throw new RuntimeException("Failed to invoke pact method", e);
    }
    VerificationResult result = runPactTest(base, pactFragment);
    validateResult(result, pactVerification);
}
Also used : PactFragment(au.com.dius.pact.model.PactFragment) Method(java.lang.reflect.Method) PactDslWithProvider(au.com.dius.pact.consumer.dsl.PactDslWithProvider) SocketException(java.net.SocketException)

Example 3 with PactDslWithProvider

use of au.com.dius.pact.consumer.dsl.PactDslWithProvider in project pact-jvm by DiUS.

the class BaseProviderRule method evaluatePactVerifications.

private void evaluatePactVerifications(PactVerifications pactVerifications, Statement base) throws Throwable {
    Optional<PactVerification> possiblePactVerification = findPactVerification(pactVerifications);
    if (!possiblePactVerification.isPresent()) {
        base.evaluate();
        return;
    }
    PactVerification pactVerification = possiblePactVerification.get();
    Optional<Method> possiblePactMethod = findPactMethod(pactVerification);
    if (!possiblePactMethod.isPresent()) {
        throw new UnsupportedOperationException("Could not find method with @Pact for the provider " + provider);
    }
    Method method = possiblePactMethod.get();
    Pact pactAnnotation = method.getAnnotation(Pact.class);
    PactDslWithProvider dslBuilder = ConsumerPactBuilder.consumer(pactAnnotation.consumer()).hasPactWith(provider);
    RequestResponsePact pact;
    try {
        pact = (RequestResponsePact) method.invoke(target, dslBuilder);
    } catch (Exception e) {
        throw new RuntimeException("Failed to invoke pact method", e);
    }
    PactVerificationResult result = runPactTest(base, pact);
    validateResult(result, pactVerification);
}
Also used : RequestResponsePact(au.com.dius.pact.model.RequestResponsePact) RequestResponsePact(au.com.dius.pact.model.RequestResponsePact) Method(java.lang.reflect.Method) PactDslWithProvider(au.com.dius.pact.consumer.dsl.PactDslWithProvider)

Aggregations

PactDslWithProvider (au.com.dius.pact.consumer.dsl.PactDslWithProvider)3 RequestResponsePact (au.com.dius.pact.model.RequestResponsePact)2 Method (java.lang.reflect.Method)2 PactFragment (au.com.dius.pact.model.PactFragment)1 SocketException (java.net.SocketException)1