Search in sources :

Example 6 with ConsumerClient

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

the class ExampleJavaConsumerPactTest method runTest.

@Override
protected void runTest(MockServer mockServer) 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.exampleclients.ConsumerClient) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with ConsumerClient

use of au.com.dius.pact.consumer.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.exampleclients.ConsumerClient) IOException(java.io.IOException)

Example 8 with ConsumerClient

use of au.com.dius.pact.consumer.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));
        Request 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.exampleclients.ConsumerClient) Request(au.com.dius.pact.model.Request) PactVerificationResult(au.com.dius.pact.consumer.PactVerificationResult) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test)

Example 9 with ConsumerClient

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

the class PactProviderTest method runTest.

@Test
@PactVerification(value = "test_provider")
public void runTest() throws IOException {
    Assert.assertEquals(new ConsumerClient(mockTestProvider.getUrl()).options("/second"), 200);
    Map expectedResponse = new HashMap();
    expectedResponse.put("responsetest", true);
    expectedResponse.put("name", "harry");
    assertEquals(new ConsumerClient(mockTestProvider.getUrl()).getAsMap("/", ""), expectedResponse);
}
Also used : ConsumerClient(au.com.dius.pact.consumer.exampleclients.ConsumerClient) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test)

Example 10 with ConsumerClient

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

the class PactProviderWithMultipleFragmentsTest method runTestWithFragment1.

@Test
@PactVerification(value = "test_provider", fragment = "createFragment")
public void runTestWithFragment1() throws IOException {
    Assert.assertEquals(new ConsumerClient(mockTestProvider.getUrl()).options("/second"), 200);
    Map expectedResponse = new HashMap();
    expectedResponse.put("responsetest", true);
    expectedResponse.put("name", "harry");
    assertEquals(new ConsumerClient(mockTestProvider.getUrl()).getAsMap("/", ""), expectedResponse);
}
Also used : ConsumerClient(au.com.dius.pact.consumer.exampleclients.ConsumerClient) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test)

Aggregations

ConsumerClient (au.com.dius.pact.consumer.exampleclients.ConsumerClient)14 HashMap (java.util.HashMap)11 Map (java.util.Map)10 Test (org.junit.Test)8 PactVerification (au.com.dius.pact.consumer.PactVerification)7 PactVerificationResult (au.com.dius.pact.consumer.PactVerificationResult)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Request (au.com.dius.pact.model.Request)1 IOException (java.io.IOException)1