cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help! REST Assertion

bjnsalgado
New Contributor

Need Help! REST Assertion

Good day! I'm having some trouble with assertions. Currently I have a JSON response below:

<Response xmlns="URL">
<code null="true"/>
<message null="true"/>
<status>Success</status>
<data>
<providerType>Medical</providerType>
<providerNumber>AAAAA</providerNumber>
<providerName>NAME</providerName>
<registrations>
<e>
<dateOn>30/10/1995</dateOn>
<dateOff/>
<state>NSW</state>
<status>PracticeActiveOpen</status>
<bulkPayIndicator>NoBulkPayment</bulkPayIndicator>
</e>
</registrations>
<specialityCodes>
<e>
<code>33</code>
<dateOn>01/07/1997</dateOn>
<dateOff/>
</e>
<e>
<code>104</code>
<dateOn>02/01/1987</dateOn>
<dateOff/>
</e>
</specialityCodes>
<supplements>
<e>
<hospitalType/>
<hospitalClass>0</hospitalClass>
<coPay>P</coPay>
<contractInd>true</contractInd>
<groupBenefitCode/>
<dateOn>23/02/1998</dateOn>
<dateOff/>
</e>
<e>
<hospitalType/>
<hospitalClass>0</hospitalClass>
<coPay>P</coPay>
<contractInd>true</contractInd>
<groupBenefitCode/>
<dateOn>23/02/1998</dateOn>
<dateOff>23/02/1998</dateOff>
</e>
<e>
<hospitalType/>
<hospitalClass>0</hospitalClass>
<coPay>P</coPay>
<contractInd>true</contractInd>
<groupBenefitCode/>
<dateOn>23/02/1998</dateOn>
<dateOff>23/02/1998</dateOff>
</e>
<e>
<hospitalType/>
<hospitalClass>0</hospitalClass>
<coPay>P</coPay>
<contractInd>true</contractInd>
<groupBenefitCode/>
<dateOn>23/02/1998</dateOn>
<dateOff>23/02/1998</dateOff>
</e>
</supplements>
</data>
</Response>

 

How can I have assertions for each of the below elements using the DB value? The elements can be dynamic as we can add or delete a particular hospital type.

<hospitalType/>
<hospitalClass>0</hospitalClass>
<coPay>P</coPay>
<contractInd>true</contractInd>
<groupBenefitCode/>
<dateOn>23/02/1998</dateOn>
<dateOff>23/02/1998</dateOff>

 

Thanks for the inputs.

3 REPLIES 3
richie
Community Hero

Re: Need Help! REST Assertion

Hi, @bjnsalgado,

Firstly can you confirm if the response detail is correct? You mention that the response is .json, but the response you posted is actually .xml.

Secondly you mention you want to assert against certain tags/attributes using a 'DB' value. Can you clarify what 'DB' value means? Do you mean DataBase? Or do you mean something different?

Thirdly. I "think" what you are asking for is that certain attributes/tags may have different values depending on certain conditions....is that right? If thats correct and i understand your problem (i may not!) then you can use an xpath assertion (if xml) or a script assertion according to SiKing's response to another post on this forum.

The relevant link is aa follows (sorry im typing this out on my phone so i havent got the embed link functionality for some reason)

https://community.smartbear.com/t5/SoapUI-Pro/Resolved-assertion-against-multiple-expected-values/td...

Hope ive been of some help!

Richie
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
bjnsalgado
New Contributor

Re: Need Help! REST Assertion

Hello @richie

 

Thank you for taking time to respond to my question.

 

To answer your questions,

1. here is the JSON response. I copied and paste the XML. Apologies for the confusion.

{
"code" : null,
"message" : null,
"status" : "Success",
"data" : {
"providerType" : "Medical",
"providerNumber" : "AAAAAAAA",
"providerName" : "NAME",
"registrations" : [
{
"dateOn" : "30/10/1995",
"dateOff" : "",
"state" : "NSW",
"status" : "PracticeActiveOpen",
"bulkPayIndicator" : "NoBulkPayment"
}
],
"specialityCodes" : [
{
"code" : 33,
"dateOn" : "01/07/1997",
"dateOff" : ""
},
{
"code" : 104,
"dateOn" : "02/01/1987",
"dateOff" : ""
}
],
"supplements" : [
{
"hospitalType" : "",
"hospitalClass" : 0,
"coPay" : "P",
"contractInd" : true,
"groupBenefitCode" : "",
"dateOn" : "23/02/1998",
"dateOff" : ""
},
{
"hospitalType" : "",
"hospitalClass" : 0,
"coPay" : "P",
"contractInd" : true,
"groupBenefitCode" : "",
"dateOn" : "23/02/1998",
"dateOff" : "23/02/1998"
},
{
"hospitalType" : "",
"hospitalClass" : 0,
"coPay" : "P",
"contractInd" : true,
"groupBenefitCode" : "",
"dateOn" : "23/02/1998",
"dateOff" : "23/02/1998"
},
{
"hospitalType" : "",
"hospitalClass" : 0,
"coPay" : "P",
"contractInd" : true,
"groupBenefitCode" : "",
"dateOn" : "23/02/1998",
"dateOff" : "23/02/1998"
}
]
}
}

 

2. I am currently trying to validate the value from the JSON response versus the Database values that we have.

3. Thirdly. I "think" what you are asking for is that certain attributes/tags may have different values depending on certain conditions....is that right? - Yes, this is correct.

aaronpliu
Frequent Contributor

Re: Need Help! REST Assertion

Hi binsalgado,

 

You may parse JSON with groovy.json.JsonSlurper to get JSON object, and then loop.

 

For example(In Groovy Script step):

def request = testRunner.testCase.testSteps["YourStepName"].testRequest

def response = request.response.contentAsString

def slurper = new groovy.json.JsonSlurper().parseText(response)

slurper.supplements.each{

     // add your script to verify

    // log.info it.hospitalType

}

 

New Here?
Join us and watch the welcome video:
Top Kudoed Authors