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.
Script instead of Diff to test return code

LegacyForum
Posts: 1,664 ✭✭
Comments
-
I think that the best way to do this would be to use a script instead of a Diff.
To do this:
1. Attach a Response->XML Data Bank to the SOAP Client.
2. Add the XPath for responseCode.
3. Add a new Method Tool after the SOAP Client, and place a checkmark in the box that says "Return value indicates success."
4. Enter the following python code in the Method tool.CODEfrom java.lang import *
from com.parasoft.api import *
#Global variables
dataSourceName = "Generated Data Source"
dataColumn = "your data source column name"
testNumber = Integer(1234)
#Returns 1 if number in data source is less than zero, and returns 0 otherwise
def lessThanZero(input, context):
number = getNumber(context)
if number < Integer(0):
result = 1
else:
result = 0
return result
#Returns 1 if number is not equal to testNumber and returns 0 otherwise
def notTestNumber(input, context):
number = getNumber(context)
if number != testNumber:
result = 1
else:
result = 0
return result
#This function assumes the number in the data source and column can be cast as an Integer
#It returns the value of the stored variable
def getNumber(context):
number = context.getValue(dataSourceName, dataColumn)
number = Integer(number)
return number
#Allows use of data sources (not necessary with Generated Data Sources)
def addDataSources(context):
return dataSourceName
5. datacolumn needs to be set to the value found in the XML Data Bank that stores your variable.
a. Go to the XML Data Bank, and select the XPath on the right.
b. Click Modify, and select DataSource column name on the left of the dialog window.
c. You want the text in the Custom Column Name field.
6. Finally, select either lessThanZero() or notTestNumber() from the Method dropdown underneath the textbox.
7. Run your project to confirm the results.
Here's what is happening:
First, the Data Bank stores the value that you want to test. Then, the Method test retrieves that value using getNumber() and performs the comparison that you want. Notice that you can easily change the comparison number in notTestNumber() by changing the value of testNumber at the beginning.
In the case that the comparison matches the condition, it returns a value of 1, otherwise it returns 0. Because the Return value indicates success box is checked, the Method Test will succeed on 1 and fail on 0.
If you have any further questions about how or why this works, please let me know.
--Jason0 -
This discussion is talking about an old tool called the Method Tool. Use the Extension Tool now. The options has been changed to "Exit code indicates success".
0