Kalaivanee Ramsekar
Kalaivanee Ramsekar

Reputation: 1

Unable to resolve class groovy.csv.CsvParser

When i execute below code block , i keep getting error as "unable to resolve class groovy.csv.CsvParser"

import groovy.json.JsonBuilder
import groovy.csv.CsvParser

def sections = []
def csvFile = new File('/test/performance/testdata/validation/createNote.csv')

def csvRows = []
csvFile.withReader { reader ->
    def csv = new CsvParser().parse(reader)
    csvRows = csv.collect()
}

def columnNames = ['E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W']
columnNames.each { columnName ->
    csvRows.each { row ->
        // Check if the column value is not empty or null
        if (row[columnName] && !row[columnName].isEmpty()) {
            sections << [
                "visitNoteSectionId": "\${VISIT_NOTE_SECTION_ID_${sections.size() + 1}}",
                "visitNoteId": "${VISIT_NOTE_ID}",
                "content": "\${${row[columnName]}}",
                "isEmpty": false
            ]
        }
    }
}

def jsonBuilder = new JsonBuilder();
jsonBuilder {
    patientId "${patientId}"
    visitNoteId "${VISIT_NOTE_ID}"
    dateOfService "${__time(yyyy-MM-dd'T'HH:mm:ss.SSS'Z',UTC)}"
    status "DRAFT"
    sections sections
    cptCodes [
        [
            "unit": "${unit_1}",
            "id": "${id_1}",
            "description": "${description_1}"
        ]
    ]
    problems [
        [
            "icdCode": "${icdCode}",
            "icdCodeDescription": "${icdCodeDescription}",
            "coreDiagnosisId": "${coreDiagnosisId}"
        ]
    ]
    resolveProblems []
    strikeoutProblems []
    placeOfServiceId null
}

println jsonBuilder.toPrettyString()

I have performed below steps as well

Download the groovy-csv JAR file from the Maven repository. Downloaded it from here: https://mvnrepository.com/artifact/com.xlson.groovycsv/groovycsv/1.3
Once downloaded the JAR file, placed it in the lib directory of your JMeter installation. The lib directory is where JMeter looks for additional JAR files to add to its classpath.
After placing the JAR file in the lib directory, restarted JMeter.

Upvotes: 0

Views: 169

Answers (2)

SiKing
SiKing

Reputation: 10329

According to documentation, the correct import is:

import static com.xlson.groovycsv.CsvParser.parseCsv

Also, since the parse() method is static, you need to chage:

def csv = new CsvParser().parse(reader) // do not instantiate the class, instead use:
def csv = parse(reader)  // as per documentation

Upvotes: 0

Ivan G
Ivan G

Reputation: 2732

I think you need to add the next import statement:

import com.xlson.groovycsv.CsvParser

Also according to JSR223 Sampler documentation:

The JSR223 test elements have a feature (compilation) that can significantly increase performance. To benefit from this feature:

  • Use Script files instead of inlining them. This will make JMeter compile them if this feature is available on ScriptEngine and cache them.

  • Or Use Script Text and check Cache compiled script if available property.

    When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.

So you might want to change the JMeter Functions and Variables inlined into your script with either parameters or Groovy-code-based equivalents.

More information on Groovy scripting in JMeter: Apache Groovy: What Is Groovy Used For?

Upvotes: 0

Related Questions