Skip to content

Commit

Permalink
feat: Add builder interface for plugins to provide DSL to construct i…
Browse files Browse the repository at this point in the history
…nteractions
  • Loading branch information
rholshausen committed Jun 7, 2023
1 parent 7c41fc1 commit fdea11e
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ interface DslBuilder {
fun addPluginConfiguration(matcher: ContentMatcher, pactConfiguration: Map<String, JsonValue>)
}

/**
* 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<String, Any?>
}

/**
* Pact builder DSL that supports V4 formatted Pact files
*/
Expand Down Expand Up @@ -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<String, JsonValue>) {
if (pluginConfiguration.containsKey(matcher.pluginName)) {
pluginConfiguration[matcher.pluginName].deepMerge(pactConfiguration)
Expand Down

0 comments on commit fdea11e

Please sign in to comment.