use of au.com.dius.pact.consumer.dsl.PactDslWithState in project pact-jvm by DiUS.
the class PactRule method getPacts.
/**
* scan all methods for @Pact annotation and execute them, if not already initialized
* @return
*/
protected Map<String, PactFragment> getPacts() {
if (fragments == null) {
fragments = new HashMap<String, PactFragment>();
for (Method m : target.getClass().getMethods()) {
if (conformsToSigniture(m)) {
Pact pact = m.getAnnotation(Pact.class);
PactDslWithState dslBuilder = ConsumerPactBuilder.consumer(pact.consumer()).hasPactWith(pact.provider()).given(pact.state());
try {
fragments.put(pact.state(), (PactFragment) m.invoke(target, dslBuilder));
} catch (Exception e) {
LOGGER.error("Failed to invoke pact method", e);
throw new RuntimeException("Failed to invoke pact method", e);
}
}
}
}
return fragments;
}
Aggregations