From fdea11eaed916acaba329bb1d8804f98f4a42715 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Wed, 7 Jun 2023 14:54:26 +1000 Subject: [PATCH] feat: Add builder interface for plugins to provide DSL to construct interactions --- .../com/dius/pact/consumer/dsl/PactBuilder.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/PactBuilder.kt b/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/PactBuilder.kt index 28d6aa3eb..155dd91bf 100644 --- a/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/PactBuilder.kt +++ b/consumer/src/main/kotlin/au/com/dius/pact/consumer/dsl/PactBuilder.kt @@ -47,6 +47,16 @@ interface DslBuilder { fun addPluginConfiguration(matcher: ContentMatcher, pactConfiguration: Map) } +/** + * Sets up the data required by a plugin to configure an interaction + */ +interface PluginInteractionBuilder { + /** + * Construct the map of configuration that is to be passed through to the plugin + */ + fun build(): Map +} + /** * Pact builder DSL that supports V4 formatted Pact files */ @@ -297,6 +307,16 @@ open class PactBuilder( return this } + /** + * Configure the interaction using a builder supplied by the plugin author. + */ + fun with(builder: PluginInteractionBuilder): PactBuilder { + require(currentInteraction != null) { + "'with' must be preceded by 'expectsToReceive'" + } + return with(builder.build()) + } + override fun addPluginConfiguration(matcher: ContentMatcher, pactConfiguration: Map) { if (pluginConfiguration.containsKey(matcher.pluginName)) { pluginConfiguration[matcher.pluginName].deepMerge(pactConfiguration)