Forum Discussion

Jack21Z's avatar
Jack21Z
Occasional Contributor
11 years ago

groovyUtils.getXmlHolder treat data as array of characters

Hi

Why the data is treat as array of characters rather than array of strings with 1 element, when 1 result returned?

Sample:

JDBC:

<Results>
<ResultSet fetchSize="10">
<Row rowNumber="1">
<ADDRESS>North Carolina</ADDRESS>
<HOUSE_NUMBER>99000034</HOUSE_NUMBER>
</Row>
</ResultSet>
</Results>



Groovy:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def dbResult = groovyUtils.getXmlHolder('JDBC#ResponseAsXml');

def housenumber = []

for(item in dbResult['//HOUSE_NUMBER']){
housenumber += item
}

log.info housenumber


Actual:

INFO:[9, 9, 0, 0, 0, 0, 3, 4]


Expected:

INFO:[99000034]


Regards,
Jack

6 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    Looks the reading does not seem to be good.
    May be try with
    housenumber.add(item)


    And you may also test the class of the value, your case may test with string class for the item
    for eg:
    assert list instanceof java.util.List
  • Jack21Z's avatar
    Jack21Z
    Occasional Contributor
    nmrao wrote:
    Looks the reading does not seem to be good.
    May be try with
    housenumber.add(item)


    And you may also test the class of the value, your case may test with string class for the item
    for eg:
    assert list instanceof java.util.List


    I got same result when i try your code


    Regards,
    jack
  • nmrao's avatar
    nmrao
    Champion Level 3
    1. Since housenumber is defined as list in your script, assuming that you might get a list of values
    2. what is the result for the assert item instanceof java.lang.String?
  • Jack21Z's avatar
    Jack21Z
    Occasional Contributor
    nmrao wrote:
    1. Since housenumber is defined as list in your script, assuming that you might get a list of values
    2. what is the result for the assert item instanceof java.lang.String?


    1. now i understand...so if i define as list then he treat my data as list:
    i defined the housenumber as list because i assumed that my JDBC request has 0 or more results.

    2. when i assert item if String it returned OK...but when i assert item if Character i got an assertion failed

    So maybe i do checking first if my JDBC result is 1 or more?
  • nmrao's avatar
    nmrao
    Champion Level 3
    Ok.
    But, not sure if you could proceed or still having issue?
  • Jack21Z's avatar
    Jack21Z
    Occasional Contributor
    nmrao wrote:
    Ok.
    But, not sure if you could proceed or still having issue?


    Hi,

    what i did was determine first the result of jdbc if how many rows returned, if 1 i just define my variable as String not an Array

    Thanks,
    Jack