Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Comparing values

reactancexl
reactancexl Posts: 177

I have a set of values from one rest call. I need to verify if they exist in another rest call. First call may have 5 values and second call may have 15. What is the best way to validate if the first value(s) is contained in second? Sample Data: below data returned as a JSON array.
First Call Second Call

100 345
200 77
300 200
400 500
500 300
123
222
777
543

Tagged:

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,306 ✭✭✭
    edited August 2021

    I believe you would chain a Data Bank to the first REST Client to extract the values. When extracting multiple values, you can use an XPath that uses the "string-join" function so you can delimit each value with a comma, for example. So, your data bank would contain a comma-separated list of the values. Then you can chain an Assertor to the second REST Client to do the comparison. In the Assertor, you would configure a Value Assertion that extracts the values from the second client in a similar way, maybe using "string-join" to delimit the values, and then you specify the data bank column from the first test as the Expected Value.

    It looks like someone posted a variant of this high level approach which you may also want to review: Validating Variable Length Lists In API Responses

  • reactancexl
    reactancexl Posts: 177

    Thanks for the info. The string-join worked by concatenating all my array values from source and target. then the script below is doing the validation (Jython)

Tagged