Forum Discussion

timo_veldt's avatar
8 years ago

Check if no message is received

I have a Java EE application that processes a bunch of messages from different interfaces. (Some of the) functional tests are performed with SoapUI.

In one of the cases I have created a SOAP VirtResponse step that receives the output of my application and checks the values in the received message. The test has the following steps:

  1. Datasource step to load input and expected output (multiple scenarios)
  2. JMS step to send input to application on a specific interface.
  3. SOAP step to receive application output on another interface (no validation).
  4. Groovy script to check results (e.g. no message received or message received with specific values). See below for the script, couldn't get it to work in between the list items.
  5. Datasource loop to step 2.

There is a scenario (well, there are more scenarios) in which the input should not generate an output. I want to check if my application did not send an output in such a scenario.

Strategy 1: I have added a fourth groovy step in which I validate that the result of step 3 is an empty string. To make the test pass, I had to disable the checkbox in TestCase Options that says "Fail TestCase on Error". This works in cases of happy execution of tests. However if an error does occur (e.g. the application did send a response when it was not supposed to or the application send a wrong response), the entire TestCase is set to passed (because of the checkbox) and only the specific step deep down in the logs is failed. This makes it hard to see the results of the entire test suite.

Attempted strategy 2: Started out by adding a conditional test step that will skip step 3 based on the input. However that way I no longer validate if my application does not send a message when it is not supposed to.

What is the best way to check these kinds of scenarios?

EDITS:

The entire testcase should fail if one of the scenarios from the datasource fails. (It is not a problem if this means that some scenarios were not evaluated yet)

Groovy script:

// Get flag from datasource that indicates if a message should be received
def soapBerichtOntvangen = context.expand('${DataSourceUISBerichten#SoapBerichtOntvangen}' );
// Get the message from the previous step.
def receivedSoapRequest = context.expand( '${SOAPVirtResponse#Request#declare namespace out=\'http://application/messageprocessing/outbound/out:SendOutboundMessage[1]/Message[1]}' )
// If we don't expect a message the flag is set to "N"
if(soapBerichtOntvangen=="N"){
    assert(receivedSoapRequest=="")
} else if(receivedSoapRequest!=null && receivedSoapRequest!=""){
    def slurpedMessage = new XmlSlurper().parseText(receivedSoapRequest)
    def messageType=slurpedMessage.MessageHeader.MessageReference.MessageType
    // Get expected values from context
    def verwachtMessageType = context.expand('${DataSourceOutboundCIBerichten#messageType}' )
    assert(String.valueOf(messageType)==verwachtMessageType)
} else {
    // Should have received a message, but none came up.
    assert(false)
}
No RepliesBe the first to reply