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;
}
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();
}
}
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);
}
}
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();
}
}
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();
}
}
Aggregations