cancel
Showing results for 
Search instead for 
Did you mean: 

Validate multiple values from Database.

SOLVED
Highlighted
New Contributor

Validate multiple values from Database.

Hi all, I have a bit of a challenge. I am new to soap UI and Groovy scripting. I am comparing few values from my output to the database values. So my test case contains: 1. DataSource which will return few rows. 2. Rest request which will return the json nodes. I am using content assertion to compare values, if the DataSource returns single row my assertion works fine but when there are multiple rows it will only compare 1st row not the other rows. Is there any option to compare multiple rows that are returned? 

Example:

My JSON output is something like this:

 "parents": [
      {
        "personalTitlePrefix": null,
        "firstName": "XYZ",
        "middleName": null,
        "lastName": "ABC",
        "generationCodeSuffix": null,
        "maidenName": null,
        "gender": "U",
        "relationship": null,
        "isPrimaryContact": false
      },
      {
        "personalTitlePrefix": null,
        "firstName": "XYZ1",
        "middleName": null,
        "lastName": "ABC1",
        "generationCodeSuffix": null,
        "maidenName": null,
        "gender": "U",
        "relationship": null,
        "isPrimaryContact": true
      },
      {
        "personalTitlePrefix": null,
        "firstName": "XYZ2",
        "middleName": null,
        "lastName": "ABC2",
        "generationCodeSuffix": null,
        "maidenName": null,
        "gender": "U",
        "relationship": null,
        "isPrimaryContact": true
      }
    ],

 I need to compare FirstName, LastName,Gender and PrimaryContact values from the database.

 

Another question is isPrimaryContact value is 1 or 0 in DataBase, where 1 would return true and 0 would be false in Json output. How do I convert them to match the content?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

You can use if condition and setting desired values at your script level.

 

for ex: if DB return 1 then 

 

def dbVal = "YOUR DB QUERY"

if(dbVal == "1"){

dbVal = "true"

}

else{

dbVal = "false"

}

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

7 REPLIES 7
Highlighted
Community Hero

Hi @chsekhar 

 

If I understand correctly - to verify certain attributes have multiple values I think you could use a script assertion (script assertion on the test step) - something like the following:

 

//courtesy of Rao
def object = new JsonSlurper().parseText(response.text) assert object.Parents.firstName == ['XYZ', 'XYZ1', "XYZ2"]

or perhaps something like the following:

 

//courtesy of Rao
def json = new groovy.json.JsonSlurper().parseText(context.response) assert json.Parents.firstName.every{it == 'XYZ' || 'XYZ1' || 'XYZ2'}

Hope this helps,

 

cheers,

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Highlighted
Community Leader

@chsekhar ,

 

As far as i know, you can't verify this via content assertion, for this to validate you need to write some groovy code.

 

1. First you just check size of parent array

2. then iterate and assert through each node you want to validate.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Moderator

Hi all,

 

@chsekhar, were the above replies helpful? If so, could you please click the button below the appropriate reply to accept it as a solution?

Otherwise, please provide us with updates.

Thank you in advance.


Olga Terentieva
SmartBear Assistant Community Manager

Highlighted
New Contributor

@richie Thanks for your reply, I will try it out and see how it goes. Also my 2nd question was  isPrimaryContact value is 1 or 0 in DataBase, where 1 would return true and 0 would be false in Json output. How do I convert them to match the content?

New Contributor

@HimanshuTayal Thanks for the reply. Do you have any idea how do I convert the values so I can match 1 to true and 0 to false

isPrimaryContact value is 1 or 0 in DataBase, where 1 would return true and 0 would be false in Json output. 

Highlighted
Community Leader

You can use if condition and setting desired values at your script level.

 

for ex: if DB return 1 then 

 

def dbVal = "YOUR DB QUERY"

if(dbVal == "1"){

dbVal = "true"

}

else{

dbVal = "false"

}

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

Highlighted
Moderator

Thank you for the replies, Himanshu!

 

@chsekhar, any updates on your progress?


Olga Terentieva
SmartBear Assistant Community Manager

New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Want a fun and easy way to learn ReadyAPI and show off your skills? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get a full Raw JMS request

Participate!

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Get data from Petstore and add it to Excel sheets

Participate!
Top Kudoed Authors