Search in sources :

Example 11 with ConsumerClient

use of au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient in project pact-jvm by DiUS.

the class PactProviderTest method runTestWithPactError.

@Test
@PactVerification(value = "test_provider")
public void runTestWithPactError() throws IOException {
    mockTestProvider.validateResultWith((result, t) -> {
        assertThat(t, is(instanceOf(AssertionError.class)));
        assertThat(t.getMessage(), startsWith("The following requests were not received:\n" + "\tmethod: GET\n" + "\tpath: /"));
        assertThat(result, is(instanceOf(PactVerificationResult.ExpectedButNotReceived.class)));
        PactVerificationResult.ExpectedButNotReceived error = (PactVerificationResult.ExpectedButNotReceived) result;
        assertThat(error.getExpectedRequests(), hasSize(1));
        IRequest request = error.getExpectedRequests().get(0);
        assertThat(request.getPath(), is("/"));
    });
    Assert.assertEquals(new ConsumerClient(mockTestProvider.getUrl()).options("/second"), 200);
}
Also used : ConsumerClient(au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient) IRequest(au.com.dius.pact.core.model.IRequest) PactVerificationResult(au.com.dius.pact.consumer.PactVerificationResult) PactVerification(au.com.dius.pact.consumer.junit.PactVerification) Test(org.junit.Test)

Example 12 with ConsumerClient

use of au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient in project pact-jvm by DiUS.

the class PactProviderTest method runTestWithUserCodeFailure.

@Test
@PactVerification("test_provider")
public void runTestWithUserCodeFailure() throws IOException {
    mockTestProvider.validateResultWith((result, t) -> {
        assertThat(t, is(instanceOf(AssertionError.class)));
        assertThat(t.getMessage(), is("Pact Test function failed with an exception: expected:" + "<{responsetest=true, name=harry}> but was:<{responsetest=true, name=fred}>"));
        assertThat(result, is(instanceOf(PactVerificationResult.Error.class)));
        PactVerificationResult.Error error = (PactVerificationResult.Error) result;
        assertThat(error.getMockServerState(), is(instanceOf(PactVerificationResult.Ok.class)));
        assertThat(error.getError(), is(instanceOf(AssertionError.class)));
    });
    Assert.assertEquals(new ConsumerClient(mockTestProvider.getUrl()).options("/second"), 200);
    Map expectedResponse = new HashMap();
    expectedResponse.put("responsetest", true);
    expectedResponse.put("name", "fred");
    assertEquals(new ConsumerClient(mockTestProvider.getUrl()).getAsMap("/", ""), expectedResponse);
}
Also used : ConsumerClient(au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) PactVerificationResult(au.com.dius.pact.consumer.PactVerificationResult) PactVerification(au.com.dius.pact.consumer.junit.PactVerification) Test(org.junit.Test)

Example 13 with ConsumerClient

use of au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient in project pact-jvm by DiUS.

the class UnexpectedRequestConsumerPassesTest method runTest.

@Override
protected void runTest(MockServer mockServer, PactTestExecutionContext context) throws IOException {
    Map<String, Object> expectedResponse = new HashMap<String, Object>();
    expectedResponse.put("responsetest", true);
    expectedResponse.put("name", "fred");
    ConsumerClient consumerClient = new ConsumerClient(mockServer.getUrl());
    assertEquals(consumerClient.getAsMap("/", ""), expectedResponse);
    consumerClient.options("/options");
}
Also used : ConsumerClient(au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 14 with ConsumerClient

use of au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient in project pact-jvm by DiUS.

the class ExampleJavaConsumerPactTest method runTest.

@Override
protected void runTest(MockServer mockServer, PactTestExecutionContext context) throws IOException {
    Assert.assertEquals(new ConsumerClient(mockServer.getUrl()).options("/second"), 200);
    Map expectedResponse = new HashMap();
    expectedResponse.put("responsetest", true);
    expectedResponse.put("name", "harry");
    assertEquals(new ConsumerClient(mockServer.getUrl()).getAsMap("/", ""), expectedResponse);
    assertEquals(new ConsumerClient(mockServer.getUrl()).options("/second"), 200);
}
Also used : ConsumerClient(au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with ConsumerClient

use of au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient in project pact-jvm by DiUS.

the class PactMultiProviderTest method doTest.

private void doTest(String path, String json) throws IOException {
    ConsumerClient consumerClient = new ConsumerClient(mockTestProvider.getUrl());
    consumerClient.options("/second");
    try {
        consumerClient.getAsMap(path, "");
    } catch (IOException e) {
    }
    try {
        new ConsumerClient(mockTestProvider2.getUrl()).putAsMap("/", json);
    } catch (IOException e) {
    }
}
Also used : ConsumerClient(au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient) IOException(java.io.IOException)

Aggregations

ConsumerClient (au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient)19 Map (java.util.Map)14 HashMap (java.util.HashMap)13 Test (org.junit.Test)13 PactVerification (au.com.dius.pact.consumer.junit.PactVerification)9 PactVerificationResult (au.com.dius.pact.consumer.PactVerificationResult)2 PactVerifications (au.com.dius.pact.consumer.junit.PactVerifications)2 IOException (java.io.IOException)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 IRequest (au.com.dius.pact.core.model.IRequest)1 HttpResponseException (org.apache.hc.client5.http.HttpResponseException)1