Forum Discussion

saska_filip's avatar
saska_filip
New Contributor
9 years ago

how to process mime http response

Hello everybody,   I have a problem with processing MIME response. I am testing a HTTP service, which return a multipart response containing 2 parts. One is a response xml containing cid reference ...
  • saska_filip's avatar
    saska_filip
    9 years ago

    Hi Rao,

    thank you for the answer, this helped me a lot! I ran your script and ran into problems with getting the response from messageExhange. So ditched the option to use it as an assert script and got the attachment from testrunner:

     

    def testStep = testRunner.testCase.getTestStepByName( "GetDataRequest" )
    def response = testStep.testRequest.response
    def attachments = response.attachments

     

    then I converted the attachment into String using your script:

    attachments[i].inputStream.text

     

    After this it was easy to extract the information I needed from the string. This is the script that is working for me:

    def testStep = testRunner.testCase.getTestStepByName( "GetDataRequest" )
    def response = testStep.testRequest.response
    def attachments = response.attachments
    def attachmentCount = attachments.length
    
    def myInvoiceID = testRunner.testCase.getTestStepByName("GeneralProperties").getPropertyValue("InvoiceNumber")
    
    assert attachmentCount > 1, "No invoice was returned by AN"
    
    def attachmentContent
    def invoiceID
    def result = false
    
    for(i=1; i< attachmentCount; i++) {
    	attachmentContent = attachments[i].inputStream.text
    
    	assert attachmentContent.contains("invoiceID"), "Invoice ID is missing"
    
    	invoiceID = attachmentContent.split("invoiceID=")[1]
    	invoiceID = invoiceID.split("\"")[1]	
    
    	if (invoiceID.equals(myInvoiceID) ) {
    		result = true
    	}	
    }
    
    if(!result) {
    	log.info("Invoice was not found. Going back to GetPending")
    	testRunner.gotoStepByName( "Wait10s_2")
    } else {
    	log.info("Invoice was found. Proceeding with invoice acknowledgement")
    }

     

    Thank you all for your contribution. Hope it helps somebody else sometime :)

     

    Kind regards,

    Filip