Search in sources :

Example 31 with Pact

use of au.com.dius.pact.core.model.annotations.Pact 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)31 MessagePact (au.com.dius.pact.core.model.messaging.MessagePact)21 PactDslJsonBody (au.com.dius.pact.consumer.dsl.PactDslJsonBody)19 HashMap (java.util.HashMap)18 RequestResponsePact (au.com.dius.pact.core.model.RequestResponsePact)14 Method (java.lang.reflect.Method)5 MessagePactBuilder (au.com.dius.pact.consumer.MessagePactBuilder)4 DslPart (au.com.dius.pact.consumer.dsl.DslPart)4 PactDslJsonArray (au.com.dius.pact.consumer.dsl.PactDslJsonArray)3 MatchingRuleGroup (au.com.dius.pact.core.model.matchingrules.MatchingRuleGroup)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 PactDslWithProvider (au.com.dius.pact.consumer.dsl.PactDslWithProvider)2 BasePact (au.com.dius.pact.core.model.BasePact)2 ProviderState (au.com.dius.pact.core.model.ProviderState)2 PactDirectory (au.com.dius.pact.core.model.annotations.PactDirectory)2 PactFolder (au.com.dius.pact.core.model.annotations.PactFolder)2 MatchingRules (au.com.dius.pact.core.model.matchingrules.MatchingRules)2 RegexMatcher (au.com.dius.pact.core.model.matchingrules.RegexMatcher)2 Message (au.com.dius.pact.core.model.messaging.Message)2 PactVerificationResult (au.com.dius.pact.consumer.PactVerificationResult)1