parsing 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)Solved11KViews0likes3CommentsCompare test step
Purpose The process of testing often requires to compare test results to expected values. When we need to check a specific value, we can use assertions. However, there are often occasions when we need to compare one documents to another (e.g. XML, JSON). I propose to introduce a new type of test step: Compare test step. Functionality Compare test step would allow: Select documents: users would select source and target document from test step requests, responses, properties and other document holders in SoapUI environment, similarly as the Property Transfer test step does. Type of comparisson: the user could choose whether the documents have to be identical (both structure and values) or similar (only the structure should be same). Also the user could choose to ignore differences in whitespaces, attributes, or namespaces, or even data types which to ignore (e.g. xsd:dateTime is typically different). List of items to compare/ignore: the user could list the items which should be ignored, represented by XPath statements. Also there would be an opposite option: a list of XPath statements to check and to ignore the rest of the documents. Suggestions The Compare test step can utilize the XMLUnit library for XML and thus expose its function via SoapUI user interface. The Compare step can be similarly used for JSON documents.9KViews8likes3CommentsGet unexpected char: 0xFFFF exception when try to URLEncode JSON request
I am trying to send URLEncoded request. In order to URLEncode my request I am using following code in my request body: =${=java.net.URLEncoder.encode("""{ 'Guid': '934172bb-80d2-4888-a2e6-2ec6015df5dc', 'DateTime': '2016-03-16T00:00:00+00:00' }""", java.nio.charset.StandardCharsets.UTF_8.toString())} When I try to send the request I get following exception: =startup failed: Script17.groovy: 4: unexpected char: 0xFFFF @ line 4, column 1.org.codehaus.groovy.syntax.SyntaxException: unexpected char: 0xFFFF @ line 4, column 1. at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:138) at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:111) at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:237) at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:167) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:931) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:694) at groovy.lang.GroovyShell.parse(GroovyShell.java:706) at groovy.lang.GroovyShell.parse(GroovyShell.java:742) at groovy.lang.GroovyShell.parse(GroovyShell.java:733) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:138) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:89) at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SoapUIProGroovyScriptEngineFactory.java:79) at com.eviware.soapui.model.propertyexpansion.resolvers.EvalPropertyResolver.doEval(EvalPropertyResolver.java:165) at com.eviware.soapui.model.propertyexpansion.resolvers.EvalPropertyResolver.resolveProperty(EvalPropertyResolver.java:145) at com.eviware.soapui.model.propertyexpansion.PropertyExpander.expand(PropertyExpander.java:211) at com.eviware.soapui.model.propertyexpansion.PropertyExpander.expand(PropertyExpander.java:156) at com.eviware.soapui.model.propertyexpansion.PropertyExpander.expand(PropertyExpander.java:152) at com.eviware.soapui.model.propertyexpansion.PropertyExpander.expandProperties(PropertyExpander.java:135) at com.eviware.soapui.impl.wsdl.submit.filters.HttpRequestFilter.filterHttpRequest(HttpRequestFilter.java:320) at com.eviware.soapui.impl.wsdl.submit.filters.RestRequestFilter.filterRestRequest(RestRequestFilter.java:31) at com.eviware.soapui.impl.wsdl.submit.filters.AbstractRequestFilter.filterAbstractHttpRequest(AbstractRequestFilter.java:42) at com.eviware.soapui.impl.wsdl.submit.filters.AbstractRequestFilter.filterRequest(AbstractRequestFilter.java:34) at com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.filterRequest(HttpClientRequestTransport.java:378) at com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.sendRequest(HttpClientRequestTransport.java:183) at com.eviware.soapui.impl.wsdl.WsdlSubmit.run(WsdlSubmit.java:119) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: Script17.groovy:4:1: unexpected char: 0xFFFF at org.codehaus.groovy.antlr.parser.GroovyLexer.mSTRING_CTOR_END(GroovyLexer.java:2345) at org.codehaus.groovy.antlr.parser.GroovyLexer.mSTRING_LITERAL(GroovyLexer.java:1942) at org.codehaus.groovy.antlr.parser.GroovyLexer.nextToken(GroovyLexer.java:478) at org.codehaus.groovy.antlr.parser.GroovyLexer$1.nextToken(GroovyLexer.java:262) at groovyjarjarantlr.TokenBuffer.fill(TokenBuffer.java:69) at groovyjarjarantlr.TokenBuffer.LA(TokenBuffer.java:80) at groovyjarjarantlr.LLkParser.LA(LLkParser.java:52) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.pathExpression(GroovyRecognizer.java:11680) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.postfixExpression(GroovyRecognizer.java:13410) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.unaryExpressionNotPlusMinus(GroovyRecognizer.java:13379) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.powerExpressionNotPlusMinus(GroovyRecognizer.java:13083) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.multiplicativeExpression(GroovyRecognizer.java:13015) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.additiveExpression(GroovyRecognizer.java:12685) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.shiftExpression(GroovyRecognizer.java:9921) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.relationalExpression(GroovyRecognizer.java:12590) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.equalityExpression(GroovyRecognizer.java:12514) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.regexExpression(GroovyRecognizer.java:12462) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.andExpression(GroovyRecognizer.java:12430) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.exclusiveOrExpression(GroovyRecognizer.java:12398) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.inclusiveOrExpression(GroovyRecognizer.java:12366) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.logicalAndExpression(GroovyRecognizer.java:12334) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.logicalOrExpression(GroovyRecognizer.java:12302) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.conditionalExpression(GroovyRecognizer.java:4956) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.assignmentExpression(GroovyRecognizer.java:8122) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.expression(GroovyRecognizer.java:10061) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.expressionStatementNoCheck(GroovyRecognizer.java:8449) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.expressionStatement(GroovyRecognizer.java:8995) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.statement(GroovyRecognizer.java:1278) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.compilationUnit(GroovyRecognizer.java:668) at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:134) ... 34 more 1 error """, java.nio.charset.StandardCharsets.UTF_8.toString())} The issue is with {. If I remove {, I don't get any exception. I also tried to escape { using \ but it didn't work. Any help would be appriciated. Thanks, Ritesh6.5KViews0likes3CommentsOAS 3.0.3 request schema for an empty JSON body
I am attempting to create an OAS schema for an empty JSON body: { } I am trying to get the documentation to show an empty JSON body, and have that autogenerated. The API defines this as a POST (yes, it ought to be a GET, the design of the API is in some respects sub-optimal) request, and expects the open/close bracket, and nothing else. I've tried … content: application/json: { } … but that doesn't work (it just shows nothing in the request body), and everything else I've tried is invalid. Would appreciate any assistance on this. I have not been able to find any examples or even similar questions (maybe I’m looking in the wrong place?). Any assistance would be greatly appreciated!Solved6.1KViews0likes2CommentsSoapUI NG Pro 1.4.0 - JSON Response view removing decimal points
Hello, I am testing REST API's. I just upgraded to 1.4.0. On my tests, I have a content assertion for an account balance field. This has always been set to validate a content of '0.0'. However after upgrading, this assertion always fails. Expected 0.0, Actual 0. 1.4.0 is removing the decimal point in JSON view, the raw response still contains the decimal point. Example of Raw response: { "OutstandingBalance": 0.0 } Example of JSON View tab for same element: { "OutstandingBalance": 0 } Can this be investigated please as all of my existing tests (of which there are a lot) are failing because of this. It is the0.0 value I am expecting to see. Please let me know of any additional information that may be needed. ThanksSolved5.8KViews0likes9CommentsHow 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.6KViews0likes6Commentsjson block as a property value
Is it possible to have a json block as my property value? { "firstName": "John", "lastName" : "doe", "age" : 26, "address" : { "streetAddress": "naist street", "city" : "Nara", "postalCode" : "630-0192" } I tried it by making it a single line and it worked. However, when it comes to large json data, it will be very hard to maintain it.Solved5.1KViews0likes8CommentsCompare two REST response and ignore some fields
to compare two json response i can use below function but in the current context response return some dynamic fields which will be unique every time, can some one please explain how we can handle this void compareResponse(def atcualresponse, def expectedREsponse){ def map1 = new JsonSlurper().parseText(atcualresponse) def map2 = new JsonSlurper().parseText(expectedREsponse) assert map1 == map2 }Solved4.3KViews0likes7CommentsMaven Soapui Plugin with json assertions does not work well in junit test
Maven Soapui Plugin with json assertions does not work well when i use last respository version in a maven project: <groupId>com.smartbear.soapui</groupId> <artifactId>soapui-maven-plugin</artifactId> <version>5.1.3</version> Logs: 17:37:26,465 ERROR [TestAssertionRegistry] Missing assertion for type [JsonPath RegEx Match] 17:37:26,482 ERROR [TestAssertionRegistry] Missing assertion for type [JsonPath Count] When will it be released 5.1.2 version to be able to use this type of assertion? A lot of thanks!!!!! Cristian Romero Matesanz3.9KViews0likes3CommentsOn 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.5KViews0likes5Comments