public class CachingConsumerTest {
@Rule
public PactProviderRule mockTestProvider = new PactProviderRule("test_provider", "localhost", 8080, this);
@Pact(provider = "test_provider", consumer = "test_consumer")
protected PactFragment createFragment(PactDslWithProvider builder) {
return builder
.uponReceiving("a request for something")
.path("/v1/event-publish/node-topics")
.method("GET")
.willRespondWith()
.status(200)
.body("{\"responsetest\":true}").toFragment();
}
@Test
@PactVerification("test_provider")
public void runTest() throws IOException {
EventPublisherClientConfiguration clientConfiguration = new EventPublisherClientConfiguration();
clientConfiguration.setBaseUrl("http://localhost:8080");
clientConfiguration.setTimeout(Duration.seconds(30));
EventPublisherClient client = new EventPublisherClient(clientConfiguration);
assertEquals(client.build().findAll(""), "{\"responsetest\":true}");
}
}
--
You received this message because you are subscribed to the Google Groups "Pact" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pact-support...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import au.com.dius.pact.consumer.Pact;import au.com.dius.pact.consumer.PactProviderRule;import au.com.dius.pact.consumer.PactVerification;import au.com.dius.pact.consumer.dsl.PactDslWithProvider;import au.com.dius.pact.model.PactFragment;import org.junit.Rule;import org.junit.Test;import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import java.io.IOException;import java.util.HashMap;import java.util.Map;
import static org.junit.Assert.assertEquals;
public class PactRuleWithRandomPortTest { Logger LOGGER = LoggerFactory.getLogger(PactRuleWithRandomPortTest.class); @Rule public PactProviderRule rule = new PactProviderRule("test_provider", this);
@Pact(provider="test_provider", consumer="test_consumer") public PactFragment createFragment(PactDslWithProvider builder) { return builder .given("test state") .uponReceiving("random port test interaction") .path("/")
.method("GET") .willRespondWith() .status(200)
.body("{\"ok\": true}")
.toFragment(); }
@Test @PactVerification("test_provider") public void runTest() throws IOException {
Map expectedResponse = new HashMap(); expectedResponse.put("ok", true); assertEquals(new ConsumerClient("http://localhost:" + rule.getConfig().port()).getAsMap("/", ""), expectedResponse); }}