Forum Discussion

US_20's avatar
US_20
Occasional Contributor
6 years ago

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)
    }
    
    
  • richie's avatar
    richie
    Community Hero
    Hi,

    I just want to make sure i understand.

    You have a REST request that will return a response
    You have a JDBC request that will return a response

    You want to compare an attribute value from each response but ONLY if the one response returns >0 rows?

    Cheers,

    richie
    • US_20's avatar
      US_20
      Occasional Contributor

      Hi Richie ,

       

      Thanks for looking into my query. So here is my request:

       

      1. REST request which will return a field A (+ve or -ve integer) as response

      2. JDBC request that will return a response which has Order Total field (field B)-- can be 0 or +ve integer

       

      Now I need to make sure if field B value and field A value are equal only if field B returns a +ve integer(>0)

       

      Can you pls help me how to assert this?

       

       

      • groovyguy's avatar
        groovyguy
        Community Hero

        My first thought is that this may have to be done via a groovy script. Can you provide some responses, sample or mocked up, so that we can see exactly what we're dealing with?

  • Hi US_20 ,

     

    First get the two different values in two different variables, then assert both of them for example:

     

    def responseA = "Get the response"

    def responseB = "Get the response"

     

    assert reponseA == responseB : "response of A and B not matched"