0
votes

I am comparing JSON response and JSON File in SOAPUI (ver - 4.6.4, freeware) Groovy script:

import groovy.json.JsonSlurper
import java.io.File

def ResponseMessage = testRunner.testCase.testSteps["Fi - Request 1"].testRequest.response.contentAsString

def jsonResp = new JsonSlurper().parseText(ResponseMessage)

def jsonFile = new File("C:/Users/new_2.json")
def InputJSON = new JsonSlurper().parseFile(jsonFile, 'UTF-8')

assert jsonResp.equals(InputJSON)

But every time it runs a pop up of exception is thrown as:

groovy.lang.MissingMethodException: No signature of method: groovy.json.JsonSlurper.parseFile() is applicable for argument types: (java.io.File, java.lang.String) values: [C:\Users\new_2.json, UTF-8] Possible solutions: parseText(java.lang.String) error at line: 12

It didn't work for parseText either. Treat it as a beginner scripting.

Now I am facing completely new error -

groovy.json.JsonException: Lexing failed on line: 1, column: 1, while reading '', no possible valid JSON value or punctuation could be recognized.error at line: 9

Line 1 of JSON file content: {

"Metadata": {
    "DocType": "Report",
    "SubType": "",
    "Content": {
        "Title": "Economic Comment",
        "Headline": "",
        "Summary": "",
        "Blurb": ""

    },
    "Priority": "1",
    "DocumentIDs": {
        "DocumentID": {
            "label": "",
            "type": "",
            "level": "",
            "value": ""
        }
    },

Note: this content is incomplete. I cannot paste full JSON here due to security reasons

1
what is the version of groovy in soapui-4.6.4 ? check the name of the file SOAPUI/lib/groovy-all-*jardaggett
groovy-all-2.1.7NewToGroovy
so check the JsonSlurper class methods. Something like this should work for you: new JsonSlurper().parse( jsonFile.newReader("UTF-8") )daggett
Now I face a completely different error:NewToGroovy
groovy.json.JsonException: Lexing failed on line: 1, column: 1, while reading '', no possible valid JSON value or punctuation could be recognized. error at line: 9. JSON file content as : "Priority": "1", "DocumentIDs": { "DocumentID": { "label": "xyz", "type": "xyz", "level": "xyz", "value": "xyz"NewToGroovy

1 Answers

1
votes

The error message clearly says the alternatives.

Change below statement:

def InputJSON = new JsonSlurper().parseFile(jsonFile, 'UTF-8')

To:

def InputJSON = new JsonSlurper().parse(jsonFile, 'UTF-8')

Refer JsonSlurper API from documentation