Search in sources :

Example 1 with ConsumerClient

use of au.com.dius.pact.consumer.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.INSTANCE.getClass())));
        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.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.PactVerification) Test(org.junit.Test)

Example 2 with ConsumerClient

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

the class PactProviderWithMultipleFragmentsTest method runTestWithFragment2.

@Test
@PactVerification(value = "test_provider", fragment = "createFragment2")
public void runTestWithFragment2() throws IOException {
    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.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 3 with ConsumerClient

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

the class MissingRequestConsumerPassesTest method runTest.

@Override
protected void runTest(MockServer mockServer) 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);
}
Also used : ConsumerClient(au.com.dius.pact.consumer.exampleclients.ConsumerClient) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 4 with ConsumerClient

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

the class UnexpectedRequestConsumerPassesTest method runTest.

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

Example 5 with ConsumerClient

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

the class PactRuleWithRandomPortTest method runTest.

@Test
@PactVerification("test_provider")
public void runTest() throws IOException {
    Map expectedResponse = new HashMap();
    assertEquals(new ConsumerClient("http://localhost:" + rule.getPort()).getAsMap("/", ""), expectedResponse);
}
Also used : ConsumerClient(au.com.dius.pact.consumer.exampleclients.ConsumerClient) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) 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