skyscreamer / JSONassert

Write JSON unit tests in less code. Great for testing REST interfaces.
http://jsonassert.skyscreamer.org
Apache License 2.0
1k stars 197 forks source link

compare failure, complex structure #60

Closed sdetweil closed 8 years ago

sdetweil commented 8 years ago

I am supporting wildcards (*) (to allow any data in that spot, in particular places in a json document.

I have one where the compare returns confusing info.

source content

[
{
  "commodities":[
       {
              "reason":"initial",
              "merchantComRefId":"Soccer01",
              "quantity":1,
              "recordIndex":2
       }
  ],
  "merchantParcelId":"46545100015600",
  "orderNumber":"ORMUSP111295059BR",
  "parcelSize":
  {
            "length":2,
            "weightUnit":"lb",
            "distanceUnit":"in",
            "weight":2,
            "height":2,
            "width":2
  },
  "dcId":"2622",  
  "shipper":
  {
            "name":"UPS",
            "service":"UPS Ground",
            "trackingNumber":"1ZW6X8760324049789"
  },
  "returnAddress":
  {
             "countryCode":"US",
             "firstName":"John",
             "lastName":"Doe",
             "phoneNumber":"1-317-123-4567",
             "email":"depot@returns.walmart.com",
             "street1":"3333 N Franklin Road",
             "street2":null,
             "street3":null,
             "city":"Indianapolis",
             "provinceOrState":"IN",
             "countyOrRegion":"US",
             "postalOrZipCode":"46226"
  }
}
]

model to compare to (the source looks good in the editor before save)

[{  
   "commodities":[  
      "_"
   ],
   "merchantParcelId":"_",
   "orderNumber":"_",
   "parcelSize":{  
      "length":"_",
      "weightUnit":"_",
      "distanceUnit":"_",
      "weight":"_",
      "height":"_",
      "width":"_"
   },
   "shipper":{  
      "name":"_",
      "service":"_",
      "trackingNumber":"_"
   },
   "dcId":""_"",  <----------field with trouble
      "returnAddress":{  
      "countryCode":"_",
      "firstName":"_",
      "lastName":"_",
      "phoneNumber":"_",
      "email":"_",
      "street1":"_",
      "street2":"_",
      "street3":"_",
      "city":"_",
      "countyOrRegion":"_",
      "provinceOrState":"_",
      "postalOrZipCode":"*"
   }
} 
]

I should get a compare error for every place there is an * in the model.

but it appears we lost a pointer to the error for some reason

error returned (<-- with comments)

Assert matching failed [dcId=] <--- right, \ in model Expected: a JSON object <--- yes but none found <---- what???? ; [dcId=2622] <---- input is correct Unexpected: a JSON object <--- say what??

using version 1.2.3 jsonassert-1.2.3.jar

sdetweil commented 8 years ago

code used to call (in groovy)

                Customization c = new Customization("/", null);
                def CustomComparator mc = new CaseInsensitiveComparator(JSONCompareMode.LENIENT, c);
                mc.setLogger(_logger);
                JSONAssert.assertEquals(test_body,request_body, mc);
sdetweil commented 8 years ago

i have found and fixed this problem in the 1.3.0 release..