Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Nested JSON Array response validation

Parasofttoudaya
Parasofttoudaya Posts: 232 ✭✭
edited September 2017 in SOAtest

Hi Team,

Asserting array of response, which i achieved writing to a writable data source and looping thru the validation step in different test source. Here i got another problem For each array in response there is another child array is getting generated. How to assert this array child array responses.

for ( each array response1 ) {
-- Written the response to writable data source and created separate TestSuite to validate it.

Foreach child arrray of response 1 {
how to validate this??

}
}

Regards
Udaya

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    High level, think of each test suite as a loop. You can nest test suites to create nested loops. You can use multiple writable data sources as needed to store values for outer loop and inner loop.

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭

    Thanks for understanding so easy.

    Here i have a query in achieving that..
    Using writable data source is not possible as i cant predict the second level hierarchy array of response...

    if not i have to put everything in a single data source with reference.
    is there any way to achieve it??

    is it possible to create writable data source dynamic??

    Regards
    Udaya

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited September 2017

    I believe this is possible. Writable data sources are intended to be used when you can't predict what data might need to go there or how many rows might be needed. You should be able to do this with two writable data sources and two test suites, an outer and an inner. You would first have a test that would populate the first writable. Next, the outer suite would iterate over that, populating the second writable data source. Next, the inner test suite would run over each row in the second writable. The next time the outer suite is executed, the second writable will be automatically cleared and can be re-populated with new row data for the inner suite to run again.

    An example might be best to demonstrate. Unfortunately, I don't have one ready and I'm not sure I have time to do this any time soon. I am generally only able try to provide quick answers to users on the forum, to help steer SOAtest users in the right direction. Maybe someone else in the forum community can provide more help or detail if needed.

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭

    Thanks for the response, I will update the thread if i am stuck with anything..

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭
    edited September 2017

    Hi Benken ,

    I am able to pull the records.
    First Hierarchy of Array goes to writable data source and able to loop thru the testsuite with validation steps..

    Second Hierarchy : I am able to extract to different writable data source, But i am unable refer the row belongs to which array in 1st hierarchy...

    Explaining with an example:

    {
    "_embedded" : [
    {
    "orderid" : "XYZ",
    "orderAmount": "122.00",
    "customeName": "xxx",
    "products":[
    {
    "productid":"1212",
    "prodName" :"xxx",
    "prodcost" : "33.33"
    },
    {
    "productid":"1212",
    "prodName" :"xxx",
    "prodcost" : "33.33"
    },
    {
    "productid":"1212",
    "prodName" :"xxx",
    "prodcost" : "33.33"
    }

        ]
    },
    {
        "orderid" : "XYZ",
        "orderAmount": "122.00",
        "customeName": "xxx",
        "products":[
            {
                "productid":"1212",
                "prodName" :"xxx",
                "prodcost" : "33.33"
            },
            {
                "productid":"1212",
                "prodName" :"xxx",
                "prodcost" : "33.33"
            },
            {
                "productid":"1212",
                "prodName" :"xxx",
                "prodcost" : "33.33"
            }
    
        ]
    },
    {
        "orderid" : "XYZ",
        "orderAmount": "122.00",
        "customeName": "xxx",
        "products":[
            {
                "productid":"1212",
                "prodName" :"xxx",
                "prodcost" : "33.33"
            },
            {
                "productid":"1212",
                "prodName" :"xxx",
                "prodcost" : "33.33"
            },
            {
                "productid":"1212",
                "prodName" :"xxx",
                "prodcost" : "33.33"
            }
    
        ]
    }
    ]
    

    }

    From the above example Array Orders goes to writable source and all products goes to another writable source.

    But here i am not able to identify the products belongs to which order in writable source :(

    Any help would be appreciable.

    Regards
    Udaya

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited September 2017

    If your first writable, you should be extracting the entire JSON array to a column.
    Next, you should have the outer suite/loop iterate over this writable. You should have a JSON data bank in this suite which takes the column containing the JSON array as input, and writes the values in the array into the second writable. Next, the inner suite/loop would iterate over the second writable.
    psuedo code:

    write orders to writable a
    for each order in writable a
       write products from order to writable b
       for each product in writable b
          do something
    
  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    How to assert this array child array responses

    I wanted to clarify that I'm not sure how you intend to do your validation, exactly. I just want to make sure that iterating through every product in every order, which it seems you were originally asking, is really what you need. For validation, the usual thing to do would be to diff the entire response (with Diff tool).