Groovy If statement is not behaving as expected
I have written some code in which I am parsing the response xml of JDBC request and saving the rows in an ArrayList. "ar"
Later I am matching the return values with a watch list array called "requiredfield". I will be have some more JDBC steps which I am calling using this script. The logic is if the matching value exist in ar array then I have to update in the table otherwise I have to insert a row. In the below code I manage to record the values in my array "ar" but when I match these values with my watch list array "requiredField" , the if statement always return false and control goes to else part. here is the code
Integer rr=0 ArrayList ar = new ArrayList() jdbcXml = context.expand('${JDBCRequestForCheckingCommandPropertyID#ResponseAsXml}') def root = new XmlSlurper().parseText(jdbcXml) root.ResultSet.Row.each{row-> ar.add(row["COMMANDPROPERTYID"]) rr++ } ArrayList requiredField = new ArrayList() requiredField.add(61) requiredField.add(276) requiredField.add(605) for (j=0; j<requiredField.size();j++) { if (ar.contains(requiredField[j])) { testRunner.gotoStepByName("Update"+requiredField[j]) } else { testRunner.gotoStepByName("Add"+requiredField[j]) } }
However similar logic works fine if I created an array list and pass insert the values in "ar" array manually, here is my logic before reading the values from XML, In this if statement behaves as expected.
ArrayList ar = new ArrayList() ar.add(605) ar.add(61) ar.add(276) ArrayList requiredField = new ArrayList() requiredField.add(61) requiredField.add(276) requiredField.add(605) for (j=0; j<requiredField.size();j++) { if (ar.contains(requiredField[j])) { testRunner.gotoStepByName("Update"+requiredField[j]) } else { testRunner.gotoStepByName("Add"+requiredField[j]) } }
Your help will highly appriciated.
regards,
Hurray....
I manage to fixed this by converting the array value into integer Herer is the sample code
ArrayList ar = new ArrayList() jdbcXml = context.expand('${JDBCRequestForCheckingCommandPropertyID#ResponseAsXml}') def root = new XmlSlurper().parseText(jdbcXml) root.ResultSet.Row.each{row-> ar.add(row["COMMANDPROPERTYID"].toInteger()) }