setProprertyValue string to integer to insert into database
From REST Request I get a json response which contains an accountID which I want to use in the next teststep as and id in insertion to database.
In the REST request I use script assertion:
import net.sf.json.groovy.JsonSlurper def jsonResponse = new JsonSlurper().parseText(messageExchange.responseContent) assert null != jsonResponse.accountId, "accountId of response either does not have value or null" context.testCase.testSuite.setPropertyValue('ACCOUNT_ID', jsonResponse.accountId.toString())
In the next JDBC step I use a property userId which has value ${#TestSuite#ACCOUNT_ID}.
But when I try the INSERT, I get a error that column is of type bigint but expression is of type character varying. I've tried typing it like so :userId::integer. But then I get an error which says "No value specified for parameter 2". I suppose it's because the string I get is an array.
The question is how can I setPropertyValue as a single int? There is no way that there could be an array of numbers. Userid is always just one number.
I've tried everything the groovy script like toInteger() and so on, but it won't let me do that.
Can someone suggest something?
Rao has identified the issue correctly, just got the order a little wrong.
You should be able to spot the problem following this:
def parse = {json -> new net.sf.json.groovy.JsonSlurper().parseText(json)} def json1 = '{"accountId":1000092192}' def json2 = '[{"accountId": 1000092192}]' assert parse(json1).accountId.toString() == '1000092192' assert parse(json2).accountId.toString() == '[1000092192]' assert parse(json2).first().toString() == json1 assert parse(json2).first().accountId.toString() == '1000092192'
Alternative notation:
assert parse(json2)[0] == parse(json2).first()