I currently have the following assertion script to check the value of three fields.
import org.junit.Assert
def response = messageExchange.getResponseContent()
def xml = new XmlSlurper().parseText(response)
def nodelist = xml.'**'.findAll{ it.name() == 'premium' }
def assertions = [6.19, 6.47, 6.90]
def i=0
for (node in nodelist) assert node.toString().matches(assertions[i++].toString())
I am trying to get it so that the assertion will pass in the actual value is within 0.05 either side of the expected value.
The following script works when there is one value, but I am struggling to implement it with the assertion above.
import org.junit.Assert
// get the xml response
def response = messageExchange.getResponseContent()
// parse it
def xml = new XmlSlurper().parseText(response)
// find your node by name
def node = xml.'**'.find { it.name() == 'premium' }
// assert
if(node.toDouble() != 0.0)
Assert.assertEquals(0.00, node.toDouble(), 0.05)
Edit
Sample Response:
<b:quote-data>
<b:quote-data>
<b:premium>6.13</b:premium>
</b:quote-data>
<b:quote-data>
<b:premium>6.45</b:premium>
</b:quote-data>
<b:quote-data>
<b:premium>6.91</b:premium>
</b:quote-data>
</b:quote-data>
Here are couple of things for failure in your case.
BigDecimaltype.Here is the sample to achieve the above:
Note that using sample fixed xml, you can use to for dynamic response like you are already doing.
If you also need the logic for validation with tolerance, then use below along with above script.
You can quickly try it online demo
EDIT: Another suggestion
When you are using script assertion, you can change below:
From:
To: