Search in sources :

Example 1 with MvcProviderVerifier

use of au.com.dius.pact.provider.spring.MvcProviderVerifier in project pact-jvm by DiUS.

the class MockMvcTarget method testInteraction.

/**
     * {@inheritDoc}
     */
@Override
public void testInteraction(final String consumerName, final Interaction interaction) {
    ProviderInfo provider = getProviderInfo();
    ConsumerInfo consumer = new ConsumerInfo(consumerName);
    provider.setVerificationType(PactVerification.ANNOTATED_METHOD);
    MockMvc mockMvc = standaloneSetup(controllers.toArray()).setControllerAdvice(controllerAdvice.toArray()).build();
    MvcProviderVerifier verifier = (MvcProviderVerifier) setupVerifier(interaction, provider, consumer);
    Map<String, Object> failures = new HashMap<>();
    for (int i = 0; i < runTimes; i++) {
        verifier.verifyResponseFromProvider(provider, interaction, interaction.getDescription(), failures, mockMvc);
    }
    try {
        if (!failures.isEmpty()) {
            verifier.displayFailures(failures);
            throw getAssertionError(failures);
        }
    } finally {
        verifier.finialiseReports();
    }
}
Also used : ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) MvcProviderVerifier(au.com.dius.pact.provider.spring.MvcProviderVerifier) MockMvc(org.springframework.test.web.servlet.MockMvc)

Example 2 with MvcProviderVerifier

use of au.com.dius.pact.provider.spring.MvcProviderVerifier in project pact-jvm by DiUS.

the class MockMvcTarget method setupVerifier.

@Override
protected ProviderVerifier setupVerifier(Interaction interaction, ProviderInfo provider, ConsumerInfo consumer) {
    MvcProviderVerifier verifier = new MvcProviderVerifier();
    verifier.setDebugRequestResponse(printRequestResponse);
    setupReporters(verifier, provider.getName(), interaction.getDescription());
    verifier.setProjectClasspath(new MethodClosure(this, "getClassPathUrls"));
    verifier.initialiseReporters(provider);
    verifier.reportVerificationForConsumer(consumer, provider);
    if (interaction.getProviderState() != null) {
        verifier.reportStateForInteraction(interaction.getProviderState(), provider, consumer, true);
    }
    verifier.reportInteractionDescription(interaction);
    return verifier;
}
Also used : MvcProviderVerifier(au.com.dius.pact.provider.spring.MvcProviderVerifier) MethodClosure(org.codehaus.groovy.runtime.MethodClosure)

Aggregations

MvcProviderVerifier (au.com.dius.pact.provider.spring.MvcProviderVerifier)2 ConsumerInfo (au.com.dius.pact.provider.ConsumerInfo)1 ProviderInfo (au.com.dius.pact.provider.ProviderInfo)1 MethodClosure (org.codehaus.groovy.runtime.MethodClosure)1 MockMvc (org.springframework.test.web.servlet.MockMvc)1