Class PactDslKt

  • All Implemented Interfaces:

    
    public final class PactDslKt
    
                        
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final static V4Pact pact(String consumer, String provider, Function1<ConsumerPactDsl, Unit> block) Creates a V4 Pact using an idiomatic Kotlin DSL.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • 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))