Search in sources :

Example 1 with PactDslWithState

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;
}
Also used : PactFragment(au.com.dius.pact.model.PactFragment) PactDslWithState(au.com.dius.pact.consumer.dsl.PactDslWithState) Method(java.lang.reflect.Method)

Aggregations

PactDslWithState (au.com.dius.pact.consumer.dsl.PactDslWithState)1 PactFragment (au.com.dius.pact.model.PactFragment)1 Method (java.lang.reflect.Method)1