Assertions with conditions
Hi,
I am new to SOAP UI, I have a JDBC request which is a select query and it returns an XML response.
JDBC request (say Request B)==> In response, there is a field, Order total which returns 0 or +ve interger based on response returned in the previous response(say REST request A) (which returns a +ve or -ve integer)
So I want to check if the Order total(returned in request B) matches the response returned in request A only when reponse of A returns a +ve value. How can i acheive this assertion when I have a condition to be given?
Thanks in advance,
Udaya
I mocked up a rest request with the response you provided, but I ran into a problem mocking out a JDBC request since I don't have ready access to a database. Still, I was able to put together a groovy script that will compare a value returned by the rest request in the morphOnlyNetAmount in the response against a REFUNDABLE_AMOUNT if the latter is a postive integer. You'll need to adjust the script to your own uses, but it should be a good start.
package json import com.eviware.soapui.support.XmlHolder import groovy.json.* // Cna use the right-click Get-Data menu here to get the rest request response. def restResponse = context.expand( '${REST Request#Response}' ) log.info(restResponse); def r = new JsonSlurper().parseText(restResponse) // Gets the morphOnlyNetAmount from response and converts to float. def restValue = r.morphOnlyNetAmount.toFloat(); // You need to use the right-click Get-Data menu here to ensure it works as expected. Without a fully formed JDBC response, I cannot fully mock this out. def jdbcResponse = context.expand( '${JDBC Requests#Response#//REFUNDABLE_AMOUNT[1]}' ).toFloat(); if (jdbcResponse > 0) { assert (jdbcResponse == restValue) }