Search in sources :

Example 16 with PactVerification

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

the class PactMultiProviderTest method bothprovidersFail.

@Test
@PactVerification(value = { "test_provider", "test_provider2" })
public void bothprovidersFail() throws IOException {
    mockTestProvider.validateResultWith((result, t) -> {
        assertThat(t, is(instanceOf(AssertionError.class)));
        assertThat(t.getMessage(), startsWith("The following mismatched requests occurred:\nUnexpected Request:\n\tmethod: GET\n\tpath: /abc"));
        assertThat(result, is(instanceOf(PactVerificationResult.Mismatches.class)));
        PactVerificationResult.Mismatches error = (PactVerificationResult.Mismatches) result;
        assertThat(error.getMismatches(), hasSize(1));
        PactVerificationResult result1 = error.getMismatches().get(0);
        assertThat(result1, is(instanceOf(PactVerificationResult.UnexpectedRequest.class)));
        PactVerificationResult.UnexpectedRequest unexpectedRequest = (PactVerificationResult.UnexpectedRequest) result1;
        assertThat(unexpectedRequest.getRequest().getPath(), is("/abc"));
    });
    mockTestProvider2.validateResultWith((result, t) -> {
        assertThat(t, is(instanceOf(AssertionError.class)));
        assertThat(t.getMessage(), is("The following mismatched requests occurred:\n" + "body - $.name: Expected 'larry' (String) but received 'farry' (String)"));
        assertThat(result, is(instanceOf(PactVerificationResult.Mismatches.class)));
        PactVerificationResult.Mismatches error = (PactVerificationResult.Mismatches) result;
        assertThat(error.getMismatches(), hasSize(1));
        PactVerificationResult result1 = error.getMismatches().get(0);
        assertThat(result1, is(instanceOf(PactVerificationResult.PartialMismatch.class)));
        PactVerificationResult.PartialMismatch error1 = (PactVerificationResult.PartialMismatch) result1;
        assertThat(error1.getMismatches(), hasSize(1));
        Mismatch mismatch = error1.getMismatches().get(0);
        assertThat(mismatch, is(instanceOf(BodyMismatch.class)));
    });
    doTest("/abc", "{\"name\": \"farry\"}");
}
Also used : Mismatch(au.com.dius.pact.core.matchers.Mismatch) BodyMismatch(au.com.dius.pact.core.matchers.BodyMismatch) PactVerificationResult(au.com.dius.pact.consumer.PactVerificationResult) PactVerification(au.com.dius.pact.consumer.junit.PactVerification) Test(org.junit.Test)

Example 17 with PactVerification

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

the class PactMultiProviderTest method provider2Fails.

@Test
@PactVerification(value = { "test_provider", "test_provider2" })
public void provider2Fails() throws IOException {
    mockTestProvider2.validateResultWith((result, t) -> {
        assertThat(t, is(instanceOf(AssertionError.class)));
        assertThat(t.getMessage(), is("The following mismatched requests occurred:\n" + "body - $.name: Expected 'larry' (String) but received 'farry' (String)"));
        assertThat(result, is(instanceOf(PactVerificationResult.Mismatches.class)));
        PactVerificationResult.Mismatches error = (PactVerificationResult.Mismatches) result;
        assertThat(error.getMismatches(), hasSize(1));
        PactVerificationResult result1 = error.getMismatches().get(0);
        assertThat(result1, is(instanceOf(PactVerificationResult.PartialMismatch.class)));
        PactVerificationResult.PartialMismatch error1 = (PactVerificationResult.PartialMismatch) result1;
        assertThat(error1.getMismatches(), hasSize(1));
        Mismatch mismatch = error1.getMismatches().get(0);
        assertThat(mismatch, is(instanceOf(BodyMismatch.class)));
    });
    doTest("/", "{\"name\": \"farry\"}");
}
Also used : Mismatch(au.com.dius.pact.core.matchers.Mismatch) BodyMismatch(au.com.dius.pact.core.matchers.BodyMismatch) PactVerificationResult(au.com.dius.pact.consumer.PactVerificationResult) PactVerification(au.com.dius.pact.consumer.junit.PactVerification) Test(org.junit.Test)

Example 18 with PactVerification

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

the class PactProviderHttpsTest method runTestWithUserCodeFailure.

@Test(expected = AssertionError.class)
@PactVerification("test_provider")
public void runTestWithUserCodeFailure() throws IOException {
    Assert.assertEquals(new ConsumerHttpsClient(mockTestProvider.getConfig().url()).options("/second"), 200);
    Map expectedResponse = new HashMap();
    expectedResponse.put("responsetest", true);
    expectedResponse.put("name", "fred");
    assertEquals(new ConsumerHttpsClient(mockTestProvider.getConfig().url()).getAsMap("/", ""), expectedResponse);
}
Also used : ConsumerHttpsClient(au.com.dius.pact.consumer.junit.exampleclients.ConsumerHttpsClient) 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 19 with PactVerification

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

the class PactProviderHttpsTest method runTest.

@Test
@PactVerification(value = "test_provider")
public void runTest() throws IOException {
    LOGGER.info("Config: " + mockTestProvider.getConfig());
    Assert.assertEquals(new ConsumerHttpsClient(mockTestProvider.getConfig().url()).options("/second"), 200);
    Map expectedResponse = new HashMap();
    expectedResponse.put("responsetest", true);
    expectedResponse.put("name", "harry");
    assertEquals(new ConsumerHttpsClient(mockTestProvider.getConfig().url()).getAsMap("/", ""), expectedResponse);
}
Also used : ConsumerHttpsClient(au.com.dius.pact.consumer.junit.exampleclients.ConsumerHttpsClient) 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 20 with PactVerification

use of au.com.dius.pact.consumer.junit.PactVerification 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)

Aggregations

PactVerification (au.com.dius.pact.consumer.junit.PactVerification)20 Test (org.junit.Test)20 Map (java.util.Map)10 ConsumerClient (au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient)9 HashMap (java.util.HashMap)8 PactVerificationResult (au.com.dius.pact.consumer.PactVerificationResult)5 ConsumerHttpsClient (au.com.dius.pact.consumer.junit.exampleclients.ConsumerHttpsClient)3 ArticlesRestClient (au.com.dius.pact.consumer.junit.exampleclients.ArticlesRestClient)2 BodyMismatch (au.com.dius.pact.core.matchers.BodyMismatch)2 Mismatch (au.com.dius.pact.core.matchers.Mismatch)2 MockHttpsKeystoreProviderConfig (au.com.dius.pact.consumer.model.MockHttpsKeystoreProviderConfig)1 IRequest (au.com.dius.pact.core.model.IRequest)1 File (java.io.File)1 ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)1