Search in sources :

Example 1 with ProviderClient

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)));
}
Also used : ProviderClient(au.com.dius.pact.consumer.junit.exampleclients.ProviderClient) HashMap(java.util.HashMap) MockProviderConfig(au.com.dius.pact.consumer.model.MockProviderConfig) RequestResponsePact(au.com.dius.pact.core.model.RequestResponsePact) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) PactVerificationResult(au.com.dius.pact.consumer.PactVerificationResult) ConsumerPactRunnerKt.runConsumerTest(au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest) Test(org.junit.Test)

Aggregations

ConsumerPactRunnerKt.runConsumerTest (au.com.dius.pact.consumer.ConsumerPactRunnerKt.runConsumerTest)1 PactVerificationResult (au.com.dius.pact.consumer.PactVerificationResult)1 ProviderClient (au.com.dius.pact.consumer.junit.exampleclients.ProviderClient)1 MockProviderConfig (au.com.dius.pact.consumer.model.MockProviderConfig)1 RequestResponsePact (au.com.dius.pact.core.model.RequestResponsePact)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1