Search in sources :

Example 1 with PactVerifications

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

the class PactProviderWithMultipleFragmentsTest method runTestWithAllFragments.

@Test
@PactVerifications({ @PactVerification(value = "test_provider", fragment = "createFragment"), @PactVerification(value = "test_provider2", fragment = "createFragment2"), @PactVerification(value = "test_provider2", fragment = "createFragment3") })
public void runTestWithAllFragments() 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);
    try {
        new ConsumerClient(mockTestProvider2.getUrl()).getAsMap("/path/2", "");
        fail();
    } catch (IOException ex) {
        ex.printStackTrace();
    // assertThat(ex.getStatusCode(), is(404));
    }
}
Also used : ConsumerClient(au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient) HashMap(java.util.HashMap) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) PactVerifications(au.com.dius.pact.consumer.junit.PactVerifications)

Example 2 with PactVerifications

use of au.com.dius.pact.consumer.junit.PactVerifications 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 3 with PactVerifications

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

the class PactProviderWithMultipleFragmentsTest method runTestWithPactVerificationsAndDefaultResponseValuesArePresent.

@Test
@PactVerifications({ @PactVerification(value = "test_provider2", fragment = "createFragment2") })
public void runTestWithPactVerificationsAndDefaultResponseValuesArePresent() throws IOException {
    HttpResponse httpResponse = Request.get(mockTestProvider2.getUrl()).addHeader("testreqheader", "testreqheadervalue").execute().returnResponse();
    assertThat(Arrays.stream(httpResponse.getHeaders("testresheader")).map(Header::getValue).collect(Collectors.toList()), is(equalTo(List.of("testresheadervalue"))));
}
Also used : Header(org.apache.hc.core5.http.Header) HttpResponse(org.apache.hc.core5.http.HttpResponse) Test(org.junit.Test) PactVerifications(au.com.dius.pact.consumer.junit.PactVerifications)

Aggregations

PactVerifications (au.com.dius.pact.consumer.junit.PactVerifications)3 Test (org.junit.Test)3 ConsumerClient (au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 IOException (java.io.IOException)1 Header (org.apache.hc.core5.http.Header)1 HttpResponse (org.apache.hc.core5.http.HttpResponse)1