styks styks - 2 months ago 20
Groovy Question

How to check Response-Object in SoapUI has no attachment

I'm looking for an easy way to check whether the messageExchange-Object has no attachment, since there isn't a specified method to do that in the interface and apparently not in the implementations either.
Of course, when there is no attachment, something like

assert messageExchange.getResponseAttachments().length() == 0

won't work, and

assert messageExchange.getResponseAttachments() == null

is of no use either. I've seen there's a method
, however the documentation doesn't say what could possibly be in there (probably response object? I'm handling Xml btw), and since I haven't found out how to do proper logging in SoapUI yet (if possible without the extension plugin), I don't know if that thing contains anything useful.

It's obviously possible to check the response for the correct error code, but I'd like to know a way to do it in Script form if just for curiosity's sake.

If it's of any difference, I'm using the basic version. Thanks!


messageExchange variable allows you to get the response, and from here you can access the attachments array.

So you can try with the follow code inside the script assertion

assert messageExchange.response.getAttachments().size() == 0

Additionally if you're interested in logging on SoapUI, you can simply use log variable which is in almost all script contexts: 'your message' 


def myMsg = 'your' "${myMsg} message"

SoapUI use internally log4j so all available levels are log.debug,, log.warn... However note that default configuration level for this scripts is INFO, so log.debug prints nothings. You can check it in SOAPUI_HOME\bin\soapui-log4j.xml:

<logger name="groovy.log">
     <level value="INFO" />
    <appender-ref ref="GLOBAL_GROOVY_LOG" />