3
votes

I'm new to groovy script and what I'm trying to do is not working. What I try to do is:

  • Read a .csv file
  • Add the data from from the .csv file to a variable that I can use in XML (e.g.

test.csv name,age Tester,20 Java,30

and use the Tester in a variable named name in the XML and 30 in a variable named 20)

Which software / jar files do I use:

  • OpenCSV v3.9 jar file added to the SoapUI directory: bin/ext

  • GroovyCSV v1.1 jar file added to the SoapUI directory: bin/ext

  • SoapUI 5.2.1.

I searched Google on how to do this and used the following code to try to get it working:

   @Grab('com.xlson.groovycsv:groovycsv:1.1')
import static com.xlson.groovycsv.CsvParser.parseCsv

def csv = '''Name,Lastname
Mark,Andersson
Pete,Hansen'''

def data = parseCsv(csv)
for(line in data) {
    println "$line.Name $line.Lastname"
}

This is what I used to see if everything is working but I am getting the following error code:

java.lang.noclassdeffounderror: org/apache/ivy/core/settings/Ivysettings

I searched Google for this but couldn't really find a good solution, please advise.

1
If you've put groovyCSV (and all dependant jars) in the classpath, you don't need the @Grab - tim_yates

1 Answers

3
votes

Missing the dependency in the soapui's class path.

Just download the IvySetting and copy it under SOAPUI_HOME/bin/ext directory and restart soapui, then retry.

EDIT: Based on comments.

  • Got SoapUI 5.2
  • Extracted & Copied opencsv2.3.jar from this archive to SOAPUI_HOME/bin/ext
  • Copied groovycsv-1.1.jar from here
  • Restart SOAPUI.

Able to run the below script:

import static com.xlson.groovycsv.CsvParser.parseCsv

def csv = '''Name,Lastname
Mark,Andersson
Pete,Hansen'''

def data = parseCsv(csv)
for(line in data) {
    println "$line.Name $line.Lastname"
}

opencsv 3.9 has changed the packaging structure running into different issue. So, it would be better to stick to xlson documentation.