Search in sources :

Example 1 with PactVerification

use of au.com.dius.pact.consumer.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());
    MockHttpsProviderConfig config = (MockHttpsProviderConfig) mockTestProvider.getConfig();
    LOGGER.info("Config Cert: " + config.getHttpsCertificate().certificate());
    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.exampleclients.ConsumerHttpsClient) HashMap(java.util.HashMap) MockHttpsProviderConfig(au.com.dius.pact.model.MockHttpsProviderConfig) HashMap(java.util.HashMap) Map(java.util.Map) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test)

Example 2 with PactVerification

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

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

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

the class ArticlesTest method testArticles.

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

Example 5 with PactVerification

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

Aggregations

PactVerification (au.com.dius.pact.consumer.PactVerification)17 Test (org.junit.Test)17 HashMap (java.util.HashMap)8 Map (java.util.Map)8 ConsumerClient (au.com.dius.pact.consumer.exampleclients.ConsumerClient)7 PactVerificationResult (au.com.dius.pact.consumer.PactVerificationResult)5 ConsumerHttpsClient (au.com.dius.pact.consumer.exampleclients.ConsumerHttpsClient)3 RequestPartMismatch (au.com.dius.pact.model.RequestPartMismatch)2 ArticlesRestClient (au.com.dius.pact.consumer.exampleclients.ArticlesRestClient)1 MockHttpsKeystoreProviderConfig (au.com.dius.pact.model.MockHttpsKeystoreProviderConfig)1 MockHttpsProviderConfig (au.com.dius.pact.model.MockHttpsProviderConfig)1 Request (au.com.dius.pact.model.Request)1 File (java.io.File)1 HttpResponse (org.apache.http.HttpResponse)1