Reputation: 501
I have the following XML which is generated from a JDBC response step:
<ResultSet fetchSize="64">
<Row rowNumber="1">
<TW341_LIMITDEFN.LIMIT_CODE>022</TW341_LIMITDEFN.LIMIT_CODE>
<TW341_LIMITDEFN.LIMIT_TYPE>N</TW341_LIMITDEFN.LIMIT_TYPE>
<TW341_LIMITDEFN.PERIOD_VAL>1</TW341_LIMITDEFN.PERIOD_VAL>
<TW341_LIMITDEFN.PERIOD_TYPE>C</TW341_LIMITDEFN.PERIOD_TYPE>
</Row>
<Row rowNumber="2">
<TW341_LIMITDEFN.LIMIT_CODE>023</TW341_LIMITDEFN.LIMIT_CODE>
<TW341_LIMITDEFN.LIMIT_TYPE>N</TW341_LIMITDEFN.LIMIT_TYPE>
<TW341_LIMITDEFN.PERIOD_VAL>3</TW341_LIMITDEFN.PERIOD_VAL>
<TW341_LIMITDEFN.PERIOD_TYPE>R</TW341_LIMITDEFN.PERIOD_TYPE>
</Row>
<Row rowNumber="3">
<TW341_LIMITDEFN.LIMIT_CODE>030</TW341_LIMITDEFN.LIMIT_CODE>
<TW341_LIMITDEFN.LIMIT_TYPE>N</TW341_LIMITDEFN.LIMIT_TYPE>
<TW341_LIMITDEFN.PERIOD_VAL>1</TW341_LIMITDEFN.PERIOD_VAL>
<TW341_LIMITDEFN.PERIOD_TYPE>C</TW341_LIMITDEFN.PERIOD_TYPE>
</Row>
I am trying to grab these values into an assert in a later step. I want the values to arrive in a data map.
I have the following Groovy script in my assert which I am hoping will pick up the values from the JDBC response and assign them to each data mapping stated in the script:
def jdbcResponse = context.expand( '${JDBC Request for expected results#ResponseAsXml}')
def xml = new XmlSlurper().parseText(jdbcResponse)
def expected = xml.'**'.findAll{it.name() == 'Row'}.collect{ [
LimitCode : it.TW341_LIMITDEFN.LIMIT_CODE.text(),
LimitType : it.TW341_LIMITDEFN.LIMIT_TYPE.text(),
LimitPeriod : it.TW341_LIMITDEFN.PERIOD_VAL.text(),
LimitPeriodType : it.TW341_LIMITDEFN.PERIOD_TYPE.text()
]
}.sort {it.LimitCode}
But the values form the JDBC response are not arriving. 'expected' looks like this:
Thu Oct 12 10:51:05 WST 2017:INFO:
[{LimitCode=, LimitType=, LimitPeriod=, LimitPeriodType=},
{LimitCode=, LimitType=, LimitPeriod=, LimitPeriodType=},
{LimitCode=, LimitType=, LimitPeriod=, LimitPeriodType=},]
I can see that 'xml' is coming through as follows:
Thu Oct 12 10:55:19 WST 2017:INFO:022N1C023N3R030N1C033N5R043N3R093N1C601S1C
Any ideas why I can't allocate these values from JDBC response XML into the data map values?
Upvotes: 0
Views: 583
Reputation: 21379
It is because, the element name has .
. Hence, you need to put the element name between the single quote(') as shown below:
def expected = xml.'**'.findAll{it.name() == 'Row'}.collect{ [
LimitCode : it.'TW341_LIMITDEFN.LIMIT_CODE'.text(),
LimitType : it.'TW341_LIMITDEFN.LIMIT_TYPE'.text(),
LimitPeriod : it.'TW341_LIMITDEFN.PERIOD_VAL'.text(),
LimitPeriodType : it.'TW341_LIMITDEFN.PERIOD_TYPE'.text()
]
}.sort {it.LimitCode}
Upvotes: 2