diff --git a/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt b/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt index 104cdc918e..0fa7e42286 100644 --- a/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt +++ b/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt @@ -215,6 +215,11 @@ sealed class ConsumerVersionSelectors { val fallbackTag: String? = null ): ConsumerVersionSelectors() + /** + * Raw JSON form of a selector. + */ + data class RawSelector(val selector: JsonValue): ConsumerVersionSelectors() + fun toJson(): JsonValue { return when (this) { is Branch -> { @@ -278,6 +283,7 @@ sealed class ConsumerVersionSelectors { JsonValue.Object(entries) } is Tag -> JsonValue.Object("tag" to JsonValue.StringValue(this.tag)) + is RawSelector -> this.selector } } } diff --git a/provider/src/main/kotlin/au/com/dius/pact/provider/junitsupport/loader/SelectorBuilder.kt b/provider/src/main/kotlin/au/com/dius/pact/provider/junitsupport/loader/SelectorBuilder.kt index 6dedd8da0e..efb876ace8 100644 --- a/provider/src/main/kotlin/au/com/dius/pact/provider/junitsupport/loader/SelectorBuilder.kt +++ b/provider/src/main/kotlin/au/com/dius/pact/provider/junitsupport/loader/SelectorBuilder.kt @@ -1,6 +1,7 @@ package au.com.dius.pact.provider.junitsupport.loader import au.com.dius.pact.core.pactbroker.ConsumerVersionSelectors +import au.com.dius.pact.core.support.json.JsonParser /** * Builder for setting up consumer version selectors in provider JUnit tests. @@ -106,6 +107,14 @@ open class SelectorBuilder { return this } + /** + * Selector in raw JSON form. + */ + fun rawSelectorJson(json: String): SelectorBuilder { + selectors.add(ConsumerVersionSelectors.RawSelector(JsonParser.parseString(json))) + return this + } + /** * Construct the final list of consumer version selectors */ diff --git a/provider/src/test/groovy/au/com/dius/pact/provider/junitsupport/loader/SelectorBuilderSpec.groovy b/provider/src/test/groovy/au/com/dius/pact/provider/junitsupport/loader/SelectorBuilderSpec.groovy new file mode 100644 index 0000000000..649bfd9ae9 --- /dev/null +++ b/provider/src/test/groovy/au/com/dius/pact/provider/junitsupport/loader/SelectorBuilderSpec.groovy @@ -0,0 +1,17 @@ +package au.com.dius.pact.provider.junitsupport.loader + +import spock.lang.Specification + +import static au.com.dius.pact.core.support.JsonKt.jsonArray + +class SelectorBuilderSpec extends Specification { + + def 'allow providing selectors in raw form'() { + expect: + jsonArray(new SelectorBuilder() + .rawSelectorJson('{"iAmA": "selector"}') + .build() + .collect { it.toJson() }).serialise() == '[{"iAmA":"selector"}]' + } + +}