Forum Discussion

mamar's avatar
mamar
Contributor
12 years ago

[Resolved] How to validate series of values in the response?

Hi,
I have a below response from my test. Here, i want to validate whether my response is having all my <TrnType>'s as 'Debit' and all the <PostedDt>'s are in between '2013-09-01' and '2013-09-30'. How should i do in Groovy. Can any one help me with the Code.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<com.fnf.depaccttrninq.v2_1:DepAcctTrnRec>
<BankAcctTrnRec xmlns="http://www.ifxforum.org/IFX_150">
<TrnType>Debit</TrnType>
<PostedDt>2013-09-18</PostedDt>
<EffDt>2013-09-18T12:00:00.000000-00:00</EffDt>
<CurAmt>
<Amt>15.00</Amt>
<CurCode>USD</CurCode>
</CurAmt>
<Name>SERVICE CHARGE</Name>
</BankAcctTrnRec>
<ChkNum xmlns="http://www.ifxforum.org/IFX_150">0000000000</ChkNum>
<DepAcctIdTo xmlns="http://www.ifxforum.org/IFX_150">
<AcctId/>
</DepAcctIdTo>
<NetworkTrnInfo xmlns="http://www.ifxforum.org/IFX_150">
<NetworkOwner/>
</NetworkTrnInfo>
<AcctBal xmlns="http://www.ifxforum.org/IFX_150">
<BalType>Transaction</BalType>
<CurAmt>
<Amt>401.51</Amt>
<CurCode>USD</CurCode>
</CurAmt>
</AcctBal>
<com.fnf:TrnCode xmlns:com.fnf="http://www.fnf.com/xes">GT01</com.fnf:TrnCode>
<com.fnf:OnlineDesc xmlns:com.fnf="http://www.fnf.com/xes"/>
<com.fnf:TrnDesc xmlns:com.fnf="http://www.fnf.com/xes">Maintenance charge</com.fnf:TrnDesc>
<com.fnf:TrnDesc2 xmlns:com.fnf="http://www.fnf.com/xes"/>
<com.fnf:TrnDesc3 xmlns:com.fnf="http://www.fnf.com/xes"/>
</com.fnf.depaccttrninq.v2_1:DepAcctTrnRec>
<com.fnf.depaccttrninq.v2_1:DepAcctTrnRec>
<BankAcctTrnRec xmlns="http://www.ifxforum.org/IFX_150">
<TrnType>Debit</TrnType>
<PostedDt>2013-09-19</PostedDt>
<EffDt>2013-09-18T12:00:00.000000-00:00</EffDt>
<CurAmt>
<Amt>0.02</Amt>
<CurCode>USD</CurCode>
</CurAmt>
<Name>IOD INTEREST PAID</Name>
</BankAcctTrnRec>
<ChkNum xmlns="http://www.ifxforum.org/IFX_150">0000000000</ChkNum>
<DepAcctIdTo xmlns="http://www.ifxforum.org/IFX_150">
<AcctId/>
</DepAcctIdTo>
<NetworkTrnInfo xmlns="http://www.ifxforum.org/IFX_150">
<NetworkOwner/>
</NetworkTrnInfo>
<AcctBal xmlns="http://www.ifxforum.org/IFX_150">
<BalType>Transaction</BalType>
<CurAmt>
<Amt>416.51</Amt>
<CurCode>USD</CurCode>
</CurAmt>
</AcctBal>
<com.fnf:TrnCode xmlns:com.fnf="http://www.fnf.com/xes">GT20</com.fnf:TrnCode>
<com.fnf:OnlineDesc xmlns:com.fnf="http://www.fnf.com/xes"/>
<com.fnf:TrnDesc xmlns:com.fnf="http://www.fnf.com/xes">IOD INTEREST PAID</com.fnf:TrnDesc>
<com.fnf:TrnDesc2 xmlns:com.fnf="http://www.fnf.com/xes"/>
<com.fnf:TrnDesc3 xmlns:com.fnf="http://www.fnf.com/xes"/>
</com.fnf.depaccttrninq.v2_1:DepAcctTrnRec>
<com.fnf.depaccttrninq.v2_1:DepAcctTrnRec>
<BankAcctTrnRec xmlns="http://www.ifxforum.org/IFX_150">
<TrnType>Debit</TrnType>
<PostedDt>2013-09-20</PostedDt>
<EffDt>2013-08-16T12:00:00.000000-00:00</EffDt>
<CurAmt>
<Amt>15.00</Amt>
<CurCode>USD</CurCode>
</CurAmt>
<Name>SERVICE CHARGE</Name>
<SPRefId>0</SPRefId>
</BankAcctTrnRec>
<ChkNum xmlns="http://www.ifxforum.org/IFX_150">0000000000</ChkNum>
<DepAcctIdTo xmlns="http://www.ifxforum.org/IFX_150">
<AcctId/>
</DepAcctIdTo>
<NetworkTrnInfo xmlns="http://www.ifxforum.org/IFX_150">
<NetworkOwner/>
</NetworkTrnInfo>
<AcctBal xmlns="http://www.ifxforum.org/IFX_150">
<BalType>Transaction</BalType>
<CurAmt>
<Amt>416.49</Amt>
<CurCode>USD</CurCode>
</CurAmt>
</AcctBal>
<com.fnf:TrnCode xmlns:com.fnf="http://www.fnf.com/xes">GT01</com.fnf:TrnCode>
<com.fnf:OnlineDesc xmlns:com.fnf="http://www.fnf.com/xes"/>
<com.fnf:TrnDesc xmlns:com.fnf="http://www.fnf.com/xes">Maintenance charge</com.fnf:TrnDesc>
<com.fnf:TrnDesc2 xmlns:com.fnf="http://www.fnf.com/xes"/>
<com.fnf:TrnDesc3 xmlns:com.fnf="http://www.fnf.com/xes"/>
</com.fnf.depaccttrninq.v2_1:DepAcctTrnRec>
</soapenv:Body>
</soapenv:Envelope>

