Package au.com.dius.pact.consumer.kotlin
Class PactDslKt
-
- All Implemented Interfaces:
public final class PactDslKt
-
-
Method Summary
Modifier and Type Method Description final static V4Pactpact(String consumer, String provider, Function1<ConsumerPactDsl, Unit> block)Creates a V4 Pact using an idiomatic Kotlin DSL. final static <R extends Any> PactVerificationResultrunConsumerTest(V4Pact pact, MockProviderConfig config, Function1<MockServer, R> test)Runs a consumer Pact test against a mock HTTP server and writes the Pact file on success. -
-
Method Detail
-
pact
final static V4Pact pact(String consumer, String provider, Function1<ConsumerPactDsl, Unit> block)
Creates a V4 Pact using an idiomatic Kotlin DSL.
Example:
val myPact = pact(consumer = "MyConsumer", provider = "MyProvider") { uponReceiving("a request for users") { given("users exist") withRequest { method("GET") path("/api/users") header("Accept", "application/json") } willRespondWith { status(200) header("Content-Type", "application/json") body(newJsonArray { newObject { stringType("name", "Alice") numberType("age", 30) } }) } } }
-
runConsumerTest
final static <R extends Any> PactVerificationResult runConsumerTest(V4Pact pact, MockProviderConfig config, Function1<MockServer, R> test)
Runs a consumer Pact test against a mock HTTP server and writes the Pact file on success.
The test block receives the MockServer as its receiver; call MockServer.getUrl to obtain the base URL for making requests against the mock.
Example:
val result = runConsumerTest(myPact) { val response = URL("${getUrl()}/api/users").readText() assertThat(response, containsString("Alice")) } assertThat(result, instanceOf(PactVerificationResult.Ok::class.java))
-
-
-
-