2

I am trying to compare the rest API response of two environments. I am using rest assured to get the response back. The problem I am facing is that I get a hashmap back which has a couple of hashmaps.

I have tried flattening the map into one map but keep on missing a hierarchy when the response differs slightly

here is a sample of the rest response

{  
   programmes:[  
      {  
         episodenumber:21,
         seasonnumber:5,
         seasontitle:"program Season 5",
         seasonuuid:"7aabb30e-39a1-48bb-8dca-38f732c9c982",
         seriestitle:"programm",
         seriesuuid:"f95caa09-8cd7-4e23-a88a-444f7932714d",
         sy:"blah blah blah. (S5, ep 21)",
         t:"blah blah Fathers",
         trailer:false,
         type:"programme",
         uuid:"69b91264-37c9-4b2f-a515-b45805a58867",
         uuidtype:"programme",
         waystowatch:{  
            svod:[  
               {  
                  ad:false,
                  added:1495800164,
                  at:"DD",
                  availendtime:1497729599,
                  broadcasttime:1495137600,
                  cgid:10053,
                  cgname:"blah",
                  channelname:"blah1 HD",
                  d:2880,
                  downloadlink:"oig://FFC27E94",
                  hardofhearing:false,
                  is3d:false,
                  providerid:"ab_st_hd",
                  providername:"blah HD",
                  s:true,
                  sid:4061,
                  size:2352611,
                  sy:"blah blah. (S5, ep 21)",
                  videotype:"HD"
               }
            }
         ]         ps:255,
         tc:3
      }

I am using the guava diff lib and for that, i need a simple map. I know this might not be the best of doing this comparison but this is for a short duration and this is what I can come up with. My question is how do I either flatten this response to make one map which i can pass to

 MapDifference<String, ?> diff = Maps.difference(test, test2);

or is there a better way to compare two responses in rest assured. I have to get both the response at runtime.

MQ_
  • 51
  • 7

1 Answers1

0

If you are open to evaluating other tools take a look at Karate because it has been designed to:

  • allow you to specify expected payloads in (simplified) JSON itself
  • enable you to perform a "deep equals" comparison of two JSON payloads
  • be flexible so that you do a contains if you only want to check a sub-set of fields
  • handle dynamic values by letting you mark those fields as to be ignored or use a fuzzy match
  • even let you handle arrays where the elements are JSON (not just primitives), and ignore the order if needed

Disclaimer: am dev.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248