Search in sources :

Example 1 with PactVerification

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

the class PactProviderHttpsKeystoreTest method testSslHandshakeException.

@Test(expected = SSLHandshakeException.class)
@PactVerification(value = "test_provider")
public void testSslHandshakeException() throws IOException {
    testKeystoreHappyPath();
    new ConsumerHttpsClient(mockTestProvider.getConfig().url()).getAsMap("/", "");
}
Also used : ConsumerHttpsClient(au.com.dius.pact.consumer.junit.exampleclients.ConsumerHttpsClient) PactVerification(au.com.dius.pact.consumer.junit.PactVerification) Test(org.junit.Test)

Example 2 with PactVerification

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

Example 3 with PactVerification

use of au.com.dius.pact.consumer.junit.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.getPassword()).when().options(mockTestProvider.getConfig().url() + "/second").then().statusCode(200);
    RestAssured.given().header("testreqheader", "testreqheadervalue").trustStore(config.getKeystore(), config.getPassword()).when().get(mockTestProvider.getConfig().url() + "/").then().body("responsetest", Matchers.equalTo(true)).body("name", Matchers.equalTo("harry"));
}
Also used : MockHttpsKeystoreProviderConfig(au.com.dius.pact.consumer.model.MockHttpsKeystoreProviderConfig) PactVerification(au.com.dius.pact.consumer.junit.PactVerification) Test(org.junit.Test)

Example 4 with PactVerification

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

the class PactProviderTest method runTest.

@Test
@PactVerification(value = "test_provider")
public void runTest() 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)

Example 5 with PactVerification

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

the class StatusCodeMatcherPactTest 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)

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