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);
}
Aggregations