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