Search in sources :

Example 1 with ProviderVerifier

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

the class AmqpTarget method setupVerifier.

protected ProviderVerifier setupVerifier(Interaction interaction, ProviderInfo provider, ConsumerInfo consumer) {
    ProviderVerifier verifier = new ProviderVerifier();
    verifier.setProjectClasspath(new MethodClosure(this, "getClassPathUrls"));
    setupReporters(verifier, provider.getName(), interaction.getDescription());
    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 : MethodClosure(org.codehaus.groovy.runtime.MethodClosure) ProviderVerifier(au.com.dius.pact.provider.ProviderVerifier)

Example 2 with ProviderVerifier

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

the class HttpTarget method setupVerifier.

@Override
protected ProviderVerifier setupVerifier(Interaction interaction, ProviderInfo provider, ConsumerInfo consumer) {
    ProviderVerifier verifier = new ProviderVerifier();
    setupReporters(verifier, provider.getName(), interaction.getDescription());
    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 : ProviderVerifier(au.com.dius.pact.provider.ProviderVerifier)

Example 3 with ProviderVerifier

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

the class HttpTarget method testInteraction.

/**
     * {@inheritDoc}
     */
@Override
public void testInteraction(final String consumerName, final Interaction interaction) {
    ProviderInfo provider = getProviderInfo();
    ConsumerInfo consumer = new ConsumerInfo(consumerName);
    ProviderVerifier verifier = setupVerifier(interaction, provider, consumer);
    Map<String, Object> failures = new HashMap<>();
    verifier.verifyResponseFromProvider(provider, interaction, interaction.getDescription(), failures);
    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) HashMap(java.util.HashMap) ProviderVerifier(au.com.dius.pact.provider.ProviderVerifier)

Example 4 with ProviderVerifier

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

the class AmqpTarget method testInteraction.

/**
     * {@inheritDoc}
     */
@Override
public void testInteraction(final String consumerName, final Interaction interaction) {
    ProviderInfo provider = getProviderInfo();
    ConsumerInfo consumer = new ConsumerInfo(consumerName);
    ProviderVerifier verifier = setupVerifier(interaction, provider, consumer);
    Map<String, Object> failures = new HashMap<>();
    verifier.verifyResponseByInvokingProviderMethods(provider, consumer, interaction, interaction.getDescription(), failures);
    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) HashMap(java.util.HashMap) ProviderVerifier(au.com.dius.pact.provider.ProviderVerifier)

Example 5 with ProviderVerifier

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

the class BaseTarget method setupReporters.

protected void setupReporters(ProviderVerifier verifier, String name, String description) {
    String reportDirectory = "target/pact/reports";
    String[] reports = new String[] {};
    boolean reportingEnabled = false;
    VerificationReports verificationReports = testClass.getAnnotation(VerificationReports.class);
    if (verificationReports != null) {
        reportingEnabled = true;
        reportDirectory = verificationReports.reportDir();
        reports = verificationReports.value();
    } else if (valueResolver.propertyDefined("pact.verification.reports")) {
        reportingEnabled = true;
        reportDirectory = valueResolver.resolveValue("pact.verification.reportDir:" + reportDirectory);
        reports = valueResolver.resolveValue("pact.verification.reports:").split(",");
    }
    if (reportingEnabled) {
        File reportDir = new File(reportDirectory);
        reportDir.mkdirs();
        verifier.setReporters(Seq.of(reports).filter(r -> !r.isEmpty()).map(r -> {
            VerifierReporter reporter = ReporterManager.createReporter(r.trim());
            reporter.setReportDir(reportDir);
            reporter.setReportFile(new File(reportDir, name + " - " + description + reporter.getExt()));
            return reporter;
        }).toList());
    }
}
Also used : SystemPropertyResolver(au.com.dius.pact.provider.junit.sysprops.SystemPropertyResolver) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) ValueResolver(au.com.dius.pact.provider.junit.sysprops.ValueResolver) Interaction(au.com.dius.pact.model.Interaction) Seq(org.jooq.lambda.Seq) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) File(java.io.File) Tuple2(org.jooq.lambda.tuple.Tuple2) ProviderVerifier(au.com.dius.pact.provider.ProviderVerifier) TestClass(org.junit.runners.model.TestClass) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) Map(java.util.Map) Optional(java.util.Optional) VerifierReporter(au.com.dius.pact.provider.reporters.VerifierReporter) VerificationReports(au.com.dius.pact.provider.junit.VerificationReports) ReporterManager(au.com.dius.pact.provider.reporters.ReporterManager) VerificationReports(au.com.dius.pact.provider.junit.VerificationReports) VerifierReporter(au.com.dius.pact.provider.reporters.VerifierReporter) File(java.io.File)

Aggregations

ProviderVerifier (au.com.dius.pact.provider.ProviderVerifier)5 ConsumerInfo (au.com.dius.pact.provider.ConsumerInfo)3 ProviderInfo (au.com.dius.pact.provider.ProviderInfo)3 HashMap (java.util.HashMap)2 Interaction (au.com.dius.pact.model.Interaction)1 VerificationReports (au.com.dius.pact.provider.junit.VerificationReports)1 SystemPropertyResolver (au.com.dius.pact.provider.junit.sysprops.SystemPropertyResolver)1 ValueResolver (au.com.dius.pact.provider.junit.sysprops.ValueResolver)1 ReporterManager (au.com.dius.pact.provider.reporters.ReporterManager)1 VerifierReporter (au.com.dius.pact.provider.reporters.VerifierReporter)1 File (java.io.File)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 MethodClosure (org.codehaus.groovy.runtime.MethodClosure)1 Seq (org.jooq.lambda.Seq)1 Tuple2 (org.jooq.lambda.tuple.Tuple2)1 TestClass (org.junit.runners.model.TestClass)1