Skip to content

Commit

Permalink
fix: pass the value resolver on to the PactVerificationContext, fixes…
Browse files Browse the repository at this point in the history
… issues with Spring tests #1572
  • Loading branch information
uglyog committed Jul 26, 2022
1 parent c085da6 commit d914ff1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ open class PactVerificationExtension(
pactSource is BrokerUrlSource && pactSource.result?.pending == true
val verificationContext = PactVerificationContext(store, context,
consumer = ConsumerInfo(pact.consumer.name, pactSource = pactSource, pending = pending),
interaction = interaction, providerInfo = ProviderInfo(serviceName))
interaction = interaction,
providerInfo = ProviderInfo(serviceName),
valueResolver = propertyResolver
)
store.put("interactionContext", verificationContext)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import au.com.dius.pact.provider.TestResultAccumulator
import com.github.michaelbull.result.Err
import com.github.michaelbull.result.Ok
import org.junit.jupiter.api.extension.ExtensionContext
import spock.lang.Issue
import spock.lang.Specification

class PactVerificationExtensionSpec extends Specification {
Expand Down Expand Up @@ -126,4 +127,31 @@ class PactVerificationExtensionSpec extends Specification {
def exception = thrown(AssertionError)
exception.message == 'Failed to update the test results: failed'
}

@Issue('#1572')
def 'beforeEach method passes the property resolver on to the verification context'() {
given:
def map = [:]
ExtensionContext.Store store = Stub {
get(_) >> { args -> map[args[0]] }
put(_, _) >> { args -> map[args[0]] = args[1] }
}
ExtensionContext extContext = Stub {
getStore(_) >> store
}
def mockValueResolver = Mock(ValueResolver)

def interaction1 = new RequestResponseInteraction('interaction1')
PactBrokerSource pactSource = new PactBrokerSource('localhost', '80', 'http')
def pact = new RequestResponsePact(new Provider(), new Consumer(), [interaction1], [:], pactSource)

PactVerificationExtension extension = new PactVerificationExtension(pact, pactSource, interaction1,
'service', 'consumer', mockValueResolver)

when:
extension.beforeEach(extContext)

then:
map['interactionContext'].valueResolver == mockValueResolver
}
}

0 comments on commit d914ff1

Please sign in to comment.