Forum Discussion

Apoorva6's avatar
Apoorva6
Frequent Contributor
8 years ago

How to compare node values in Rest services?

Hi Team,

 

I have 2 requests. One will create the account and another will retrieve the account details. Once the account is created, I need to compare the the account number with the one retrieved and both should match which means Test step should pass, else fail it.

 

Response1

 

{
   "invoiceNodeDetails":    {
      "nodeLabel": "mx",
      "hierarchyPointId": "18648",
      "nodeStartDate": "20170420 19:40:35",
      "sequenceNumber": "982985",
      "updateDate": "20170420 19:40:35",
      "nodeCreateDate": "20170422 05:40:17",
      "account1Number": "8290000000746"
   },
   "transactionDetails":    {
      "startRow": "1",
      "endRow": "400",
      "totalRow": "1",
      "timeZone": "EST"
   },
   "orderDetails": {"serviceOrderNumber": "MX-EUAM-35056"}
}

 

Response2:

 

In Retrieval, we will get same account number which we need to map. But it is in CDATA

 

<data contentType="application/jason; charset=UTF-8" contentLength="4477"><![CDATA[{"transactionDetails":{"startRow":"1","endRow":"400","totalRow":"1","timeZone":"EST"},"invoiceNodeList":[{"InvoiceNode":{"invoiceNodeDetails":{"invoiceArrangement":null,"invoiceForward":null,"printZeroChargesIndicator":"","customerLegalName":"","forwardStartDate":"20170420 19:40:35","forwardEndDate":null,"oclIndicator":null,"document":null,"billprintSuppression":null,"nodeType":"I","nodeId":"8290000000746","nodeLabel":"mx","hierarchyPointId":"18648","nodeStartDate":"20170420 19:40:35","endDate":"","cfmStartDate":"","sequenceNumber":"982985","billPeriod":"11","interOfferRelinkDate":"","creditMemoVat":"","mcsIndicator":"","rebateAccountIdentifier":"","rollupOption":"","rollupDetails":"","gsaNumber":"","seiLeadAccountNumber":"","cssReferenceNumber":"","cssEffectiveDate":"","cssEndDate":"","solutionBillIdentifier":"","invoiceCurrency":"","ratingCurrency":"USD","language":"ENG","paymentMethod":"","eRateIndicator":"","eFileIndicator":"","eFileClientId":"","transferOfService":"","monthlyChargeBillPeriod":"","billFrequency":"","singleDomesticBillBundling":"","paymentAccountSuffix":"","billingName1":"Martins Super Markets","billingName2":"","billingName3":"","billingName4":null,"manualBillAuthorizationNumber":"","specialBillingInvoiceIdentifier":"","csfIdentifier":"","billPrintSupression":"","foreignAccountStartRow":"","foreignAccountEndRow":"","foreignAccountCount":"0","leadMCN":"","billingType":"2","billFrequencyDate":null,"purchaseOrderNumber":"","siVendorName":null,"sifIdentifier":null,"updateDate":null,"nodeCreateDate":null,"account1Number":null,"federalTaxExemptionCode":"","stateTaxExemptionCode":"","countyTaxExemptionCode":"","cityTaxExemptionCode":"","otherTaxExemptionCode":"","seiIndicator":"","planCount":null,"installedServiceList":[],"foreignAccountList":[],"specialBidList":[],"documentComponentList":[{"documentType":"media","documentTypeValue":"0001","offerCode":null,"productHierarchyPathCode":"0000096300013085"},{"documentType":"media","documentTypeValue":"0001","offerCode":null,"productHierarchyPathCode":"000009630001308500013086"},{"documentType":"format","documentTypeValue":"1001","offerCode":null,"productHierarchyPathCode":"00000963000130850001308600013087"},{"documentType":"delivery","documentTypeValue":"C001","offerCode":null,"productHierarchyPathCode":"00000963000130850001308600013088"}]},"parentNodeDetails":{"customerExcerpt":{"customerId":"31132066","customerName":"New Customer Node Details","hierarchyPointSequenceNumber":null,"planCount":null},"hierarchyExcerpt":{"parentageLevel":"2","account1Number":"","hierarchyPointId":"114013556","nodeLabel":"New Hierarchy Node Label","customerBillingHierarchyId":"33320982","hierarchyPointSequenceNumber":null,"planCount":"1"},"bundleAggregatorExcerpt":{"parentageLevel":"1","account1Number":"50000310574","nodeLabel":"Modifieddescription","hierarchyPointId":"114013557","hierarchyPointSequenceNumber":null,"planCount":"68"},"invoiceExcerpt":null,"customerDefinedGroupExcerpt":null,"subAccountExcerpt":null,"genericAggregatorExcerpt":null,"locationAggregatorExcerpt":null,"nonNetworkSiteNodeExcerpt":null},"addressList":[{"addressId":"17366","addressType":"Reporting Address","addressLine1":"760 W. COTTER STREET","addressLine2":"25 Florence ave.","addressLine3":"painesvilee OH 44077","addressLine4":"dtr","streetAddress":"radha","addressName":"Martins Super Markets","city":"painesvilee","state":"OH","province":"AP","zipCode":"45246","zipCodeSuffix":"2143","foreignPostalCode":"ABC","countyName":"andhra","countryName":"india","countryCode":"US","geoCode":"0136085200000","attentionName":"John Raab","siteId":null,"simultaneousCallCount":"","equipmentLocationId":"00698776","invoiceForward":"","addressStartDate":"20-APR-17","addressEndDate":null,"outsideCityLimitIndicator":"N","serviceLocationDetails":null},{"addressId":"17367","addressType":"Taxing Address","addressLine1":"sriram nagar","addressLine2":"near SBI","addressLine3":"DHONE","addressLine4":"Andhra pradesh I","streetAddress":"5055 PRESTON AVENUE","addressName":"hari","city":"PASADENA","state":"TX","province":"VI","zipCode":"43215","zipCodeSuffix":"5822","foreignPostalCode":"ABC","countyName":"karnataka","countryName":"japan","countryCode":"BR","geoCode":"0144201222000","attentionName":"neha","siteId":null,"simultaneousCallCount":"","equipmentLocationId":"009668","invoiceForward":"","addressStartDate":"20-APR-17","addressEndDate":null,"outsideCityLimitIndicator":"N","serviceLocationDetails":null}]}}]}]]></data>

  • Hi Apoorva6,

     

    In the second response, check the Raw tab. Do you see the XML tags there? Probably not. It seems that your server is misconfigured to return "Content-Type: application/jason" instead of "application/json". You should ask your developers to fix that, because it might cause problems with other clients.

     

    Assuming there are no XML tags in the actual raw response, you can use the JsonPath Match assertion:

    JSONPath Expression:

    $.invoiceNodeList[0].InvoiceNode.invoiceNodeDetails.nodeId

    Expected result:

    ${Response 1 Step Name#Response#$.invoiceNodeDetails.account1Number}

    Replace "Response 1 Step Name" with the corresponding step name.

     

    If you prefer shorter expressions:
    JSONPath Expression:

    $..nodeId

    Expected result:

    ${Response 1 Step Name#Response#$..account1Number} 

    ".." means recursive search.

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi Apoorva6,

     

    In the second response, check the Raw tab. Do you see the XML tags there? Probably not. It seems that your server is misconfigured to return "Content-Type: application/jason" instead of "application/json". You should ask your developers to fix that, because it might cause problems with other clients.

     

    Assuming there are no XML tags in the actual raw response, you can use the JsonPath Match assertion:

    JSONPath Expression:

    $.invoiceNodeList[0].InvoiceNode.invoiceNodeDetails.nodeId

    Expected result:

    ${Response 1 Step Name#Response#$.invoiceNodeDetails.account1Number}

    Replace "Response 1 Step Name" with the corresponding step name.

     

    If you prefer shorter expressions:
    JSONPath Expression:

    $..nodeId

    Expected result:

    ${Response 1 Step Name#Response#$..account1Number} 

    ".." means recursive search.

  • nmrao's avatar
    nmrao
    Champion Level 3
    Please format your data. Use code snippets.
  • Apoorva6's avatar
    Apoorva6
    Frequent Contributor
    HKosova, Thank you very much. Jason vs json is my mistake. Its taken care.

    nmrao could you please elaborate on using code snippet? Want to know more on that please.