1
1
package au .com .dius .pact .provider .junit .filter ;
2
2
3
+ import au .com .dius .pact .core .model .HttpRequest ;
3
4
import au .com .dius .pact .core .model .Interaction ;
4
5
import au .com .dius .pact .core .model .ProviderState ;
5
6
import au .com .dius .pact .core .model .Request ;
6
7
import au .com .dius .pact .core .model .RequestResponseInteraction ;
8
+ import au .com .dius .pact .core .model .V4Interaction ;
7
9
import au .com .dius .pact .core .model .messaging .Message ;
8
10
import au .com .dius .pact .provider .junitsupport .filter .InteractionFilter ;
9
11
import org .junit .Assert ;
12
+ import org .junit .jupiter .api .Assertions ;
10
13
import org .junit .jupiter .api .Nested ;
11
14
import org .junit .jupiter .api .Test ;
15
+ import org .junit .jupiter .params .ParameterizedTest ;
16
+ import org .junit .jupiter .params .provider .ValueSource ;
12
17
13
18
import java .lang .reflect .InvocationTargetException ;
14
19
import java .util .Arrays ;
15
20
import java .util .Collections ;
21
+ import java .util .List ;
16
22
17
23
class InteractionFilterTest {
18
24
@@ -25,34 +31,27 @@ class ByProviderState {
25
31
ByProviderState () throws InvocationTargetException , NoSuchMethodException , InstantiationException , IllegalAccessException {
26
32
}
27
33
28
- @ Test
29
- public void filterRequestResponseInteraction () {
30
- RequestResponseInteraction interaction = new RequestResponseInteraction (
34
+ @ ParameterizedTest
35
+ @ ValueSource (classes = {
36
+ RequestResponseInteraction .class ,
37
+ Message .class ,
38
+ V4Interaction .SynchronousHttp .class ,
39
+ V4Interaction .SynchronousMessages .class ,
40
+ V4Interaction .AsynchronousMessage .class
41
+ })
42
+ public void filterInteraction (Class interactionClass )
43
+ throws NoSuchMethodException , InvocationTargetException , InstantiationException , IllegalAccessException {
44
+ Interaction interaction = (Interaction ) interactionClass .getDeclaredConstructor (String .class , List .class ).newInstance (
31
45
"test" ,
32
46
Arrays .asList (new ProviderState ("state1" ), new ProviderState ("state2" ))
33
47
);
34
48
35
- Assert .assertTrue (interactionFilter .buildPredicate (new String []{"state1" }).test (interaction ));
36
- Assert .assertFalse (interactionFilter .buildPredicate (new String []{"noop" }).test (interaction ));
37
- Assert .assertTrue (interactionFilter .buildPredicate (new String []{"state1" , "state2" }).test (interaction ));
38
- Assert .assertTrue (interactionFilter .buildPredicate (new String []{"noop" , "state2" }).test (interaction ));
39
- Assert .assertTrue (interactionFilter .buildPredicate (new String []{"state1" , "state2" }).test (interaction ));
40
- Assert .assertFalse (interactionFilter .buildPredicate (new String []{"" }).test (interaction ));
41
- }
42
-
43
- @ Test
44
- public void filterMessageInteraction () {
45
- Message interaction = new Message (
46
- "test" ,
47
- Arrays .asList (new ProviderState ("state1" ), new ProviderState ("state2" ))
48
- );
49
-
50
- Assert .assertTrue (interactionFilter .buildPredicate (new String []{"state1" }).test (interaction ));
51
- Assert .assertFalse (interactionFilter .buildPredicate (new String []{"noop" }).test (interaction ));
52
- Assert .assertTrue (interactionFilter .buildPredicate (new String []{"state1" , "state2" }).test (interaction ));
53
- Assert .assertTrue (interactionFilter .buildPredicate (new String []{"noop" , "state2" }).test (interaction ));
54
- Assert .assertTrue (interactionFilter .buildPredicate (new String []{"state1" , "state2" }).test (interaction ));
55
- Assert .assertFalse (interactionFilter .buildPredicate (new String []{"" }).test (interaction ));
49
+ Assertions .assertTrue (interactionFilter .buildPredicate (new String []{"state1" }).test (interaction ));
50
+ Assertions .assertFalse (interactionFilter .buildPredicate (new String []{"noop" }).test (interaction ));
51
+ Assertions .assertTrue (interactionFilter .buildPredicate (new String []{"state1" , "state2" }).test (interaction ));
52
+ Assertions .assertTrue (interactionFilter .buildPredicate (new String []{"noop" , "state2" }).test (interaction ));
53
+ Assertions .assertTrue (interactionFilter .buildPredicate (new String []{"state1" , "state2" }).test (interaction ));
54
+ Assertions .assertFalse (interactionFilter .buildPredicate (new String []{"" }).test (interaction ));
56
55
}
57
56
}
58
57
@@ -73,16 +72,41 @@ public void filterRequestResponseInteraction() {
73
72
new Request ("GET" , "/some-path" )
74
73
);
75
74
76
- Assert .assertTrue (interactionFilter .buildPredicate (new String []{"\\ /some-path" }).test (interaction ));
77
- Assert .assertFalse (interactionFilter .buildPredicate (new String []{"other" }).test (interaction ));
78
- Assert .assertTrue (interactionFilter .buildPredicate (new String []{"\\ /some-path.*" }).test (interaction ));
79
- Assert .assertTrue (interactionFilter .buildPredicate (new String []{".*some-path" }).test (interaction ));
80
- Assert .assertFalse (interactionFilter .buildPredicate (new String []{"" }).test (interaction ));
75
+ Assertions .assertTrue (interactionFilter .buildPredicate (new String []{"\\ /some-path" }).test (interaction ));
76
+ Assertions .assertFalse (interactionFilter .buildPredicate (new String []{"other" }).test (interaction ));
77
+ Assertions .assertTrue (interactionFilter .buildPredicate (new String []{"\\ /some-path.*" }).test (interaction ));
78
+ Assertions .assertTrue (interactionFilter .buildPredicate (new String []{".*some-path" }).test (interaction ));
79
+ Assertions .assertFalse (interactionFilter .buildPredicate (new String []{"" }).test (interaction ));
81
80
}
82
81
83
82
@ Test
84
- public void filterMessageInteraction () {
85
- Message interaction = new Message ("test" , Collections .emptyList ());
83
+ public void filterSynchronousHttpInteraction () {
84
+ V4Interaction .SynchronousHttp interaction = new V4Interaction .SynchronousHttp (
85
+ "key" ,
86
+ "test" ,
87
+ Collections .emptyList (),
88
+ new HttpRequest ("GET" , "/some-path" )
89
+ );
90
+
91
+ Assertions .assertTrue (interactionFilter .buildPredicate (new String []{"\\ /some-path" }).test (interaction ));
92
+ Assertions .assertFalse (interactionFilter .buildPredicate (new String []{"other" }).test (interaction ));
93
+ Assertions .assertTrue (interactionFilter .buildPredicate (new String []{"\\ /some-path.*" }).test (interaction ));
94
+ Assertions .assertTrue (interactionFilter .buildPredicate (new String []{".*some-path" }).test (interaction ));
95
+ Assertions .assertFalse (interactionFilter .buildPredicate (new String []{"" }).test (interaction ));
96
+ }
97
+
98
+ @ ParameterizedTest
99
+ @ ValueSource (classes = {
100
+ Message .class ,
101
+ V4Interaction .SynchronousMessages .class ,
102
+ V4Interaction .AsynchronousMessage .class
103
+ })
104
+ public void filterMessageInteraction (Class interactionClass )
105
+ throws NoSuchMethodException , InvocationTargetException , InstantiationException , IllegalAccessException {
106
+ Interaction interaction = (Interaction ) interactionClass .getDeclaredConstructor (String .class , List .class ).newInstance (
107
+ "test" ,
108
+ Collections .emptyList ()
109
+ );
86
110
Assert .assertFalse (interactionFilter .buildPredicate (new String []{".*" }).test (interaction ));
87
111
}
88
112
}
0 commit comments