diff --git a/provider/junit5/src/main/kotlin/au/com/dius/pact/provider/junit5/PactJUnit5VerificationProvider.kt b/provider/junit5/src/main/kotlin/au/com/dius/pact/provider/junit5/PactJUnit5VerificationProvider.kt index 18c5fe3271..f374afe7dc 100644 --- a/provider/junit5/src/main/kotlin/au/com/dius/pact/provider/junit5/PactJUnit5VerificationProvider.kt +++ b/provider/junit5/src/main/kotlin/au/com/dius/pact/provider/junit5/PactJUnit5VerificationProvider.kt @@ -450,8 +450,13 @@ open class PactVerificationInvocationContextProvider : TestTemplateInvocationCon filterPactsByAnnotations(pacts, context.requiredTestClass) }.filter { p -> consumerName == null || p.consumer.name == consumerName } + val interactionFilter = System.getProperty("pact.filter.interaction") return Pair(pactSources.flatMap { pact -> - pact.interactions.map { PactVerificationExtension(pact, pact.source, it, serviceName, consumerName) } + pact.interactions + .filter { + interactionFilter.isNullOrEmpty() || it.description.matches(Regex(interactionFilter)) + } + .map { PactVerificationExtension(pact, pact.source, it, serviceName, consumerName) } }, description) } diff --git a/provider/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationInvocationContextProviderSpec.groovy b/provider/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationInvocationContextProviderSpec.groovy index f7d1d31f3e..0dfb95cab4 100644 --- a/provider/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationInvocationContextProviderSpec.groovy +++ b/provider/junit5/src/test/groovy/au/com/dius/pact/provider/junit5/PactVerificationInvocationContextProviderSpec.groovy @@ -17,6 +17,7 @@ import org.junit.jupiter.api.extension.ExtensionContext import spock.lang.Issue import spock.lang.Specification import spock.lang.Unroll +import spock.util.environment.RestoreSystemProperties @SuppressWarnings(['EmptyMethod', 'UnusedMethodParameter']) class PactVerificationInvocationContextProviderSpec extends Specification { @@ -165,6 +166,21 @@ class PactVerificationInvocationContextProviderSpec extends Specification { extensions.count() == 1 } + @Issue('#1104') + @RestoreSystemProperties + def 'supports filtering the interactions'() { + given: + System.setProperty('pact.filter.interaction', 'Get data 2') + + when: + def extensions = provider.provideTestTemplateInvocationContexts([ + 'getTestClass': { Optional.of(TestClassWithAnnotation) } ] as ExtensionContext + ) + + then: + extensions.count() == 1 + } + @Issue('#1007') def 'provideTestTemplateInvocationContexts throws an exception if there are no pacts to verify'() { when: diff --git a/provider/junit5/src/test/resources/pacts/contract2.json b/provider/junit5/src/test/resources/pacts/contract2.json index 5d705ccdf9..2a511e20de 100644 --- a/provider/junit5/src/test/resources/pacts/contract2.json +++ b/provider/junit5/src/test/resources/pacts/contract2.json @@ -7,7 +7,7 @@ }, "interactions" : [ { "providerState": "default", - "description" : "Get data", + "description" : "Get data 2", "request" : { "method" : "GET", "path" : "/data",