Forum Discussion

sarat99's avatar
sarat99
New Contributor
11 years ago

[Res]How to test the Cust list for which the order is undefi

I have a REST Response where I get the customer list but the order is not defined. I want to validate each and every customer returned in the list with my data file (in Excel format). Please help me in achieving this. Below is the response I am getting (JSON format)

{"custProfile": {
"_elapsedTime": "699",
"code": "00",
"custProfileList": [
{
"addr": {
"addrLocTyp": "HOME",
"stCd": "2"
},
"brthdyDt": "1945-04-01T00:00:00-04:00",
"custCmntTxt": "eksjdf ksdjfh skdjfh ksdjfh djskfh sdjkfh sdjkfh sdkjfh sdkf sdf sdf",
"custId": "501491",
"custRefNm": "Duckworth Vera",
"custStusCd": "Y",
"dytmPhonNr": "121021021021111",
"dytmStdPhonCd": "02",
"emailAddrTxt": "vera@sound.com",
"evngPhonNr": "056405405405405",
"evngStdPhonCd": "02",
"frstNm": "Duckworth",
"lastNm": "Vera",
"repAcctNr": "33949401",
"success": "true",
"timeZoneCd": "Australia/Sydney",
"titlCd": "2"
},
{
"addr": {
"addrLocTyp": "HOME",
"stCd": "0"
},
"custId": "501635",
"custRefNm": "Ewen Jackie",
"custStusCd": "Y",
"emailAddrTxt": "jackie.ewen@avon.com",
"frstNm": "Ewen",
"lastNm": "Jackie",
"repAcctNr": "33949401",
"success": "true",
"timeZoneCd": "Australia/Sydney",
"titlCd": "2"
},
{
"addr": {
"addrLocTyp": "HOME",
"custAddr2Txt": "dasdasd",
"custAddr3Txt": "asdasdas",
"custAddrTxt": "43dadasdas",
"stCd": "QLD"
},
"brthdyDt": "1974-01-01T00:00:00-05:00",
"custCmntTxt": "sadasdasd",
"custId": "501495",
"custRefNm": "ykhjkjh kjhkjhkhjk",
"custStusCd": "Y",
"dytmPhonNr": "234234234234234",
"dytmStdPhonCd": "02",
"emailAddrTxt": "erterter@jggj.com",
"evngPhonNr": "234234342342342",
"evngStdPhonCd": "02",
"frstNm": "ykhjkjh",
"lastNm": "kjhkjhkhjk",
"mobilePhonNr": "2342342342",
"repAcctNr": "33949401",
"success": "true",
"timeZoneCd": "Australia/Sydney",
"titlCd": "3"
},
{
"addr": {
"addrLocTyp": "HOME",
"stCd": "0"
},
"custId": "501814",
"custRefNm": "jhkh hkhk",
"custStusCd": "Y",
"frstNm": "jhkh",
"lastNm": "hkhk",
"repAcctNr": "33949401",
"success": "true",
"timeZoneCd": "Australia/Sydney",
"titlCd": "1"
},
{
"addr": {
"addrLocTyp": "HOME",
"stCd": "0"
},
"brthdyDt": "1980-01-01T00:00:00-05:00",
"custId": "501574",
"custRefNm": "Test Test",
"custStusCd": "Y",
"emailAddrTxt": "test@test.com",
"frstNm": "Test",
"lastNm": "Test",
"repAcctNr": "33949401",
"success": "true",
"timeZoneCd": "Australia/Sydney",
"titlCd": "3"
},
{
"addr": {
"addrLocTyp": "HOME",
"pstlCd": "1212",
"stCd": "5"
},
"brthdyDt": "1974-05-04T00:00:00-04:00",
"custCmntTxt": "wt rwet ret ert qetqr qwert qert qerteqrt erte",
"custId": "501490",
"custRefNm": "Bank Jeff",
"custStusCd": "Y",
"frstNm": "Bank",
"lastNm": "Jeff",
"repAcctNr": "33949401",
"success": "true",
"timeZoneCd": "Australia/Sydney",
"titlCd": "3"
},
{
"addr": {
"addrLocTyp": "HOME",
"stCd": "0"
},
"custId": "501594",
"custRefNm": "tst tst",
"custStusCd": "Y",
"frstNm": "tst",
"lastNm": "tst",
"repAcctNr": "33949401",
"success": "true",
"timeZoneCd": "Australia/Sydney",
"titlCd": "3"
},
{
"addr": {
"addrLocTyp": "HOME",
"stCd": "0"
},
"brthdyDt": "1981-12-12T00:00:00-05:00",
"custCmntTxt": "test",
"custId": "502943",
"custRefNm": "Jeff ohlmann",
"custStusCd": "Y",
"frstNm": "Jeff",
"lastNm": "ohlmann",
"repAcctNr": "33949401",
"success": "true",
"timeZoneCd": "Australia/Sydney",
"titlCd": "0"
},
{
"addr": {
"addrLocTyp": "HOME",
"stCd": "0"
},
"brthdyDt": "1954-06-04T00:00:00-04:00",
"custCmntTxt": "JKF JKSDFH JKSDFH SJKDFH JKSDFH KSDJFH KSDJFH SDJKFH JKSDFH KDSJFH KJDSFH K KJH SDJKFH KSDJFH KSDJFH SDKJF KSDJFH SDKJFH KDSJ FHKSDJFH KDJFH KSDJ KDSFH KSDJFH SDKJ",
"custId": "501492",
"custRefNm": "Jammin Seoul",
"custStusCd": "Y",
"emailAddrTxt": "DANCE@GREAT.COM",
"frstNm": "Jammin",
"lastNm": "Seoul",
"repAcctNr": "33949401",
"success": "true",
"timeZoneCd": "Australia/Sydney",
"titlCd": "2"
},
{
"addr": {
"addrLocTyp": "HOME",
"stCd": "0"
},
"custId": "501497",
"custRefNm": "vbnvbnvbnvbnvbn vbnvbnvbn",
"custStusCd": "Y",
"frstNm": "vbnvbnvbnvbnvbn",
"lastNm": "vbnvbnvbn",
"repAcctNr": "33949401",
"success": "true",
"timeZoneCd": "Australia/Sydney",
"titlCd": "1"
},
{
"addr": {
"addrLocTyp": "HOME",
"stCd": "0"
},
"brthdyDt": "1964-01-01T00:00:00-05:00",
"custId": "501496",
"custRefNm": "asdasdarwerwer rwerwfertyerte",
"custStusCd": "Y",
"dytmPhonNr": "104054065406540",
"dytmStdPhonCd": "05",
"emailAddrTxt": "jgjgj@lsls.com",
"evngPhonNr": "654065406540654",
"evngStdPhonCd": "05",
"frstNm": "asdasdarwerwer",
"lastNm": "rwerwfertyerte",
"repAcctNr": "33949401",
"success": "true",
"timeZoneCd": "Australia/Sydney",
"titlCd": "1"
},
{
"addr": {
"addrLocTyp": "HOME",
"cityNm": "gsdfgsdfgsd",
"custAddr2Txt": "sdgdsfg",
"custAddr3Txt": "sdfgsdf",
"custAddrTxt": "fdsgsdfg",
"pstlCd": "2345",
"stCd": "ACT"
},
"brthdyDt": "1984-12-10T00:00:00-05:00",
"custCmntTxt": "sdfgdfsgdsf",
"custId": "502371",
"custRefNm": "Krishnan Rajesh",
"custStusCd": "Y",
"dytmPhonNr": "342523452435",
"dytmStdPhonCd": "02",
"emailAddrTxt": "rajesh_krishnan02@infosys.com",
"frstNm": "Krishnan",
"lastNm": "Rajesh",
"mobilePhonNr": "2345234524",
"repAcctNr": "33949401",
"success": "true",
"timeZoneCd": "Australia/Sydney",
"titlCd": "3"
}
],
"mrktCd": "AU",
"repAcctNr": "33949401",
"success": "true",
"timeStamp": "2013-04-01 14:12:08 122",
"token": "f3BwleNr5AbIUIQfyM0PICN+tidoAGLWjYY1X3gga9e7u6o3W0M1ybPZQffn6vIKwnpmQjMC7PIUYsGKi3+pB+TJpqFfmv4a"
}}

