0
votes

Based on the thread Jmeter - Compare/assert multiple data: Data from JSON against data from DB i manage to/and i need to do some enhancement how i verify the data.

This time i need to compare: Data from JSON

[
{
    "approveTime": 1582543485,
    "status": 0.1,
},
{
    "approveTime": 1582543463,
    "status": 0.2,
},
{
    "approveTime": 1586355699,
    "status": 0.3
}   
]

Against: Single row returned from DB

approveTime status 
1586355699 0.3

Using JSON extractor i am capable of getting all the data from the JSON with _ALL suffix:

enter image description here

as: 1582543485, 1582543463, 1586355699

And i am able to compare/assert as:

if ( vars.get("approvetime_GW").contains(vars.get("approve_time_DB")) == false ) {
    AssertionResult.setFailure(true);
    log.warn(vars.get("approvetime_GW") + "  vs. " + (vars.get("approve_time_DB"))   )
}

into: enter image description here

and, is working perfectly fine.

The whole script:

enter image description here

JSON is generated in the ${__V(url_${__intSum(${__jm__Loop Controller__idx},1,)},)} from the Loop controller, then overwritten in the next iteration.

Data from DB is generated in the 001_2 JDBC, also overwritten in the next iteration, so data is dynamic on the every single run

But, in this way i am afraid to have some false positive results, and i am curious is there any better way how i can assert my data using equals method rather than contains, so initially i can loop through all the approveTime's, and then i can assert it using equals method?

Any help is appreciated!

2
Although I responded for the query, coming to think of it, I understand that you want to compare each object on the JSON array with the single row fetched from DB in which case my answer holds good. But in case you want to validate the presence of the data fetched from DB against the entire array data in JSON, contains is the way to go since in this case the comparison is between a single value against an arrayM Navneet Krishna

2 Answers

1
votes

Considering the fact that they are all strings, you can directly use == for comparison of the strings

If both are equal, in that case the if condition is triggered enter image description here

If unequal, in that case the else gets triggered enter image description here

You can include additional else if conditions for further filtering

0
votes

Why do you need all the approve times if you need only the last one?

The relevant JSON Path query to get the approveTime value for the 0.3 status would be:

$..[?(@.status == '0.3')].approveTime

enter image description here

More information: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios