24
24
25
25
import org .springframework .http .MediaType ;
26
26
import org .springframework .mock .http .client .MockClientHttpRequest ;
27
+ import org .springframework .test .json .JsonCompareMode ;
27
28
import org .springframework .util .LinkedMultiValueMap ;
28
29
import org .springframework .util .MultiValueMap ;
29
30
@@ -234,6 +235,16 @@ public void testJsonLenientMatch() throws Exception {
234
235
235
236
MockRestRequestMatchers .content ().json ("{\n \" foo array\" :[\" second\" ,\" first\" ] \n }" )
236
237
.match (this .request );
238
+ MockRestRequestMatchers .content ().json ("{\n \" foo array\" :[\" second\" ,\" first\" ] \n }" , JsonCompareMode .LENIENT )
239
+ .match (this .request );
240
+ }
241
+
242
+ @ Test
243
+ @ Deprecated
244
+ public void testJsonLenientMatchWithDeprecatedBooleanFlag () throws Exception {
245
+ String content = "{\n \" foo array\" :[\" first\" ,\" second\" ] , \" someExtraProperty\" : \" which is allowed\" \n }" ;
246
+ this .request .getBody ().write (content .getBytes ());
247
+
237
248
MockRestRequestMatchers .content ().json ("{\n \" foo array\" :[\" second\" ,\" first\" ] \n }" , false )
238
249
.match (this .request );
239
250
}
@@ -243,6 +254,18 @@ public void testJsonStrictMatch() throws Exception {
243
254
String content = "{\n \" foo\" : \" bar\" , \" foo array\" :[\" first\" ,\" second\" ] \n }" ;
244
255
this .request .getBody ().write (content .getBytes ());
245
256
257
+ MockRestRequestMatchers
258
+ .content ()
259
+ .json ("{\n \" foo array\" :[\" first\" ,\" second\" ] , \" foo\" : \" bar\" \n }" , JsonCompareMode .STRICT )
260
+ .match (this .request );
261
+ }
262
+
263
+ @ Test
264
+ @ Deprecated
265
+ public void testJsonStrictMatchWithDeprecatedBooleanFlag () throws Exception {
266
+ String content = "{\n \" foo\" : \" bar\" , \" foo array\" :[\" first\" ,\" second\" ] \n }" ;
267
+ this .request .getBody ().write (content .getBytes ());
268
+
246
269
MockRestRequestMatchers
247
270
.content ()
248
271
.json ("{\n \" foo array\" :[\" first\" ,\" second\" ] , \" foo\" : \" bar\" \n }" , true )
@@ -259,6 +282,19 @@ public void testJsonLenientNoMatch() throws Exception {
259
282
.content ()
260
283
.json ("{\n \" foo\" : \" bar\" \n }" )
261
284
.match (this .request ));
285
+ assertThatExceptionOfType (AssertionError .class ).isThrownBy (() ->
286
+ MockRestRequestMatchers
287
+ .content ()
288
+ .json ("{\n \" foo\" : \" bar\" \n }" , JsonCompareMode .LENIENT )
289
+ .match (this .request ));
290
+ }
291
+
292
+ @ Test
293
+ @ Deprecated
294
+ public void testJsonLenientNoMatchWithDeprecatedBooleanFlag () throws Exception {
295
+ String content = "{\n \" bar\" : \" foo\" \n }" ;
296
+ this .request .getBody ().write (content .getBytes ());
297
+
262
298
assertThatExceptionOfType (AssertionError .class ).isThrownBy (() ->
263
299
MockRestRequestMatchers
264
300
.content ()
@@ -271,6 +307,19 @@ public void testJsonStrictNoMatch() throws Exception {
271
307
String content = "{\n \" foo array\" :[\" first\" ,\" second\" ] , \" someExtraProperty\" : \" which is NOT allowed\" \n }" ;
272
308
this .request .getBody ().write (content .getBytes ());
273
309
310
+ assertThatExceptionOfType (AssertionError .class ).isThrownBy (() ->
311
+ MockRestRequestMatchers
312
+ .content ()
313
+ .json ("{\n \" foo array\" :[\" second\" ,\" first\" ] \n }" , JsonCompareMode .STRICT )
314
+ .match (this .request ));
315
+ }
316
+
317
+ @ Test
318
+ @ Deprecated
319
+ public void testJsonStrictNoMatchWithDeprecatedBooleanFlag () throws Exception {
320
+ String content = "{\n \" foo array\" :[\" first\" ,\" second\" ] , \" someExtraProperty\" : \" which is NOT allowed\" \n }" ;
321
+ this .request .getBody ().write (content .getBytes ());
322
+
274
323
assertThatExceptionOfType (AssertionError .class ).isThrownBy (() ->
275
324
MockRestRequestMatchers
276
325
.content ()
0 commit comments