Search in sources :

Example 6 with MockProviderConfig

use of au.com.dius.pact.consumer.model.MockProviderConfig in project pact-jvm by DiUS.

the class ConsumerPactTest method testPact.

@Test
public void testPact() throws Throwable {
    RequestResponsePact pact = createPact(ConsumerPactBuilder.consumer(consumerName()).hasPactWith(providerName()));
    final MockProviderConfig config = MockProviderConfig.createDefault(getSpecificationVersion());
    PactVerificationResult result = runConsumerTest(pact, config, (mockServer, context) -> {
        runTest(mockServer, context);
        return null;
    });
    Metrics.INSTANCE.sendMetrics(new MetricEvent.ConsumerTestRun(pact.getInteractions().size(), "junit"));
    if (!(result instanceof PactVerificationResult.Ok)) {
        if (result instanceof PactVerificationResult.Error) {
            PactVerificationResult.Error error = (PactVerificationResult.Error) result;
            if (!(error.getMockServerState() instanceof PactVerificationResult.Ok)) {
                throw new AssertionError("Pact Test function failed with an exception, possibly due to " + error.getMockServerState(), ((PactVerificationResult.Error) result).getError());
            } else {
                throw new AssertionError("Pact Test function failed with an exception: " + error.getError().getMessage(), error.getError());
            }
        } else {
            throw new PactMismatchesException(result);
        }
    }
}
Also used : MockProviderConfig(au.com.dius.pact.consumer.model.MockProviderConfig) MetricEvent(au.com.dius.pact.core.support.MetricEvent) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact) PactMismatchesException(au.com.dius.pact.consumer.PactMismatchesException) PactVerificationResult(au.com.dius.pact.consumer.PactVerificationResult) ConsumerPactRunnerKt.runConsumerTest(au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest) Test(org.junit.Test)

Aggregations

MockProviderConfig (au.com.dius.pact.consumer.model.MockProviderConfig)6 RequestResponsePact (au.com.dius.pact.core.model.RequestResponsePact)3 IOException (java.io.IOException)3 ConsumerPactRunnerKt.runConsumerTest (au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest)2 PactVerificationResult (au.com.dius.pact.consumer.PactVerificationResult)2 Map (java.util.Map)2 Test (org.junit.Test)2 PactMismatchesException (au.com.dius.pact.consumer.PactMismatchesException)1 ProviderClient (au.com.dius.pact.consumer.junit.exampleclients.ProviderClient)1 MetricEvent (au.com.dius.pact.core.support.MetricEvent)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1