use of au.com.dius.pact.consumer.junit.exampleclients.ProviderClient in project pact-jvm by DiUS.
the class DirectDSLConsumerPactTest method testPact.
@Test
public void testPact() {
RequestResponsePact pact = ConsumerPactBuilder.consumer("Some Consumer").hasPactWith("Some Provider").uponReceiving("a request to say Hello").path("/hello").method("POST").body("{\"name\": \"harry\"}").willRespondWith().status(200).body("{\"hello\": \"harry\"}").toPact();
MockProviderConfig config = MockProviderConfig.createDefault();
PactVerificationResult result = runConsumerTest(pact, config, (mockServer, context) -> {
Map expectedResponse = new HashMap();
expectedResponse.put("hello", "harry");
try {
assertEquals(new ProviderClient(mockServer.getUrl()).hello("{\"name\": \"harry\"}"), expectedResponse);
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
});
if (result instanceof PactVerificationResult.Error) {
throw new RuntimeException(((PactVerificationResult.Error) result).getError());
}
assertThat(result, is(instanceOf(PactVerificationResult.Ok.class)));
}
Aggregations