Search code examples
groovywsdlattachmentsoapui

How do I get the size of a response attachment in SoapUI?


I'm performing a series of file uploads and downloads through a WSDL defined interface in SoapUI (not Pro). The built-in assertions to verify these attachments are insufficient. I've found some Groovy code that allows me to get the size of the upload attachment.

import com.eviware.soapui.impl.wsdl.support.RequestFileAttachment

def uploadsize = testRunner.testCase.getTestStepByName("Upload File (200KB)").testRequest.getAttachmentAt(0).getSize()

I'm looking for comparable code to get the size of the download attachment. The HTTP headers specify that the content type is "multipart/related" and UTF-8. The attachment itself is "Content-Type: application/octet-stream \n Content-Transfer-Encoding: binary"

I've tried the following snippet of code but it doesn't give me the size of the attachment, just the size of the response.

def downloadsize = testRunner.testCase.getTestStepByName("Download File (200KB) (Logged)").testRequest.response.contentAsString.size()

Solution

  • Since the documentation for the SoapUI Groovy classes is labyrinthine at best, I used introspection to find out what kind of class I was working with:

    log.info testRunner.testCase.getTestStepByName("Download File (200KB) (Logged)").testRequest.class.name
    log.info testRunner.testCase.getTestStepByName("Download File (200KB) (Logged)").testRequest.response.class.name
    

    which yields:

    com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest
    com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.WsdlMimeMessageResponse
    

    Now one doesn't need to guess which class to look up.

    The resulting code for attachment size is:

    def downloadsize = testRunner.testCase.getTestStepByName("Download File (200KB) (Logged)").testRequest.response.getAttachments()[0].getSize()