Forum Discussion

GTaylor's avatar
GTaylor
Occasional Contributor
12 years ago

Insert multiple rows into DB from SOAP response/propertyTran

hi.
I am new to SoapUIPRO 4.5.1 and I've run into an obstacle. I have a response message that I'm mapping certain elements to a propertyTransfer so I might commit those to a database. My problem is that in my response message I have a nested object model like so.


<masterQuote>
<msterQuoteId>12345</masterQuoteId>
<quotes>
<qoute>quote 1</quote>
<quote>quote 2</quote>
<quote>quote 3</quote>
</quotes>
</msterQuote>

In my database I will have three rows that represent this data. All three rows will have the same master quote info and then the individual quote info. So the short of it is, how do I tell soapUIPro to finish inserting one row and then move on to the next row? Three inserts one per each nested model. This is a reporting database table so I'm not looking to super normalize it with a masterQuote/child quote table structure.

I can't seem to find a clear answer here in the forum, but I'm sure there has to be a pretty simple way.

Thanks for your time.

8 Replies

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

    I think what you need is SoapUI's DataSource concept.

    http://www.soapui.org/Data-Driven-Testi ... tests.html
    http://www.soapui.org/Data-Driven-Testi ... urces.html
    http://www.soapui.org/Data-Driven-Testi ... orial.html

    The DataSource can be used to iterate over some data for example the values of some element(s) of a response.
    You can even nest datasources to achieve a high level of control.

    If, in your case, the root node is "masterQuote" then you have a really simple case for datasources. If you can have several masterQuotes in a list then you may need to have a nested DataSource for "quote" within the outer "masterQuote".

    Does that make any sense? Maybe I misunderstood your question.
    It is a bit hard to explain but the tutorials and the documentation should hopefully explain it enough for you to get started.

    Regards,
    Henrik
    SmartBear Software
  • GTaylor's avatar
    GTaylor
    Occasional Contributor
    It does make sense. I think I'm going to have to have a nested DataSource. I'm going to consume the tutorials and let you know if I have any issues.
    Thank you for your response.
  • GTaylor's avatar
    GTaylor
    Occasional Contributor
    So, I've run into some problems. I think I might need a nested DataSource, but at this point I can't even find an example of what that is. Can you point me to an example of a nested DataSource?

    Also, I want to grab a list of xml nodes and inspect each node to see if it's something that I care about. I'm having a hard time doing something like this.


    List<Node> nodes = getListOfNodesFromResponse(//xpath);
    for (Node node : nodes){
    //inspect node to see if I need to persist.
    }

    Granted that's pseudo java ala DOM4J, but I don't know how to ask the question correctly. Is the above pseudo code something I need to achieve in a groovy script or something that I can leave up to other test steps. I think that's a huge source of confusion for me. When do you resort to scripting and when don't you? I am new to groovy, so scripting is not my first inclination.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    A nested DataSource is basically a DataSource - DataSource Loop procedure within another DataSource - DataSource Loop procedure. You can use one DataSource for iterating over the masterQuotes, and then another for accessing the quotes within. The workflow should look something like this:


    DataSource 1 (get masterQuote)
    DataSource 2 (get quote)
    //Do stuff with quote
    DataSource Loop 2 (go to next quote)
    DataSource Loop 2 (go to next masterQuote)


    Does this make sense? It's possible that I've misunderstood your setup.

    Regarding XML parsing, check this blog post out. It contains some useful examples
    http://www.robert-nemet.com/2011/11/gro ... oapui.html

    Let me know if you have any further questions.

    Regards,

    Arian
    SmartBear Sweden
  • GTaylor's avatar
    GTaylor
    Occasional Contributor
    I do have a question. Is your described workflow groovy script DataSources or out-of-the-box DataSources?

    Also, at first glance at the suggested xml parsing looks to be just want a I need so thank you.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    I had out-of-the-box DataSources in mind, but it works in the same way for both. Here's what I meant in a bit more detail:


    1) XML DataSource 1 (get masterQuote)
    2) XML DataSource 2 (get quote)
    3) Insert one row into database, with quote and masterQuote
    4) DataSource Loop 2 (step 2 as source, targeting step 3)
    5) DataSource Loop 2 (targeting step 2)


    Ask away if you still have any more questions, I'm happy to assist.

    Regards,

    Arian
    SmartBear Sweden
  • GTaylor's avatar
    GTaylor
    Occasional Contributor
    So the xml parsing page that is mentioned above really helped me in this situation. I've managed to complete the task at hand, and I did most of it in groovy. I parse the soap response and insert data into the db by opening up a jdbc connection from the script. I think I've got a handle on things, at least for now.

    Thank you for your help.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Great to hear that you worked things out. Let us know if you ever need any more assistance.

    Regards,

    Arian
    SmartBear Sweden