Forum Discussion

Buschfunk's avatar
Buschfunk
Frequent Contributor
15 years ago

[Solved] Groovy script does not find existing file

Hello,

I've generated a mock service from a WSDL with SoapUI Pro 3.6. This mock service has a test property.

Property name: InputFile
Property value: C:\Repository\Data\TEST\file.txt

Moreover the default response contains the following script:
def filename = context.expand(' ${#MockService#InputFile} ')
def f = new File(filename)
assert f.exists()

However, the assertion fails though this file definitely exists.

Inserting log.info(filename)[/font:2bt5mkkn] into the script outputs:
C:\Repository\Data\TEST\file.txt[/font:2bt5mkkn]

The assertion passes if I change the code as follows:
def filename = context.expand(' ${#MockService#InputFile} ')
def f = new File("C:\\Repository\\Data\\TEST\\file.txt")
assert f.exists()


Setting the property value to C:\\Repository\\Data\\TEST\\file.txt also results in a failing assertion.

Does anybody have an idea?

Thanks,
Robert
  • Buschfunk's avatar
    Buschfunk
    Frequent Contributor
    Some additional info which might help...

    log.info(f.absolutePath)[/font:1fpku7ih] returns a somewhat strange path:
    C:\Program Files (x86)\eviware\soapUI-Pro-3.6\bin\ C:\Repository\Data\TEST\file.txt[/font:1fpku7ih]

    absolutePath[/font:1fpku7ih] in a test case, i.e. not in a mock service, returns:
    C:\Repository\Data\TEST\file.txt[/font:1fpku7ih]
  • Hello,

    From the code you posted it looks like you've added two spaces in the path, it should be like this:

    def filename = context.expand('${#MockService#InputFile}')


    You can verify by doing something like log.info("[$filename]")
    which will show you if you have any spaces surrounding the path.

    Regards,
    Dain
    eviware.com
  • Buschfunk's avatar
    Buschfunk
    Frequent Contributor
    Great, thanks! You're right, there were extra blanks...