Search in sources :

Example 21 with MessagePact

use of au.com.dius.pact.core.model.messaging.MessagePact in project pact-jvm by DiUS.

the class MessagePactProviderRule method evaluatePactVerifications.

private void evaluatePactVerifications(PactVerifications pactVerifications, Statement base, Description description) throws Throwable {
    if (provider == null) {
        throw new UnsupportedOperationException("This provider name cannot be null when using @PactVerifications");
    }
    Optional<PactVerification> possiblePactVerification = findPactVerification(pactVerifications);
    if (possiblePactVerification.isEmpty()) {
        base.evaluate();
        return;
    }
    PactVerification pactVerification = possiblePactVerification.get();
    Optional<Method> possiblePactMethod = findPactMethod(pactVerification);
    if (possiblePactMethod.isEmpty()) {
        throw new UnsupportedOperationException("Could not find method with @Pact for the provider " + provider);
    }
    Method method = possiblePactMethod.get();
    Pact pact = method.getAnnotation(Pact.class);
    MessagePactBuilder builder = new MessagePactBuilder().consumer(Objects.toString(ep.parseExpression(pact.consumer(), DataType.RAW))).hasPactWith(provider);
    MessagePact messagePact = (MessagePact) method.invoke(testClassInstance, builder);
    setMessage(messagePact.getMessages().get(0), description);
    base.evaluate();
    messagePact.write(BuiltToolConfig.INSTANCE.getPactDirectory(), PactSpecVersion.V3);
}
Also used : MessagePact(au.com.dius.pact.core.model.messaging.MessagePact) MessagePact(au.com.dius.pact.core.model.messaging.MessagePact) Pact(au.com.dius.pact.core.model.annotations.Pact) MessagePactBuilder(au.com.dius.pact.consumer.MessagePactBuilder) Method(java.lang.reflect.Method)

Aggregations

Pact (au.com.dius.pact.core.model.annotations.Pact)21 MessagePact (au.com.dius.pact.core.model.messaging.MessagePact)21 PactDslJsonBody (au.com.dius.pact.consumer.dsl.PactDslJsonBody)16 HashMap (java.util.HashMap)16 RequestResponsePact (au.com.dius.pact.core.model.RequestResponsePact)5 MessagePactBuilder (au.com.dius.pact.consumer.MessagePactBuilder)4 Method (java.lang.reflect.Method)3 ProviderState (au.com.dius.pact.core.model.ProviderState)2 Message (au.com.dius.pact.core.model.messaging.Message)2 PactDslJsonArray (au.com.dius.pact.consumer.dsl.PactDslJsonArray)1 PactDirectory (au.com.dius.pact.core.model.annotations.PactDirectory)1 PactFolder (au.com.dius.pact.core.model.annotations.PactFolder)1 MetricEvent (au.com.dius.pact.core.support.MetricEvent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Statement (org.junit.runners.model.Statement)1