ReadyAPI - How to compare quoted array with unquoted array
Hello,
For my test I have a REST Request that gives back a json response.
[{
"nationalId": "01050110250",
"driverLicences": [{
"model": "BC",
"number": "1453464727",
"deliveryType": "INITIAL",
"deliveryDate": "2019-05-26",
"nis": "36015",
"codes": []
}, {
"model": "36",
"number": "1401373153",
"deliveryType": "INITIAL",
"deliveryDate": "2018-07-11",
"nis": "36015",
"codes": []
}
]
}, {
"nationalId": "91061463327",
"driverLicences": [{
"model": "BC",
"number": "1453462846",
"deliveryType": "INITIAL",
"deliveryDate": "2019-05-26",
"nis": "36015",
"codes": []
}, {
"model": "18",
"number": "1399476210",
"deliveryType": "INITIAL",
"deliveryDate": "2018-06-30",
"nis": "36015",
"codes": []
}
]
}, {
"nationalId": "01020214652",
"driverLicences": [{
"model": "BC",
"number": "1453461856",
"deliveryType": "INITIAL",
"deliveryDate": "2019-05-26",
"nis": "33011",
"codes": []
}, {
"model": "18",
"number": "1436496259",
"deliveryType": "EXCHANGE",
"deliveryDate": "2019-02-13",
"nis": "33039",
"codes": []
}, {
"model": "36",
"number": "1402915651",
"deliveryType": "INITIAL",
"deliveryDate": "2018-07-19",
"nis": "33039",
"codes": []
}
]
}, {
"nationalId": "01052314229",
"driverLicences": [{
"model": "BC",
"number": "1453472447",
"deliveryType": "INITIAL",
"deliveryDate": "2019-05-26",
"nis": "11002",
"codes": []
}, {
"model": "36",
"number": "1401628719",
"deliveryType": "INITIAL",
"deliveryDate": "2018-07-11",
"nis": "11002",
"codes": []
}
]
}
}]
As you can see, this json has an array with responses. I've searched for the nationalId and stashed them in a parameter on testcase level. This results in an array without quotes.
The extraction was done like this:
def getNRN = context.expand( '${REST Request#Response#$[*][\'nationalId\']}' )
assert getNRN != "" : "NRN is blank"
assert getNRN != null : "NRN is null"
testRunner.testCase.setPropertyValue("p_NRN", getNRN.toString())
log.info getNRN
A second test step will get information from a logfile on a website where the same values are in it. But the problem here is that this response gives me the same array but with quotes and as an XML answer.
HTTP/1.1 200 OK
Date: Thu, 08 Oct 2020 14:18:54 GMT
Server: Apache
Strict-Transport-Security: max-age=31536000
Last-Modified: Thu, 08 Oct 2020 10:08:00 GMT
ETag: "24098a-525-5b12601c504b2"
Accept-Ranges: bytes
Content-Length: 1317
Connection: close
Content-Type: text/plain
<data>
<Admin-data>
<Timestamp>2020-10-08 12:02:49</Timestamp>
<DataTreatmentId>DTO_S666_001</DataTreatmentId>
</Admin-data>
<URL-data>
<URL>/MobilityServices/1.0/ComebackMomentService</URL>
</URL-data>
<QueryString-data>
</QueryString-data>
<RequestHTTPHeader-data>
<fsbTransactionId>X37jyCwR6FDqdTz3XUxvlQAAANU</fsbTransactionId>
<method>GET</method>
</RequestHTTPHeader-data>
<RequestBody-data>
</RequestBody-data>
<ResponseHTTPHeader-data>
<Response-code>200</Response-code>
<ServiceInfo>{prvateinformation}</ServiceInfo>
</ResponseHTTPHeader-data>
<ResponseBody-data>
<DataSubject-01>["01050110250","91061463327","01020214652","01052314229"]</DataSubject-01>
</ResponseBody-data>
</data>
I need to assert that both arrays are the same. How can I do so please?
What I have so far (but it gives me an error message of course)
import com.eviware.soapui.support.XmlHolder
import groovy.json.JsonSlurper
//import groovy.xml.XmlSlurper
def holder = new XmlHolder( messageExchange.responseContentAsXml )
def rrn = holder.getNodeValue( "//data[1]/ResponseBody-data[1]/DataSubject-01[1]" )
log.info rrn.toString()
def natRegNr = context.expand( '${#TestCase#p_NRN}' )
assert getRRN != null
assert getRRN == natRegNr
I've tried to escape the quotes from the response but the regex doesn't work (
If I parse this into a jsonSlurper, the result remains the same. The quotes are still there.
anybody an idea please?
Thanks in advance,
AboveAndAbove.
AAB : As i can see you are just logging the value not storing the value in the variable. Just assign the value in the variable as below
def rrn = holder.getNodeValue( "//data[1]/ResponseBody-data[1]/DataSubject-01[1]" ) rrn = rrn.toString().replace("\"","")
Hope this will work.