@@ -83,10 +83,7 @@ func TestStubRule_ToJson(t *testing.T) {
83
83
WithScheme ("http" ).
84
84
WithPort (8080 ).
85
85
WithBearerToken (StartsWith ("token" )).
86
- WillReturnResponse (
87
- NewResponse ().
88
- WithStatus (http .StatusOK ),
89
- ),
86
+ WillReturnResponse (OK ()),
90
87
ExpectedFileName : "expected-template-bearer-auth-startsWith.json" ,
91
88
},
92
89
{
@@ -96,10 +93,7 @@ func TestStubRule_ToJson(t *testing.T) {
96
93
WithScheme ("http" ).
97
94
WithPort (8080 ).
98
95
WithBearerToken (EqualTo ("token" )).
99
- WillReturnResponse (
100
- NewResponse ().
101
- WithStatus (http .StatusOK ),
102
- ),
96
+ WillReturnResponse (OK ()),
103
97
ExpectedFileName : "expected-template-bearer-auth-equalTo.json" ,
104
98
},
105
99
{
@@ -109,10 +103,7 @@ func TestStubRule_ToJson(t *testing.T) {
109
103
WithScheme ("http" ).
110
104
WithPort (8080 ).
111
105
WithBearerToken (Contains ("token" )).
112
- WillReturnResponse (
113
- NewResponse ().
114
- WithStatus (http .StatusOK ),
115
- ),
106
+ WillReturnResponse (OK ()),
116
107
ExpectedFileName : "expected-template-bearer-auth-contains.json" ,
117
108
},
118
109
{
@@ -122,12 +113,47 @@ func TestStubRule_ToJson(t *testing.T) {
122
113
WithScheme ("http" ).
123
114
WithPort (8080 ).
124
115
WithBearerToken (EqualTo ("token123" ).And (StartsWith ("token" ))).
125
- WillReturnResponse (
126
- NewResponse ().
127
- WithStatus (http .StatusOK ),
128
- ),
116
+ WillReturnResponse (OK ()),
129
117
ExpectedFileName : "expected-template-bearer-auth-logicalMatcher.json" ,
130
118
},
119
+ {
120
+ Name : "NotLogicalMatcher" ,
121
+ StubRule : Post (URLPathEqualTo ("/example" )).
122
+ WithQueryParam ("firstName" , Not (EqualTo ("John" ).Or (EqualTo ("Jack" )))).
123
+ WillReturnResponse (OK ()),
124
+ ExpectedFileName : "not-logical-expression.json" ,
125
+ },
126
+ {
127
+ Name : "JsonSchemaMatcher" ,
128
+ StubRule : Post (URLPathEqualTo ("/example" )).
129
+ WithQueryParam ("firstName" , MatchesJsonSchema (
130
+ `{
131
+ "type": "object",
132
+ "required": [
133
+ "name"
134
+ ],
135
+ "properties": {
136
+ "name": {
137
+ "type": "string"
138
+ },
139
+ "tag": {
140
+ "type": "string"
141
+ }
142
+ }
143
+ }` ,
144
+ "V202012" ,
145
+ )).
146
+ WillReturnResponse (OK ()),
147
+ ExpectedFileName : "matches-Json-schema.json" ,
148
+ },
149
+ {
150
+ Name : "URLPathTemplateMatcher" ,
151
+ StubRule : Get (URLPathTemplate ("/contacts/{contactId}/addresses/{addressId}" )).
152
+ WithPathParam ("contactId" , EqualTo ("12345" )).
153
+ WithPathParam ("addressId" , EqualTo ("99876" )).
154
+ WillReturnResponse (OK ()),
155
+ ExpectedFileName : "url-path-templating.json" ,
156
+ },
131
157
}
132
158
133
159
for _ , tc := range testCases {
@@ -142,7 +168,7 @@ func TestStubRule_ToJson(t *testing.T) {
142
168
var expected map [string ]interface {}
143
169
err = json .Unmarshal ([]byte (fmt .Sprintf (string (rawExpectedRequestBody ), stubRule .uuid , stubRule .uuid )), & expected )
144
170
if err != nil {
145
- t .Fatalf ("StubRole json.Unmarshal error: %v" , err )
171
+ t .Fatalf ("StubRule json.Unmarshal error: %v" , err )
146
172
}
147
173
148
174
rawResult , err := json .Marshal (stubRule )
0 commit comments