Forum Discussion

bjnsalgado's avatar
bjnsalgado
New Contributor
7 years ago

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.

  • richie's avatar
    richie
    Community Hero
    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-p/38263

    Hope ive been of some help!

    Richie
    • bjnsalgado's avatar
      bjnsalgado
      New Contributor

      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's avatar
        aaronpliu
        Frequent Contributor

        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

        }