Search in sources :

Example 1 with ConsumerInfo

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

the class AmqpTarget method getProviderInfo.

protected ProviderInfo getProviderInfo() {
    Provider provider = testClass.getAnnotation(Provider.class);
    ProviderInfo providerInfo = new ProviderInfo(provider.value());
    providerInfo.setVerificationType(PactVerification.ANNOTATED_METHOD);
    providerInfo.setPackagesToScan(packagesToScan);
    PactBroker annotation = testClass.getAnnotation(PactBroker.class);
    PactFolder folder = testClass.getAnnotation(PactFolder.class);
    if (annotation != null && annotation.host() != null) {
        List list = providerInfo.hasPactsFromPactBroker(annotation.protocol() + "://" + annotation.host() + (annotation.port() != null ? ":" + annotation.port() : ""));
        providerInfo.setConsumers(list);
    } else if (folder != null && folder.value() != null) {
        try {
            PactFolderLoader folderLoader = new PactFolderLoader(folder);
            Map<Pact, File> pactFileMap = folderLoader.loadPactsWithFiles(providerInfo.getName());
            providerInfo.setConsumers(pactFileMap.entrySet().stream().map(e -> new ConsumerInfo(e.getKey().getConsumer().getName(), e.getValue())).collect(Collectors.toList()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return providerInfo;
}
Also used : PactBroker(au.com.dius.pact.provider.junit.loader.PactBroker) Pact(au.com.dius.pact.model.Pact) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) MethodClosure(org.codehaus.groovy.runtime.MethodClosure) URL(java.net.URL) PactVerification(au.com.dius.pact.provider.PactVerification) IOException(java.io.IOException) HashMap(java.util.HashMap) Interaction(au.com.dius.pact.model.Interaction) PactFolderLoader(au.com.dius.pact.provider.junit.loader.PactFolderLoader) Provider(au.com.dius.pact.provider.junit.Provider) Collectors(java.util.stream.Collectors) File(java.io.File) URLClassLoader(java.net.URLClassLoader) List(java.util.List) ProviderVerifier(au.com.dius.pact.provider.ProviderVerifier) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) Map(java.util.Map) PactFolder(au.com.dius.pact.provider.junit.loader.PactFolder) Collections(java.util.Collections) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) ProviderInfo(au.com.dius.pact.provider.ProviderInfo) PactFolderLoader(au.com.dius.pact.provider.junit.loader.PactFolderLoader) PactBroker(au.com.dius.pact.provider.junit.loader.PactBroker) PactFolder(au.com.dius.pact.provider.junit.loader.PactFolder) List(java.util.List) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Provider(au.com.dius.pact.provider.junit.Provider)

Example 2 with ConsumerInfo

use of au.com.dius.pact.provider.ConsumerInfo 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 3 with ConsumerInfo

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

the class PactBrokerLoader method loadPactsForProvider.

private List<Pact> loadPactsForProvider(final String providerName, final String tag) throws IOException {
    LOGGER.debug("Loading pacts from pact broker for provider " + providerName + " and tag " + tag);
    URIBuilder uriBuilder = new URIBuilder().setScheme(parseExpressions(pactBrokerProtocol)).setHost(parseExpressions(pactBrokerHost)).setPort(Integer.parseInt(parseExpressions(pactBrokerPort)));
    try {
        List<ConsumerInfo> consumers;
        PactBrokerClient pactBrokerClient = newPactBrokerClient(uriBuilder.build());
        if (StringUtils.isEmpty(tag)) {
            consumers = pactBrokerClient.fetchConsumers(providerName);
        } else {
            consumers = pactBrokerClient.fetchConsumersWithTag(providerName, tag);
        }
        if (failIfNoPactsFound && consumers.isEmpty()) {
            throw new NoPactsFoundException("No consumer pacts were found for provider '" + providerName + "' and tag '" + tag + "'. (URL " + pactBrokerClient.getUrlForProvider(providerName, tag) + ")");
        }
        return consumers.stream().map(consumer -> this.loadPact(consumer, pactBrokerClient.getOptions())).collect(toList());
    } catch (URISyntaxException e) {
        throw new IOException("Was not able load pacts from broker as the broker URL was invalid", e);
    }
}
Also used : PactRunnerTagListExpressionParser.parseTagListExpressions(au.com.dius.pact.provider.junit.sysprops.PactRunnerTagListExpressionParser.parseTagListExpressions) java.util(java.util) Logger(org.slf4j.Logger) Pact(au.com.dius.pact.model.Pact) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) URIBuilder(org.apache.http.client.utils.URIBuilder) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) PactRunnerExpressionParser.parseExpressions(au.com.dius.pact.provider.junit.sysprops.PactRunnerExpressionParser.parseExpressions) StringUtils(org.apache.commons.lang3.StringUtils) Collectors.toList(java.util.stream.Collectors.toList) PactReader(au.com.dius.pact.model.PactReader) PactBrokerClient(au.com.dius.pact.provider.broker.PactBrokerClient) URI(java.net.URI) ConsumerInfo(au.com.dius.pact.provider.ConsumerInfo) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) PactBrokerClient(au.com.dius.pact.provider.broker.PactBrokerClient) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 4 with ConsumerInfo

use of au.com.dius.pact.provider.ConsumerInfo 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 ConsumerInfo

use of au.com.dius.pact.provider.ConsumerInfo 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)

Aggregations

ConsumerInfo (au.com.dius.pact.provider.ConsumerInfo)5 ProviderInfo (au.com.dius.pact.provider.ProviderInfo)4 ProviderVerifier (au.com.dius.pact.provider.ProviderVerifier)3 HashMap (java.util.HashMap)3 Pact (au.com.dius.pact.model.Pact)2 IOException (java.io.IOException)2 Interaction (au.com.dius.pact.model.Interaction)1 PactReader (au.com.dius.pact.model.PactReader)1 PactVerification (au.com.dius.pact.provider.PactVerification)1 PactBrokerClient (au.com.dius.pact.provider.broker.PactBrokerClient)1 Provider (au.com.dius.pact.provider.junit.Provider)1 PactBroker (au.com.dius.pact.provider.junit.loader.PactBroker)1 PactFolder (au.com.dius.pact.provider.junit.loader.PactFolder)1 PactFolderLoader (au.com.dius.pact.provider.junit.loader.PactFolderLoader)1 PactRunnerExpressionParser.parseExpressions (au.com.dius.pact.provider.junit.sysprops.PactRunnerExpressionParser.parseExpressions)1 PactRunnerTagListExpressionParser.parseTagListExpressions (au.com.dius.pact.provider.junit.sysprops.PactRunnerTagListExpressionParser.parseTagListExpressions)1 MvcProviderVerifier (au.com.dius.pact.provider.spring.MvcProviderVerifier)1 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1