Reputation: 3419
I want to do the following in soapUI using Groovy:
To achieve this I have the following steps definied:
I did the same steps for other tests already by putting the values from database into the property object in step 2 and reading them from there in step 5. But up to now the values were always normal String
or int
. In the response I get in my current test case I get a list back. So I create an array and filled it with bean objects my wanted data in step 2. In step 5 I parse my XML-String and convert the data into an Object-Array too. So I can compare all attributes of them.
I wrote the whole test case in a singular script and tested it on groovy console first. When I started to transform it to soapUI and working with the property to "transport" the data from step 2 to step 5 my problem occurs as it looks like I can't put an Arraylist to the properties (see error message below).
Now I'm confused that this is not possible as I can easily put SQL-Instances in the properties:
def contextSqlInstanz = Sql.newInstance(urlH2, userH2, passwordH2, driverH2)
context.setProperty( "contextSqlInstanz", contextSqlInstanz )
sql = context.getProperty("contextSqlInstanz");
So how I can transport my Array, filled the Objects, from step 2 to step 5 to compare it with my webservice response. I DON'T want to convert both to strings and compare if the strings are equal but I want to compare each attributes of my bean-class by hand.
Bean Class:
class myBean {
String value1;
String value2;
...
}
Reading my local database, generating the beans and put them into a list
function getdata() {
def liste = []
// sql-statements
sql.eachRow(...) {
def myBean = new myBean();
myBean.value1 = it.value1.toString();
myBean.value2 = it.value2.toString();
...
liste.add(Schluesselwert)
}
return liste
}
Trying to put the list into properties
sollListeH2 = getdata()
def props = testRunner.testCase.getTestStepByName("P_testcase")
props.setPropertyValue( "sollListe", sollListeH2)
results in:
groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.teststeps.WsdlPropertiesTestStep.setPropertyValue() is applicable for argument types: (java.lang.String, java.util.ArrayList) values: [sollListe, [value1@15d4334, value2@1e739c8, ...]] Possible solutions: setPropertyValue(java.lang.String, java.lang.String), getPropertyValue(java.lang.String) error at line: 91
Upvotes: 0
Views: 7542
Reputation: 3419
As I didn't find another way I did it the ugly way by putting each value as an own property into the propteries
Setting the props in step 2:
def convertVectorToProps(vector) {
def size = vector.size();
def props = testRunner.testCase.getTestStepByName("P_testcase")
props.setPropertyValue("sollSize", size.toString())
for(int i=0; i < size; i++) {
props.setPropertyValue("myBean.value1" + i, vector.value1[i]);
props.setPropertyValue("myBean.value2" + i, vector.value2[i]);
...
}
}
Reading the props in step 5 and build new vector:
def convertPropsToVector() {
def props = testRunner.testCase.getTestStepByName("P_testcase")
def sollSize = props.getPropertyValue("sollSize").toInteger()
SollListe = [];
for(int i=0; i < sollSize; i++) {
def myBean = new myBean();
myBean.value1 = props.getPropertyValue("myBean.value1" + i);
myBean.value2 = props.getPropertyValue("myBean.value2" + i);
SollListe << myBean
}
return SollListe
}
Upvotes: 2