vlatko606
vlatko606

Reputation: 1149

Jmeter - Jmeter - Compare/assert multiple data:Data from JSON against data from DB(single row)

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!

Upvotes: 0

Views: 145

Answers (2)

Dmitri T
Dmitri T

Reputation: 167992

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

Upvotes: 0

M Navneet Krishna
M Navneet Krishna

Reputation: 694

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

Upvotes: 1

Related Questions