8 Replies

  • Hello,
    Can use following groovy:

    def TrnType = context.expand( '${Properties#TrnType}' )
    def PostedDt = context.expand( '${Properties#PostedDt}' )
    log.info TrnType
    log.info PostedDt
    assert TrnType == "Debit"
    assert PostedDt >= "2013-09-01" & PostedDt <= "2013-09-30"
    here, TrnType and PostedDt can be directly used from response[ or store them at properties test step for later use if any]

    Hope it helps.
  • Thanks for the code. But i tried and dint succeed. i get null value for the fields and so assert fails with exception. Below are the modified code.

    def TrnType = context.expand('${doSplInstInq#Response#TrnType}')
    log.info TrnType
    assert TrnType == "Debit"
  • Hello,
    I think you are not taking TrnType properly,
    just right click and fetch the value from response of Test step i.e: doSplInstInq
    and assert against whatever you want to.
    Hope it helps.
  • I am using SoapUI free version. so i cant get in the way what you said. is there any other way i can get it?
  • Try folowing:

    groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    holder = groovyUtils.getXmlHolder( "Request_Name#Response" )
    holder.namespaces["tns"] = "http://www.ifxforum.org/IFX_150"

    holder.getNodeValues("//tns:BankAcctTrnRec[1]/tns:TrnType")
    TrnType= TrnType.toString()
    assert TrnType == "Debit"

    I am refering the name spaces as mentioned in the response
  • Thanks much. i am able to get the list of all trantypes from the response with minor changes with your code..

    import com.eviware.soapui.support.*
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( "doDepAcctTrnInq#Response" )
    holder.namespaces["ns"] = "http://www.ifxforum.org/IFX_150"
    TrnType = holder.getNodeValues("//ns:BankAcctTrnRec//ns:TrnType")
    log.info "TrnType : " + TrnType.each{it}

    and i am also trying to validate my response is having all the TrnType's either in 'Debit' or 'Credit' or 'Check'. So i tried with the below assertions, but getting failure message and my response is having the TrnType's in these three types. Could you please help me.

    assert (TrnType.each{it} in ["Debit", "Credit", "Check"]) - got failure message
    assert (TrnType.each{it}.contains("Debit", "Credit", "Check")) - got failure message

    In SQL, we use to verify in where condition like this, "<variable> in ("Debit", "Credit", "Check")". Is there any operators in Groovy?
  • Hi,
    Rather than comparing like -> assert (TrnType.each{it} in ["Debit", "Credit", "Check"])
    you should use -> assert (TrnType.each{it} == ["Debit", "Credit", "Check"]) if the order of fields returned are 'Debit', 'Credit' and 'Check' and if TrnType is holding 3 values.
    If it contains one value
    ie while fetching -> TrnType = holder.getNodeValues("//ns:BankAcctTrnRec[1]//ns:TrnType") say from 1st node
    and it could be any of 'Debit', 'Credit' and 'Check' that can be checked by following:

    log.info "TrnType : " + TrnType.each{it}
    TrnType = TrnType.toString()
    len = TrnType.length()
    TrnType = TrnType.substring(1,len-1) // this is needed to trim off '[' and ']' from returned string
    log.info "TrnType : to string " + TrnType.each{it}
    assert (TrnType in ["Debit", "Credit", "Check"])
    Hope it helps...
  • Thanks for your time.
    Though i have all correct values, still i get the below message with the given code (from different response and not from first post). But somehow i researched and modified the code and finally got the answer what i need. Enclosed the code for your future reference, if you need.

    -> Assertion failed:

    assert (TrnType in ["Debit", "Credit", "Check"])
    | |
    | false
    Debit, Credit, Debit, Credit, Debit, Credit, Debit, Credit, Debit, Credit, Debit, Credit, Debit, Credit, Debit, Credit, Debit, Credit, Debit, Credit, Debit, Credit, Debit, Credit, Debit, Debit, Credit, Debit, Credit, Debit, Credit, Credit, Credit, Check, Debit, Credit

    -> error at line: 17

    The corrected code.

    import com.eviware.soapui.support.*
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( "doDepAcctTrnInq#Response" )
    holder.namespaces["ns"] = "http://www.ifxforum.org/IFX_150"
    TrnType = holder.getNodeValues("//ns:BankAcctTrnRec//ns:TrnType")
    log.info "TrnType : " + TrnType.each{it}
    TrnType.each{assert (it) in ["Debit", "Credit", "Check"]} // Here checks that each TrnType is available in either of three values one by one as list.

    Thanks.