Search in sources :

Example 1 with ProviderClient

use of au.com.dius.pact.consumer.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 -> {
        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);
        }
    });
    if (result instanceof PactVerificationResult.Error) {
        throw new RuntimeException(((PactVerificationResult.Error) result).getError());
    }
    assertEquals(PactVerificationResult.Ok.INSTANCE, result);
}
Also used : ProviderClient(au.com.dius.pact.consumer.exampleclients.ProviderClient) HashMap(java.util.HashMap) MockProviderConfig(au.com.dius.pact.model.MockProviderConfig) RequestResponsePact(au.com.dius.pact.model.RequestResponsePact) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) 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.exampleclients.ProviderClient)1 MockProviderConfig (au.com.dius.pact.model.MockProviderConfig)1 RequestResponsePact (au.com.dius.pact.model.RequestResponsePact)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1