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.

Capture and Loop through the response

LegacyForum
LegacyForum Posts: 1,664 ✭✭
edited December 2016 in SOAtest
Hi,

I have a query.

A method returns 10 records.
If there are more than 10 records then this method returns first 10 records.[Sorted by date/time creation] other wise it will return based on the number of records exists.

There are 5 attributes in each record. Name is one of the attribute.
The Name attributes is different for each record while the remaining attributes are constants.

One of the tests creates a record, so one of the Name attribute is known. [Response: xml Databank

How to verify whether the known Name exists in the returned records.

Note: I don’t want to use the writable database.

Thanks in advance.

Regards,
Krishna
Tagged:

Comments

  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Krishna,

    First, you will need to add an XML Transformer to the test that is receiving the records as a response.
    In the configuration pane for the XML Transformer, right-click on the name attribute and select "Add XPath for all occurences....".
    The XML Transformer will output a string containing all of the name attributes of the records that were returned.
    Next add a Method tool to the XML transformer. Check "Return value indicates sucess". Paste the following code into the text field:
    CODE
    from com.parasoft.api import *
    from java.lang import *


    def find(input, context):
    whatToFind = context.getValue("Generated Data Source", "COLUMN_NAME")
    successIndicator = 0
    input = String(str(input))
    index = input.indexOf(whatToFind)
    if (index > -1):
    successIndicator = 1
    return successIndicator


    def addGeneratedDataSources(context):
    return "Generated Data Source"


    Replace COLUMN_NAME with the name of the column from the XML Data Bank.
    Then select the find() from the method drop down.
    This method now searches the string from the XML Transformer and the test will only pass if the the method finds the name in the string.

    Joe
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Hi Joe,

    Thanks for the info.It was really helpful.

    Regards,
    Krishna
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Hi Joe,

    Thanks very much for the info.

    Correct me if I’m wrong, the solution mentioned works fine only if name attribute is added to xpath i.e. all the occurrences of the name attribute.

    Suppose I don’t know exactly how many records will be returned?
    For example: First time it may return 3 records and second time it may return 5 records but what I know exactly is it will return max of 10 records.

    Do let me know your comments in this regard.

    Thanks,
    Krishna
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Krishna,

    Since you will use the "Add XPath for all occurrences....", it should get the name field in all the records that come in, regardless of how many are returned.

    Try it out and let me know if the behavior you are getting is not what you were expecting

    ~Joe

  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Hi Joe,

    When you say "Add XPath for all occurrences...."

    Does this means manually adding each of the occurrences.
    In the XML transformer, I did not find all the occurrence option.

    Ignore All "Rows[*]" option is there in the regression control.

    I know this may be trivial question but wanted to clarify the same.

    Thanks in advance.

    Regards,
    Krishna
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Krishna,

    You will first need to run the test with an input that will produce more than one record. Then in the XML Transformer, right click on the name attribute of the first record. Then, the second item should be "Add XPath for all occurrences within RECORD[*]" where RECORD is the whatever the record is named in the XML.

    Please let me know if you have any more problems with this.

    ~Joe
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Hi Joe,

    If a method has multiple returns then the option "Add XPath for all occurrences within RECORD [*]" will be displayed.

    But in my case there is only one return with multiple records.I have attached the screen shot.

    Can you please let me know the work around in this regard?

    Thanks in advance.

    Regards,
    Krishna
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Krishna,

    In that case shown in the screen shot, you should be able right click on Cells, then select "Add XPath for all occurrences with Rows[*]" .

    This will return all of the "Cells" elements, each of which will contain the Name element.

    Please let me know if are able to add all occurrences and if that achieves what you wish to accomplish or not.

    Thanks,
    Joe