1
1
package au.com.dius.pact.provider.junit5
2
2
3
- import au.com.dius.pact.core.model.V4Interaction
4
3
import spock.lang.Specification
5
4
import au.com.dius.pact.core.model.RequestResponseInteraction
6
5
import au.com.dius.pact.core.model.messaging.Message
6
+ import au.com.dius.pact.core.matchers.generators.ArrayContainsJsonGenerator
7
+ import au.com.dius.pact.core.model.Consumer
8
+ import au.com.dius.pact.core.model.OptionalBody
9
+ import au.com.dius.pact.core.model.Provider
10
+ import au.com.dius.pact.core.model.V4Interaction
11
+ import au.com.dius.pact.core.model.V4Pact
12
+ import au.com.dius.pact.core.support.Result
13
+ import io.pact.plugins.jvm.core.CatalogueEntry
14
+ import io.pact.plugins.jvm.core.CatalogueEntryProviderType
15
+ import io.pact.plugins.jvm.core.CatalogueEntryType
16
+ import io.pact.plugins.jvm.core.InteractionVerificationData
17
+ import io.pact.plugins.jvm.core.PluginManager
7
18
8
19
class PluginTestTargetSpec extends Specification {
9
20
def ' supports any V4 interaction' () {
@@ -18,4 +29,38 @@ class PluginTestTargetSpec extends Specification {
18
29
new V4Interaction.SynchronousMessages (' test' ) | true
19
30
new V4Interaction.SynchronousHttp (' test' ) | true
20
31
}
32
+
33
+ def ' when calling a plugin, prepareRequest must merge the provider state test context config' () {
34
+ given :
35
+ def config = [
36
+ transport : ' grpc' ,
37
+ host : ' localhost' ,
38
+ port : 38525
39
+ ]
40
+ def target = new PluginTestTarget (config)
41
+ target. transportEntry = new CatalogueEntry (CatalogueEntryType . CONTENT_MATCHER , CatalogueEntryProviderType . PLUGIN ,
42
+ ' null' , ' null' )
43
+ def interaction = new V4Interaction.SynchronousHttp (null , ' test interaction' )
44
+ def pact = new V4Pact (new Consumer (), new Provider (), [ interaction ])
45
+ def context = [
46
+ providerState : [a : 100 , b : 200 ],
47
+ ArrayContainsJsonGenerator : ArrayContainsJsonGenerator . INSTANCE
48
+ ]
49
+ def expectedContext = [
50
+ transport : ' grpc' ,
51
+ host : ' localhost' ,
52
+ port : 38525 ,
53
+ providerState : [a : 100 , b : 200 ]
54
+ ]
55
+ def pluginManager = Mock (PluginManager )
56
+ target. pluginManager = pluginManager
57
+
58
+ when :
59
+ target. prepareRequest(pact, interaction, context)
60
+
61
+ then :
62
+ noExceptionThrown()
63
+ 1 * pluginManager. prepareValidationForInteraction(_, _, _, expectedContext) >> new Result.Ok (
64
+ new InteractionVerificationData (OptionalBody . missing(), [:]))
65
+ }
21
66
}
0 commit comments