Search in sources :

Example 16 with ConsumerClient

use of au.com.dius.pact.consumer.junit.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.junit.exampleclients.ConsumerClient) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) PactVerification(au.com.dius.pact.consumer.junit.PactVerification) Test(org.junit.Test)

Example 17 with ConsumerClient

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

the class PactProviderWithMultipleFragmentsTest method runTestWithBothFragments.

@Test
@PactVerifications({ @PactVerification(value = "test_provider", fragment = "createFragment"), @PactVerification(value = "test_provider2", fragment = "createFragment2") })
public void runTestWithBothFragments() 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);
    expectedResponse = new HashMap();
    expectedResponse.put("responsetest", true);
    expectedResponse.put("name", "fred");
    assertEquals(new ConsumerClient(mockTestProvider2.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) Test(org.junit.Test) PactVerifications(au.com.dius.pact.consumer.junit.PactVerifications)

Example 18 with ConsumerClient

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

the class PactConsumer400Test method runTestAndHandleTheException.

@Test
@PactVerification("test_provider")
public void runTestAndHandleTheException() throws IOException {
    try {
        new ConsumerClient("http://localhost:" + rule.getPort()).getAsMap("/does-not-exist", "");
        fail("Should have thrown an exception");
    } catch (HttpResponseException e) {
    // correct behaviour
    }
}
Also used : ConsumerClient(au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient) HttpResponseException(org.apache.hc.client5.http.HttpResponseException) Test(org.junit.Test)

Example 19 with ConsumerClient

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

the class PactDslJsonBodyTest method runTest.

@Override
protected void runTest(MockServer mockServer, PactTestExecutionContext context) {
    Map response;
    try {
        response = new ConsumerClient(mockServer.getUrl()).getAsMap("/", "");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Map<String, Object> object2 = (Map<String, Object>) response.get("2");
    assertThat(object2, hasKey("test"));
    assertThat(object2.get("test"), is(nullValue()));
}
Also used : ConsumerClient(au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient) Map(java.util.Map)

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