Search in sources :

Example 1 with PactBrokerClient

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

Aggregations

Pact (au.com.dius.pact.model.Pact)1 PactReader (au.com.dius.pact.model.PactReader)1 ConsumerInfo (au.com.dius.pact.provider.ConsumerInfo)1 PactBrokerClient (au.com.dius.pact.provider.broker.PactBrokerClient)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 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 java.util (java.util)1 Collectors.toList (java.util.stream.Collectors.toList)1 StringUtils (org.apache.commons.lang3.StringUtils)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1