Search in sources :

Example 6 with PactVerification

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

the class PactMultiProviderTest method bothprovidersFail.

@Test
@PactVerification(value = { "test_provider", "test_provider2" })
public void bothprovidersFail() 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"));
    });
    mockTestProvider2.validateResultWith((result, t) -> {
        assertThat(t, is(instanceOf(AssertionError.class)));
        assertThat(t.getMessage(), is("The following mismatched requests occurred:\n" + "PartialMismatch(mismatches=[BodyMismatch(larry,farry,Some(Expected 'larry' but received 'farry'),$.body.name,None)])"));
        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));
        RequestPartMismatch mismatch = error1.getMismatches().get(0);
        assertThat(mismatch, is(instanceOf(BodyMismatch.class)));
    });
    doTest("/abc", "{\"name\": \"farry\"}");
}
Also used : RequestPartMismatch(au.com.dius.pact.model.RequestPartMismatch) PactVerificationResult(au.com.dius.pact.consumer.PactVerificationResult) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test)

Example 7 with PactVerification

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

the class PactProviderHttpsKeystoreTest method testKeystoreHappyPath.

@Test
@PactVerification(value = "test_provider")
public void testKeystoreHappyPath() {
    MockHttpsKeystoreProviderConfig config = (MockHttpsKeystoreProviderConfig) mockTestProvider.getConfig();
    LOGGER.info("Keystore path: " + config.getKeystore());
    RestAssured.given().header("testreqheader", "testreqheadervalue").trustStore(config.getKeystore(), config.getKeystorePassword()).when().options(mockTestProvider.getConfig().url() + "/second").then().statusCode(200);
    RestAssured.given().header("testreqheader", "testreqheadervalue").trustStore(config.getKeystore(), config.getKeystorePassword()).when().get(mockTestProvider.getConfig().url() + "/").then().body("responsetest", Matchers.equalTo(true)).body("name", Matchers.equalTo("harry"));
}
Also used : MockHttpsKeystoreProviderConfig(au.com.dius.pact.model.MockHttpsKeystoreProviderConfig) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test)

Example 8 with PactVerification

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

the class ExampleServiceConsumerTest method testBookCar.

@PactVerification("CarBookingProvider")
@Test
public void testBookCar() throws IOException {
    ProviderCarBookingRestClient providerRestClient = new ProviderCarBookingRestClient();
    HttpResponse response = providerRestClient.placeOrder("http://localhost:1234", DATA_A_ID, DATA_B_ID, "2015-03-15");
    Assert.assertEquals(201, response.getStatusLine().getStatusCode());
    String orderDetails = EntityUtils.toString(response.getEntity());
    Assert.assertEquals("{\"id\":\"ORDER_ID_123456\"}", orderDetails);
}
Also used : HttpResponse(org.apache.http.HttpResponse) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test)

Example 9 with PactVerification

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

the class PactMultiProviderTest method provider2Fails.

@Test
@PactVerification(value = { "test_provider", "test_provider2" })
public void provider2Fails() throws IOException, InterruptedException {
    mockTestProvider2.validateResultWith((result, t) -> {
        assertThat(t, is(instanceOf(AssertionError.class)));
        assertThat(t.getMessage(), is("The following mismatched requests occurred:\n" + "PartialMismatch(mismatches=[BodyMismatch(larry,farry,Some(Expected 'larry' but received 'farry'),$.body.name,None)])"));
        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));
        RequestPartMismatch mismatch = error1.getMismatches().get(0);
        assertThat(mismatch, is(instanceOf(BodyMismatch.class)));
    });
    doTest("/", "{\"name\": \"farry\"}");
}
Also used : RequestPartMismatch(au.com.dius.pact.model.RequestPartMismatch) PactVerificationResult(au.com.dius.pact.consumer.PactVerificationResult) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test)

Example 10 with PactVerification

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

the class PactProviderHttpsKeystoreTest method testMisMatchedTrustStore.

@Test(expected = SSLHandshakeException.class)
@PactVerification(value = "test_provider")
public void testMisMatchedTrustStore() {
    testKeystoreHappyPath();
    //Used the following command to create jks file:
    //keytool -genkeypair -alias localhost -keyalg RSA -validity 36500 -keystore pact-jvm-other.jks
    File trustStore = Paths.get("src/test/resources/keystore/pact-jvm-other.jks").toFile();
    RestAssured.given().header("testreqheader", "testreqheadervalue").trustStore(trustStore, "bbarkewashere").when().options(mockTestProvider.getConfig().url() + "/second").then().statusCode(200);
}
Also used : File(java.io.File) PactVerification(au.com.dius.pact.consumer.PactVerification) Test(org.junit.Test)

Aggregations

PactVerification (au.com.dius.pact.consumer.PactVerification)18 Test (org.junit.Test)18 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 Response (javax.ws.rs.core.Response)1 HttpResponse (org.apache.http.HttpResponse)1 EidasCountryDto (uk.gov.ida.hub.policy.domain.EidasCountryDto)1 SessionId (uk.gov.ida.hub.policy.domain.SessionId)1