5 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    Thank you for your inquiry, and I'm sorry that we kept you waiting a couple of days.

    This is definitely doable, but it's a bit more difficult than if we would've known the order. What exactly do you want to validate - do you want to check that every customer profile in the JSON response exists in your excel spreadsheet, or the other way around?


    Regards,

    Arian
    SmartBear Sweden
  • sarat99's avatar
    sarat99
    New Contributor
    Thanks for the reply and sorry for my delayed reply.

    I am happy to hear that this is doable. I want to validate in a way to check that every customer profile in the JSON response exists in an excel spreadsheet. I will pull the data from Data Base to a excel file and then wanted to validate the JSON response against the data I have in the excel file.
  • sarat99's avatar
    sarat99
    New Contributor
    Hi Arian,

    Can you please help me on this ASAP?

    Thanks,
    Sarat
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi again Sarat,

    I once again apologize for keeping you waiting. Here's my solution:

    Structure your test case like this:



    In the first step, "Read Excel DataSource", create a data source using your excel data file and save each customer's name (or ID, or whatever you want to validate) in a property (In my example I've called it "name").

    In the second step, run the following script in the "Add name to list" step:
    if ( context["allRows"] == null )
    context["allRows"] = []

    context["allRows"] << context.expand('${Read Excel DataSource#name}')

    This creates a list in the context object so that we can access it later, and enters the current "name" property into it.

    We want to fill this list with all the customer names, so we add a "DataSource Loop" using the excel file and with the groovy test step as the target.

    Then, after performing your "REST request" and receiving a response, we want to check that all the customers exist in this aforementioned list (that we built using the excel data source). In order to do this we use a second groovy script (the "Validate names" step), utilizing the JsonSlurper class (http://groovy.codehaus.org/gapi/groovy/ ... urper.html).

    Here's a quick (untested) groovy snippet that should work:

    import groovy.json.JsonSlurper

    def nameList = context["allRows"]
    def responseString = context.expand( '${REST request#Response}' )

    def slurper = new JsonSlurper()
    def response = slurper.parseText(responseString)

    for (customer in custProfile.custProfileList)
    assert nameList.contains(customer.custRefNm)


    I hope this helps. Normally we don't support groovy, but I made an exception in this case. Let me know if you have any further questions!

    Regards,

    Arian
    SmartBear Sweden