Search in sources :

Example 11 with PactVerification

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

the class V4HttpPactTest method runTest.

@Test
@PactVerification
public void runTest() throws IOException {
    Map expectedResponse = Map.of("responsetest", true, "version", "v3");
    assertEquals(new ConsumerClient(mockTestProvider.getUrl()).getAsMap("/", ""), expectedResponse);
}
Also used : ConsumerClient(au.com.dius.pact.consumer.junit.exampleclients.ConsumerClient) Map(java.util.Map) PactVerification(au.com.dius.pact.consumer.junit.PactVerification) Test(org.junit.Test)

Example 12 with PactVerification

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

Example 13 with PactVerification

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

Example 14 with PactVerification

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

the class ArticlesHttpsTest method testArticles.

@PactVerification("ArticlesProvider")
@Test
public void testArticles() throws IOException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    ArticlesRestClient providerRestClient = new ArticlesRestClient();
    providerRestClient.getArticles("https://localhost:1234");
}
Also used : ArticlesRestClient(au.com.dius.pact.consumer.junit.exampleclients.ArticlesRestClient) PactVerification(au.com.dius.pact.consumer.junit.PactVerification) Test(org.junit.Test)

Example 15 with PactVerification

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

the class PactMultiProviderTest method provider1Fails.

@Test
@PactVerification(value = { "test_provider", "test_provider2" })
public void provider1Fails() throws IOException, InterruptedException {
    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"));
    });
    doTest("/abc", NAME_LARRY_JSON);
}
Also used : PactVerificationResult(au.com.dius.pact.consumer.PactVerificationResult) 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