Need to add values to validation sum is 100

LegacyForumLegacyForum Posts: 1,669 ✭✭
edited December 2016 in SOAtest
Hi,

I would like to write a method to summarize these values. Note that XML Data Bank list the percentage value as Percentage, percentage 1, percentage2, etc. There was an example in the forums, but after several attempts, I was not able to get the python script to work. I would like to be able to run the script and verify that the asset allocations equal 100.

<ns2:assetAllocation>
<ns2:allocation>
<ns2:assetClass>
<ns2:assetClassType>Stock</ns2:assetClassType>
</ns2:assetClass>
<ns2:percentage>96.93</ns2:percentage>
<ns2:allocation>
<ns2:assetClass>
<ns2:assetClassType>US Equity</ns2:assetClassType>
</ns2:assetClass>
<ns2:percentage>93.88</ns2:percentage>
</ns2:allocation>
<ns2:allocation>
<ns2:assetClass>
<ns2:assetClassType>Non-US Equity</ns2:assetClassType>
</ns2:assetClass>
<ns2:percentage>6.12</ns2:percentage>
</ns2:allocation>
</ns2:allocation>
<ns2:allocation>
<ns2:assetClass>
<ns2:assetClassType>Bond</ns2:assetClassType>
</ns2:assetClass>
</ns2:allocation>
<ns2:allocation>
<ns2:assetClass>
<ns2:assetClassType>Cash</ns2:assetClassType>
</ns2:assetClass>
<ns2:percentage>2.5</ns2:percentage>
</ns2:allocation>
<ns2:allocation>
<ns2:assetClass>
<ns2:assetClassType>Other</ns2:assetClassType>
</ns2:assetClass>
<ns2:percentage>0.57</ns2:percentage>
</ns2:allocation>
</ns2:assetAllocation>
Tagged:

Comments

  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    This can be accomplished by using the Expression Assertion with the XML Assertor tool chained to the Response portion of your test case.

    Instructions:
    1. Add XML Assertor to the Response output of your messaging test case (e.g. SOAP Client, Messaging Client)
    2. Run the test case once to populate the XML Assertor with a response
    3. Open up XML Assertor and switch to Configuration tab and press Add button
    4. Add Expression Assertion located within the Value Assertions section
    5. Within the Expression Assertion GUI/editor, press New button
    6. Type in a name for the Expression Name (optional, or SOAtest will give it a default name if left blank) and make sure Add radio button is selected
    7. Under Choose XPath Operands, one by one, select the desired <percentage> element and click Add for each of them
    8. Click on section Summary & Modification, you should see "../percentage" listed three times in the top table, and under Expression View, you should see the following expression: ../percentage + ../percentage + ../percentage. This is how we sum up the values.
    9. Click Finish
    10. Back to the main Expression Assertion GUI/editor, make sure Numeric Value radio button is selected, and input 100 as the "Expected Value".

    The assertion will now add the percentages and you can compare it to be == 100 (there is a number of other operators that can be used for comparison such as: <, !=, >, etc.)

    I'm attaching a sample .tst file with the above Expression Assertion configured using your sample payload. Please feel free use it as a reference when building your own. I created the sample .tst file with SOAtest 5.5.3 w/ SP 1.0

    Hi,

    I would like to write a method to summarize these values. Note that XML Data Bank list the percentage value as Percentage, percentage 1, percentage2, etc. There was an example in the forums, but after several attempts, I was not able to get the python script to work. I would like to be able to run the script and verify that the asset allocations equal 100.

    <ns2:assetAllocation>
    <ns2:allocation>
    <ns2:assetClass>
    <ns2:assetClassType>Stock</ns2:assetClassType>
    </ns2:assetClass>
    <ns2:percentage>96.93</ns2:percentage>
    <ns2:allocation>
    <ns2:assetClass>
    <ns2:assetClassType>US Equity</ns2:assetClassType>
    </ns2:assetClass>
    <ns2:percentage>93.88</ns2:percentage>
    </ns2:allocation>
    <ns2:allocation>
    <ns2:assetClass>
    <ns2:assetClassType>Non-US Equity</ns2:assetClassType>
    </ns2:assetClass>
    <ns2:percentage>6.12</ns2:percentage>
    </ns2:allocation>
    </ns2:allocation>
    <ns2:allocation>
    <ns2:assetClass>
    <ns2:assetClassType>Bond</ns2:assetClassType>
    </ns2:assetClass>
    </ns2:allocation>
    <ns2:allocation>
    <ns2:assetClass>
    <ns2:assetClassType>Cash</ns2:assetClassType>
    </ns2:assetClass>
    <ns2:percentage>2.5</ns2:percentage>
    </ns2:allocation>
    <ns2:allocation>
    <ns2:assetClass>
    <ns2:assetClassType>Other</ns2:assetClassType>
    </ns2:assetClass>
    <ns2:percentage>0.57</ns2:percentage>
    </ns2:allocation>
    </ns2:assetAllocation>

  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    THANK YOU! This works great! I even created another one to validate another sum in the XPATH Operands.

    Thanks again!
Sign In or Register to comment.