Contributions
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)Solved10KViews0likes3CommentsInserting 10000 rows of data in database
Hi all, Goal: Use groovy to insert several rows in the database. Here I have to insert 10000 zipcodes with validity true or false in oracle database. Achieved: Know to insert one row Following is the code import groovy.sql.Sql import java.sql.SQLException import com.eviware.soapui.support.GroovyUtils.* try { def dbURL = context.expand('${#Project#ORACLE12c}') def dbUser = context.expand('${#Project#SchemaUser}') def dbPass = context.expand('${#Project#Pass}') def dbDriver = context.expand('${#Project#ORACLEDriver}') def dbconf = context.expand('${#Project#SchemaConf}') com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(dbDriver) def sql = Sql.newInstance(dbURL, dbUser, dbPass, dbDriver) sql.execute("DELETE FROM "+dbconf+".ZipCodes WHERE VALID='true'") sql.execute("INSERT INTO "+dbconf+".ZipCodes (ZIPCODE, VALID) VALUES ('71232', 'true')"); } catch (SQLException e){ def tmp = e.getSQLState () log.error (tmp, e) } How to insert several rows using groovy teststep or even JDBC teststep? Pls ignore the syntax error, if any.Solved2.7KViews0likes3CommentsExtracting value of an attribute from XML using groovy
I would use same sample xml from my previous post <property name="mail"> <entry key="server" value="outlook"/> </property> <property name="housekeep"> <entry key="files.days" value="60"/> <entry key="logs.days" value="30"/> </property> <property name="ConnectedDB"> <entry key="name" value="oracle" /> <entry key="table1" value="tableA" /> <entry key="table2" value="tableB"/> </property> Using groovy, I have to access "oracle". I am hard-coding to get the value of oracle. ..@value[0] def getxml = new XmlSlurper().parse(new File ('C:/ConfigXML/file.xml')) def chosenDB =getxml.property.find{it.@name=='ConnectedDB'}.entry.@value[0] log.info(chosenDB) //gives oracle Pls suggest without the hard-coded way..like give me the 'value' where 'key'== 'name' from property 'ConnectedDB'1.7KViews0likes0CommentsPassing value from external XML file to project/testsuite property and executing groovy script
I have an external XML config file which looks like below. I have to pass this value of"oracle" [from property name="ConnectedDB"] to soapui project properties or test suite properties <property name="mail"> <entry key="server" value="outlook"/> </property> <property name="housekeep"> <entry key="files.days" value="60"/> <entry key="logs.days" value="30"/> </property> <property name="ConnectedDB"> <entry key="name" value="oracle" /> <entry key="table1" value="tableA" /> <entry key="table2" value="tableB"/> </property> Once I know which database my software is connected to, I can run groovy script depending on database. I have 5 databases to choose from Currently, I am running all 5 scripts at once. (which is a bad idea considering the software is connected to one database at one time) I don't know if its possible or not. May be an idea or something... if its not possible, I would appreciate another alternative idea which could be implemented by me.924Views0likes1CommentRe: Groovy script for database manipulation using project property
I checked for MySQL, my syntax didn't work. Indeed your worked as well for MySQL. This is the sample for MySQL.. sql.execute("INSERT INTO "+dbschema1+".STATS VALUES ('01','$testRunner.testCase.name','CPU','MEMORY')) //worked sql.execute("INSERT INTO '$dbschema1'.STATS VALUES ('01','$testRunner.testCase.name','CPU','MEMORY')) //didn't work sql.execute("INSERT INTO $dbschema1.STATS VALUES ('01','$testRunner.testCase.name','CPU','MEMORY')) //didn't work and couple of more didn't work Just wanted to thank you!3.7KViews0likes1CommentRe: Groovy script for database manipulation using project property
You are absolutely right. It does displays the correct value INFO:DELETE FROM [EMP_SCHEMA].[dbo].[JOB] WHERE EMPNAME = 'NAME1' But while substituting with [$dbschema1] it gives the error . I don'tknowif its database mssql 2012 specific..i hope not3.7KViews0likes5CommentsRe: Groovy script for database manipulation using project property
Nope, it then gives error, I already checked some of these but doesn't work. com.microsoft.sqlserver.jdbc.SQLServerException: The index 1 is out of range. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setterGetParam(SQLServerPreparedStatement.java:714) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObjectNoType(SQLServerPreparedStatement.java:910) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.setObject(SQLServerPreparedStatement.java:935) at groovy.sql.Sql.setObject(Sql.java:3655) at groovy.sql.Sql.setParameters(Sql.java:3620) at groovy.sql.Sql.getPreparedStatement(Sql.java:3881) at groovy.sql.Sql.getPreparedStatement(Sql.java:3928) at groovy.sql.Sql.execute(Sql.java:2287) at groovy.sql.Sql.execute(Sql.java:2360) at groovy.sql.Sql$execute.call(Unknown Source) 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 Script40.run(Script40.groovy:16) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92) 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)3.7KViews0likes7CommentsGroovy script for database manipulation using project property
I want to execute simple delete query with the schema nametaken from project properties, but I am not sure how to pass the value to it, current way doesn't work for me. import groovy.sql.Sql import com.eviware.soapui.support.GroovyUtils.* def dbURL = context.expand('${#Project#MSSQLUrl}') def dbUser = context.expand('${#Project#MSSQLUser}') def dbPass = context.expand('${#Project#MSSQLPassword}') def dbDriver = context.expand('${#Project#MSSQLDriver}') def dbschema1 = context.expand('${#Project#Schema1}') def dbschema2 = context.expand('${#Project#Schema2}') com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(dbDriver) log.info (dbschema1) //logsEMP_SCHEMA def sql = Sql.newInstance(dbURL, dbUser, dbPass, dbDriver) sql.execute("DELETE FROM ['$dbschema1'].[dbo].[JOB] WHERE EMPNAME = 'NAME1'"); //doesnt work,com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name ''EMP_SCHEMA'.dbo.JOB'. error at line: 14 sql.execute("DELETE FROM [EMP_SCHEMA].[dbo].[JOB] WHERE EMPNAME = 'NAME1'"); //works Dont know how to pass the schema value to SQL querySolved3.8KViews0likes9Comments