本文整理汇总了Java中au.com.dius.pact.model.Pact类的典型用法代码示例。如果您正苦于以下问题:Java Pact类的具体用法?Java Pact怎么用?Java Pact使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pact类属于au.com.dius.pact.model包,在下文中一共展示了Pact类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
@Override
public List<Pact> load(String providerName) throws IOException {
if ("broker".equals(System.getProperty("pactSource"))) {
Properties properties = new Properties();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("config/pact.properties"));
String host = properties.getProperty("host", "localhost");
String port = properties.getProperty("port", "80");
String protocol = properties.getProperty("protocol", "https");
String username = properties.getProperty("username");
String password = properties.getProperty("password");
String tags = System.getProperty("pactTags");
List<String> tagsList = StringUtils.isNotBlank(tags) ? Arrays.asList(tags.split(",")) : Collections.emptyList();
PactBrokerLoader pbl = new PactBrokerLoader(new PactBrokerImpl(host, port, protocol, username, password, tagsList));
return pbl.load(providerName);
} else {
PactFolderLoader pfl = new PactFolderLoader("pacts");
return pfl.load(providerName);
}
}
示例2: loadContractFiles
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
protected List<Pact> loadContractFiles(List<URI> contracts, String providerName) {
if (contracts != null) {
List<URI> contractFiles = contracts.stream()
.filter(uri -> uri.toString().endsWith(".json"))
.collect(toList());
if (contractFiles != null) {
return contractFiles.stream()
.map(URI::toString)
.map(PactReader::loadPact)
.filter(pact -> pact.getProvider().getName().equals(providerName))
.collect(Collectors.toList());
}
}
return new ArrayList<>();
}
示例3: should_load_pacts_from_annotation_test
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
@Test
public void should_load_pacts_from_annotation_test() {
// Given
final PactsRetriever pactsRetriever = new PactsRetriever();
pactsRetriever.pactsInstanceProducer = instanceProducer;
pactsRetriever.algeronProviderConfigurationInstance = instance;
// When
pactsRetriever.retrievePacts(new BeforeClass(PactDefinition.class));
// Then
verify(instanceProducer).set(argumentCaptor.capture());
Pacts pacts = argumentCaptor.getValue();
final List<Pact> listOfLoadedPacts = pacts.getPacts();
assertThat(listOfLoadedPacts).hasSize(1).element(0)
.hasFieldOrPropertyWithValue("provider", new au.com.dius.pact.model.Provider("planets_provider"))
.hasFieldOrPropertyWithValue("consumer", new Consumer("planets_consumer"));
}
示例4: getPacts
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
protected List<Pact> getPacts(BeforeClass test) {
final TestClass testClass = test.getTestClass();
final Provider providerInfo = testClass.getAnnotation(Provider.class);
if (providerInfo == null) {
return Collections.emptyList();
}
final String serviceName = providerInfo.value();
final Consumer consumerInfo = testClass.getAnnotation(Consumer.class);
final String consumerName = consumerInfo != null ? consumerInfo.value() : null;
List<Pact> pacts;
try {
final ContractsRetriever contractsSource =
getContractsSource(testClass, algeronProviderConfigurationInstance.get());
contractsSource.setProviderName(serviceName);
final List<URI> contractsDirectory = contractsSource.retrieve();
pacts = loadContractFiles(contractsDirectory, serviceName).stream()
.filter(p -> consumerName == null || p.getConsumer().getName().equals(consumerName))
.collect(toList());
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
return pacts;
}
示例5: setup
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
@Before
public void setup() {
final PactsRetriever pactsRetriever = new PactsRetriever();
pactsRetriever.algeronProviderConfigurationInstance = algeronConfiguration;
final List<Pact> pacts = pactsRetriever.getPacts(new BeforeClass(PactProvider.class));
pactsInstance = () -> new Pacts(pacts);
when(eventContext.getEvent()).thenReturn(test);
}
示例6: should_load_pacts_from_algeron_provider_configuration
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
@Test
public void should_load_pacts_from_algeron_provider_configuration() {
// Given
final PactsRetriever pactsRetriever = new PactsRetriever();
pactsRetriever.pactsInstanceProducer = instanceProducer;
pactsRetriever.algeronProviderConfigurationInstance = instance;
String retriever = "provider: folder" + System.lineSeparator() + "contractsFolder: pacts";
final Map<String, String> configuration = new HashMap<>();
configuration.put("retrieverConfiguration", retriever);
final AlgeronProviderConfiguration algeronProviderConfiguration =
AlgeronProviderConfiguration.fromMap(configuration);
when(instance.get()).thenReturn(algeronProviderConfiguration);
// When
pactsRetriever.retrievePacts(new BeforeClass(NonePactDefinition.class));
// Then
verify(instanceProducer).set(argumentCaptor.capture());
Pacts pacts = argumentCaptor.getValue();
final List<Pact> listOfLoadedPacts = pacts.getPacts();
assertThat(listOfLoadedPacts).hasSize(1).element(0)
.hasFieldOrPropertyWithValue("provider", new au.com.dius.pact.model.Provider("planets_provider"))
.hasFieldOrPropertyWithValue("consumer", new Consumer("planets_consumer"));
}
示例7: shouldNotSetUpStateIfInteractionDidNotSpecifyState
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
@Test
public void shouldNotSetUpStateIfInteractionDidNotSpecifyState() {
Request request = someRequest();
Response expectedResponse = emptySuccessResponse();
Pact pact = Pact.apply(Provider.apply("someProvider"), Consumer.apply("someConsumer"), of(Interaction.apply("someDescription", Option.empty(), request, expectedResponse)));
when(providerClientMock.makeRequest(any(Request.class)))
.thenReturn(expectedResponse);
subject.evaluate(pact);
verify(stateProviderMock,never()).setState(anyString());
}
示例8: shouldSetUpStateIfSpecifiedInInteraction
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
@Test
public void shouldSetUpStateIfSpecifiedInInteraction() {
Request request = someRequest();
Response expectedResponse = emptySuccessResponse();
Pact pact = Pact.apply(Provider.apply("someProvider"), Consumer.apply("someConsumer"), of(Interaction.apply("someDescription", Option.apply("someState"), request, expectedResponse)));
when(providerClientMock.makeRequest(any(Request.class)))
.thenReturn(expectedResponse);
subject.evaluate(pact);
verify(stateProviderMock).setState("someState");
}
示例9: shouldMakeGetRequest
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
@Test
public void shouldMakeGetRequest() {
Request request = someRequest();
Response expectedResponse = emptySuccessResponse();
Pact pact = Pact.apply(Provider.apply("someProvider"), Consumer.apply("someConsumer"), of(Interaction.apply("someDescription", Option.empty(), request, expectedResponse)));
when(providerClientMock.makeRequest(any(Request.class)))
.thenReturn(expectedResponse);
subject.evaluate(pact);
verify(providerClientMock).makeRequest(request);
}
示例10: Pacts
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
public Pacts(List<Pact> pacts) {
this.pacts = new ArrayList<>(pacts);
}
示例11: getPacts
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
public List<Pact> getPacts() {
return pacts;
}
示例12: retrievePacts
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
public void retrievePacts(@Observes BeforeClass test) {
List<Pact> pacts = getPacts(test);
if (!pacts.isEmpty()) {
pactsInstanceProducer.set(new Pacts(pacts));
}
}
示例13: warnPactFileHasNoInteractions
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
@Override
public void warnPactFileHasNoInteractions(Pact pact) {
appendTextEntry("WARNING: Pact file has no interactions", this.verificationGroup);
}
示例14: executePacts
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
private void executePacts(EventContext<Test> test, final Pacts pacts, final Field interactionField,
final Field consumerField) {
final TestClass testClass = test.getEvent().getTestClass();
final Object testInstance = test.getEvent().getTestInstance();
for (Pact pact : pacts.getPacts()) {
RequestResponsePact requestResponsePact = (RequestResponsePact) pact;
// Inject current consumer
if (consumerField != null) {
setField(testInstance, consumerField, pact.getConsumer());
}
for (final RequestResponseInteraction interaction : requestResponsePact.getInteractions()) {
executeStateChanges(interaction, testClass, testInstance);
Target target = targetInstance.get();
if (target instanceof ArquillianTestClassAwareTarget) {
ArquillianTestClassAwareTarget arquillianTestClassAwareTarget =
(ArquillianTestClassAwareTarget) target;
arquillianTestClassAwareTarget.setTestClass(testClass, testInstance);
}
if (target instanceof PactProviderExecutionAwareTarget) {
PactProviderExecutionAwareTarget pactProviderExecutionAwareTarget =
(PactProviderExecutionAwareTarget) target;
pactProviderExecutionAwareTarget.setConsumer(pact.getConsumer());
pactProviderExecutionAwareTarget.setRequestResponseInteraction(interaction);
}
// Inject current interaction to test
if (interactionField != null) {
setField(testInstance, interactionField, interaction);
}
// run the test
test.proceed();
}
}
}
示例15: evaluate
import au.com.dius.pact.model.Pact; //导入依赖的package包/类
public ImmutableList<ResponsePartMismatch> evaluate(Pact pact) {
return fromSeq(pact.interactions()).stream()
.flatMap(this::evaluateInteraction)
.collect(toImmutableList());
}