Suggestions for how to assert test with embedded json in xml response
I running tests on a service that return an xml response, but some of the information is in a json format. I need to validate the json part of the test, and I don't know if there is a way of doing this without custom assertions. Has anyone done something like this before?
I need to assert for instance, that the count of elements in BookingByStatus for Status B is 4
This is an example of the response:
{"Date":"2018-12-06T00:00:00","LastBookingDateUtc":"2018-11-29T20:15:46","CalendarID":6780,"HotelID":7427,"ChainID":8001587,"BookingByStatus":[{"Count":4,"Status":"B","OnPropertyStatus":"N"},{"Count":28,"Status":"R","OnPropertyStatus":"H"},{"Count":24,"Status":"R","OnPropertyStatus":"N"},{"Count":4,"Status":"R","OnPropertyStatus":"A"},{"Count":8,"Status":"R","OnPropertyStatus":"C"},{"Count":8,"Status":"X","OnPropertyStatus":"N"}],"ArrivalByStatus":[{"Count":4,"Status":"R","OnPropertyStatus":"C"}],"DepartureByOnPropertyStatus":[{"Count":4,"Status":"B","OnPropertyStatus":"N"},{"Count":28,"Status":"R","OnPropertyStatus":"H"},{"Count":20,"Status":"R","OnPropertyStatus":"N"},{"Count":4,"Status":"R","OnPropertyStatus":"A"},{"Count":4,"Status":"R","OnPropertyStatus":"C"},{"Count":8,"Status":"X","OnPropertyStatus":"N"}],"LOSByStatus":[{"Key":3,"Count":4,"Status":"B","OnPropertyStatus":"N"},{"Key":3,"Count":28,"Status":"R","OnPropertyStatus":"H"},{"Key":3,"Count":20,"Status":"R","OnPropertyStatus":"N"},{"Key":3,"Count":4,"Status":"R","OnPropertyStatus":"A"},{"Key":3,"Count":8,"Status":"R","OnPropertyStatus":"C"},{"Key":1,"Count":4,"Status":"R","OnPropertyStatus":"N"},{"Key":3,"Count":8,"Status":"X","OnPropertyStatus":"N"}],"BookingByGuestAgeGroupAndStatus":[{"Key":"Adult","Count":4,"Status":"B","OnPropertyStatus":"N"},{"Key":"Children","Status":"B","OnPropertyStatus":"N"},{"Key":"Adult","Count":28,"Status":"R","OnPropertyStatus":"H"},{"Key":"Children","Status":"R","OnPropertyStatus":"H"},{"Key":"Adult","Count":24,"Status":"R","OnPropertyStatus":"N"},{"Key":"Children","Status":"R","OnPropertyStatus":"N"},{"Key":"Adult","Count":4,"Status":"R","OnPropertyStatus":"A"},{"Key":"Children","Status":"R","OnPropertyStatus":"A"},{"Key":"Adult","Count":8,"Status":"R","OnPropertyStatus":"C"},{"Key":"Children","Status":"R","OnPropertyStatus":"C"},{"Key":"Adult","Count":8,"Status":"X","OnPropertyStatus":"N"},{"Key":"Children","Status":"X","OnPropertyStatus":"N"}],"ArrivalByGuestAgeGroupAndStatus":[{"Key":"Adult","Count":4,"Status":"R","OnPropertyStatus":"C"},{"Key":"Children","Status":"R","OnPropertyStatus":"C"}],"DepartureByGuestAgeGroupAndStatus":[{"Key":"Adult","Count":4,"Status":"B","OnPropertyStatus":"N"},{"Key":"Children","Status":"B","OnPropertyStatus":"N"},{"Key":"Adult","Count":28,"Status":"R","OnPropertyStatus":"H"},{"Key":"Children","Status":"R","OnPropertyStatus":"H"},{"Key":"Adult","Count":20,"Status":"R","OnPropertyStatus":"N"},{"Key":"Children","Status":"R","OnPropertyStatus":"N"},{"Key":"Adult","Count":4,"Status":"R","OnPropertyStatus":"A"},{"Key":"Children","Status":"R","OnPropertyStatus":"A"},{"Key":"Adult","Count":4,"Status":"R","OnPropertyStatus":"C"},{"Key":"Children","Status":"R","OnPropertyStatus":"C"},{"Key":"Adult","Count":8,"Status":"X","OnPropertyStatus":"N"},{"Key":"Children","Status":"X","OnPropertyStatus":"N"}]}
{"Date":"2018-12-05T00:00:00","LastBookingDateUtc":"2018-11-28T21:11:59","CalendarID":6779,"HotelID":7427,"ChainID":8001587,"BookingByStatus":[{"Count":4,"Status":"B","OnPropertyStatus":"N"},{"Count":28,"Status":"R","OnPropertyStatus":"H"},{"Count":24,"Status":"R","OnPropertyStatus":"N"},{"Count":4,"Status":"R","OnPropertyStatus":"A"},{"Count":4,"Status":"R","OnPropertyStatus":"C"},{"Count":8,"Status":"X","OnPropertyStatus":"N"}],"ArrivalByStatus":[{"Count":8,"Status":"R","OnPropertyStatus":"N"}],"DepartureByOnPropertyStatus":[],"LOSByStatus":[{"Key":3,"Count":4,"Status":"B","OnPropertyStatus":"N"},{"Key":3,"Count":28,"Status":"R","OnPropertyStatus":"H"},{"Key":3,"Count":20,"Status":"R","OnPropertyStatus":"N"},{"Key":3,"Count":4,"Status":"R","OnPropertyStatus":"A"},{"Key":3,"Count":4,"Status":"R","OnPropertyStatus":"C"},{"Key":1,"Count":4,"Status":"R","OnPropertyStatus":"N"},{"Key":3,"Count":8,"Status":"X","OnPropertyStatus":"N"}],"BookingByGuestAgeGroupAndStatus":[{"Key":"Adult","Count":4,"Status":"B","OnPropertyStatus":"N"},{"Key":"Children","Status":"B","OnPropertyStatus":"N"},{"Key":"Adult","Count":28,"Status":"R","OnPropertyStatus":"H"},{"Key":"Children","Status":"R","OnPropertyStatus":"H"},{"Key":"Adult","Count":24,"Status":"R","OnPropertyStatus":"N"},{"Key":"Children","Status":"R","OnPropertyStatus":"N"},{"Key":"Adult","Count":4,"Status":"R","OnPropertyStatus":"A"},{"Key":"Children","Status":"R","OnPropertyStatus":"A"},{"Key":"Adult","Count":4,"Status":"R","OnPropertyStatus":"C"},{"Key":"Children","Status":"R","OnPropertyStatus":"C"},{"Key":"Adult","Count":8,"Status":"X","OnPropertyStatus":"N"},{"Key":"Children","Status":"X","OnPropertyStatus":"N"}]}
Comments
-
I'm assuming that the JSON is embedded within an XML element. If that is the case, you should be able to use an XML Transformer to extract the JSON, and then send that to a JSON Assertor to do the assertions.
0 -
Yes the JSON is embedded, I looked in the help for examples of XML Transformer, but couldn't find anything in detail.
0 -
Actually, I think this is simpler with an XML Data Bank and and JSON Assertor. Let's assume you have XML like the following:
<xml> <jsonElement> { "foo":"bar" } </jsonElement> </xml>
Create an XML Data Bank to extract the content of "jsonElement". Then create a standalone JSON Assertor. In the input tab of the JSON Assertor, use the Data Source option and select the data source column name specified in the XML Data Bank.
0