How to convert JSON to XML using xslt?
Hi All, How can I convert the below JSON input request to XML format using XSLT I have tried with this XSLT from here https://www.quora.com/Is-there-a-way-to-convert-JSON-to-JSONX-without-using-IBM-DataPower but I didn't get desired output and it's throwing an error:"illegal character { at offset 0" in Datapower. My input request: { "SMS": [{ "to": "+966874939494", "Message": "<subject+message> " }, { "to": "+96687499490", "Message": "<subject+message>" } ] } My Expected Output: <?xml version="1.0" encoding="UTF-8"?> <sendReq> <MsgRqHdr> <RqUID>SR_123</RqUID> <SCId>SF12</SCId> <FuncId>36</FuncId> <UsrId>S12</UsrId> <Dt>2020-05-26T15:12:13</Dt> <Service>SMS</Service> </MsgRqHdr> <Body> <Com> <Specific> <Type>SMS</Type> </Specific> <CValue> <Char> <Name>ID</Name> </Char> <Value>966560329031</Value> </CValue> <CValue> <Char> <Name>Event</Name> </Char> <Value>subject&messagetext</Value> </CValue> <CValue> <Char> <Name>EventParam</Name> </Char> <Value>English</Value> </CValue> </Com> </Body> Can someone help on this please ? I never even tried Gateway script to give a try.3.1KViews0likes2CommentsValidate Data from DB2 in groovy script
I have 2 test cases, for one of them I need to validate in DB2, for the other one in SQL. The scenario: I have a search service and when sending a customer number I get all the credit cards connected to that customer. For this I need to validate in DB2. If I send a number for a customer who only has paypal accounts, I need to validate in SQL. For the second one I'm using simple SELECT query to retrieve records from one table. Here is the code that I use to validate: //----------Script Functions---------- //XMLify Response def XMLifyResponse(String step) { def resp = context.expand('${' + step + '#ResponseAsXml}') def xml = new XmlSlurper().parseText(resp) log.info("String response for step " + step + ": " + resp) log.info("XMLified content for step " + step + ": " + xml) return xml } //Jsonify Response def JsonifyResponse(String step) { def resp = context.expand('${' + step + '#Response}').toString() def json = new groovy.json.JsonSlurper().parseText(resp) log.info("String response for step " + step + ": " + resp) log.info("Jsonified content for step " + step + ": " + json) return json } //----------Main Script---------- //Parse Responses def xmlSQL = XMLifyResponse('TestData_SQL') def jsonEndpoint = JsonifyResponse('List Request') //Put into organized lists def sqlList =xmlSQL.'**'.findAll{it.name() == 'Row'} log.info("SQL LIST: "+sqlList) def endpointList = jsonEndpoint.creditCards //Validate Sizes assert sqlList.size() == endpointList.size() assert endpointList.size() <= 500, "Endpoint returned more than 500 results. " //Account Validation Endpoint - SQL endpointList.each { //Account Number def creditCardNumberHashCode = it.creditCardNumberHashCode.toString() log.info creditCardNumberHashCode def sqlcreditCardNumberHashCode = sqlList.find{it.PAYMENT_METHOD_ID.toString() == creditCardNumberHashCode} log.info sqlcreditCardNumberHashCode def statusCode = it.statusCode.toString() log.info statusCode assert it.creditCardNumberHashCode == sqlcreditCardNumberHashCode.PAYMENT_METHOD_ID.toString(), "SQL and endpoint account numbers do not match" assert it.statusCode == sqlcreditCardNumberHashCode.PAYMENT_METHOD_STATUS_TYPE_CD.toString() } log.info("Validation Complete") -------------------------------------------------------------------------- This line:def sqlcreditCardNumberHashCode = sqlList.find{it.PAYMENT_METHOD_ID.toString() == creditCardNumberHashCode} --- is supposed to create another list for that row where the account numbers match The problem arises when I need to validate in DB2 where the query retrieves following XML: <Row rowNumber="1"> <CUST_CREDT_CARD.CREDITCARD>0011001101</CUST_CREDT_CARD.CREDITCARD> <CUST_CREDT_CARD.CC_LAST_FOUR_NBR>1817</CUST_CREDT_CARD.CC_LAST_FOUR_NBR> <CUST_CREDT_CARD.CC_TYP_CD>VI </CUST_CREDT_CARD.CC_TYP_CD> </Row> <Row rowNumber="2"> <CUST_CREDT_CARD.CREDITCARD>00101010</CUST_CREDT_CARD.CREDITCARD> <CUST_CREDT_CARD.CC_LAST_FOUR_NBR>8453</CUST_CREDT_CARD.CC_LAST_FOUR_NBR> <CUST_CREDT_CARD.CC_TYP_CD>VI </CUST_CREDT_CARD.CC_TYP_CD> </Row> ---So when I use that same line of code to create a list from a row based on a specific credit card number from Json response: def db2creditCardNumberHashCode = db2List.find{it.CUST_CREDT_CARD.CREDITCARD.toString() == creditCardNumberHashCode} I get null object. I am Joining 3 tables and when querying db2 i receive an XML that gives the table and field (CUST_CREDT_CARD.CREDITCARD) and that seems to be the problem. When validating SQL jdbc response it works fine because it just retrieves me the field name (PAYMENT_METHOD_ID). I tried with using just CREDITCARD, I tried replacing the . (dot) with different things, nothing helped. Any suggestions will be greatly appreciated!1.1KViews0likes0CommentsHow to compare two Array Lists in SoapUI using groovy script?
I have 2 lists, the first one I got from json response when collecting all the customer numbers, the second one from a database using a query that should give me the same customer numbers as the response to the rest request. listA = [0012345678, 0012123443, 0012321232, 0055544321] listB = [0012123443,0012321232,0055544321, 0012345678] I want to check if both of the lists contain the same items. I don't care about the order, just if they have the exact same items. I tried listA.contains(listB), listA.containsAll(listB), i tried sorting both the lists (listA.sort() and listB.sort()) and then used equals, I still get false. It doesn't even seem to really sort the values, I thought this would work considering they are numbers, or at least appear so. There is no difference in number of white spaces between the numbers in both lists. Any suggestions?2.3KViews0likes1Commentparsing json via Groovy in soapui
The JSON Data is a response of a rest service(list_files) {"Files": [ {"filepath": "input/file_29112017d.csv"}, {"filepath": "input/file_29112017d.log"}, {"filepath": "input/file_29112017d.ini"}, {"filepath": "output/file_29112017d.xml"}, {"filepath": "output/file_29112017d.csv.trc"} ]} The goal is to get the path of csv file and not *csv.trc. Also the order of response varies with each test runs i.e $.Files[*].filepath[0] does not yield always input/file_29112017d.csv This doesn't work either import static com.jayway.jsonpath.JsonPath.parse def response = context.expand( '${list_files#Response}' ) //log.info response gives correctly def csvpath= parse(response).read('$.Files[?(@.filepath =~ /.*csv/i)]') log.info csvpath the error is Wed Nov 29 17:06:54 CET 2017:ERROR:java.lang.IllegalArgumentException: Unsupported operator = java.lang.IllegalArgumentException: Unsupported operator = at com.jayway.jsonpath.internal.filter.eval.ExpressionEvaluator.eval(ExpressionEvaluator.java:65) at com.jayway.jsonpath.internal.filter.ArrayEvalFilter.isMatch(ArrayEvalFilter.java:90) at com.jayway.jsonpath.internal.filter.ArrayEvalFilter.filter(ArrayEvalFilter.java:69) at com.jayway.jsonpath.internal.filter.PathTokenFilter.filter(PathTokenFilter.java:50) at com.jayway.jsonpath.JsonPath.read(JsonPath.java:255) at com.jayway.jsonpath.internal.JsonReader.read(JsonReader.java:103) at com.jayway.jsonpath.internal.JsonReader.read(JsonReader.java:97) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSite.invoke(PojoMetaMethodSite.java:189) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at Script12.run(Script12.groovy:5) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90) at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:141) at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:250) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)Solved11KViews0likes3CommentsHow can I assert a json parameter in Request with a XML response through Script Assertion in Soap UI
I am using SoapUI version 5.3.0 My Application have a couple of RESTful APIs. I am sending multiple request to a WebService in the form of a json request as below: { "app_key":"i8gAVDwcAq40n2kAv6Ox+w==", "targetDB":"${#TestCase#TARGET_DB}", "createNew": "true" } The response from the WebService is as follows: <StartDataExtractResult xmlns="http://schemas.datacontract.org/2004/07/AriaTechCore" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <StatusCode>1</StatusCode> <StatusText>success</StatusText> <RequestNumber>101</RequestNumber> </StartDataExtractResult> I am using a Groovy Script to generate a dynamic name for "targetDB" as follows: def targetdb = ((context.expand('${#TestCase#TARGET_DB}') ?: 100) as Integer) + 1 log.info "Target db for current request : ${targetdb}" context.testCase.setPropertyValue('TARGET_DB', targetdb.toString()) I have designed my Test data in such a way that passing the parameter of the 'targetdb' as "101" will result in the RequestNumber tag set to "101" in the response. Now I want to add an assertion to check if the RequestNumber tag contains the same value as of the variable "${#TestCase#TARGET_DB}" (sent in Request json) . To achieve that I wrote a Script Assertion as follows: def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) def holder = groovyUtils.getXmlHolder(messageExchange.responseContent) holder.namespaces["ns1"] = "http://schemas.datacontract.org/2004/07/AriaTechCore" def nodeRequestNumber = holder.getNodeValue("//ns1:RequestNumber") assert nodeRequestNumber != null if(nodeRequestNumber=="${TARGET_DB}") { log.info "Pass" } else { log.info "Fail"} But I am getting an error as: No such Property: TARGET_DB for class: Script 53 Can any one help me out please?Solved5.6KViews0likes6CommentsMismatch between JSON displayed in Raw Data and in JSON viewer pane
Hi, I am using SOAPUI 5.2.1 (build date: 20151002-1138) to test the response of a REST webservice. The service seems to be sending an incorrect JSON data, wherein a node that was expected to come as an array is, of course, not coming as an array. The JSON Viewer pane though shows the node as an array, which caused quite a bit great confusion till the raw data pane showed that the JSON response is indeed having an issue. To illustrate, let me give an example here: Data taken from Raw: { "APIResponse": { "Contact": { "phoneNumbers" : { "type" : "mobile", "number" : "1234567890" }, "phoneNumbers" : { "type" : "landline", "number" : "9876543210" } } } } And this is how it mysteriously appears in JSON tab with the node "phoneNumbers" automatically converted as an array: { "APIResponse": { "Contact": { "phoneNumbers" : [ { "type" : "mobile", "number" : "1234567890" }, { "type" : "landline", "number" : "9876543210" } ] } } } Any idea why this is happening? Thanks in advance!!819Views0likes0CommentsOn property transfer, getting invalid JSON although is valid & response is printed in the JSON tab
Hi , I have posted this issue earlier as well but did not get a solution to this problem. Hencereposting the same. I have created a sample project for the error. On hitting the request, i am able to see the JSON Response getting printed on the JSON tab. But when i am trying to extract a property, SOAP UI is throwing an error. I have attached screenshots of both the steps here. I have tried using groovy script as it was suggested on my earlier post but no luck. PFA the sample project with the JSON response as well. It looks like a bug to me but ifsomeone could pleasehelp, that would be really helpful. Regards, Piyu3.6KViews0likes5CommentsHow to make transfer data to post query string in json format
I try to make data transfer from first post request (response from it in json) to second (request in second method in multiform/data type, but query param contain Json array). I need to past value like "4e2c056931d398831128ad2c6a45ec91" in second post request as querystring param mediaIds: [{"mediaId":"54a985e73f0f9360039750aac89d0133","type":0}]where "type":0 just static parameter. How can I do it?Can I do it via target request? Or I must use "Property expansion"? or maybe it is impossible without Groovy? P.S. I haven't any problem with parse response from first request, but I don't know how to transform it in json array that I need =(1.2KViews0likes0Comments