Jesko R.
Jesko R.

Reputation: 827

Properly adding an assertion to a WsdlTestRequestStep in SoapUI 5.0.0 in Java

I tried to add assertions to a WsdlTestRequestStep, but so far I failed in most parts.

The first thing that I did try was adding assertions using WsdlTestRequestStep.addAssertion which only worked for SoapResponseAssertion and updated the GUI properly. When I tried the same with a couple of other assertion types, SoapUI responded with and error in the console window and corrupted my project file with an assertion with empty type attribute. (see belowaddNotSoapFaultAssertion).

Then I did update the request config of the test step. This worked everytime without error. However, the GUI did only refresh when I reloaded the project, which is kind of impractical. (see below AddAssertions)

Now, I am wondering if there is a way to make this work properly, meaning no errors and immediate GUI update.

    import com.eviware.soapui.config.CredentialsConfig;
    import com.eviware.soapui.config.TestAssertionConfig;
    import com.eviware.soapui.config.WsdlRequestConfig;
    import com.eviware.soapui.impl.wsdl.WsdlProject;
    import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
    import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
    import com.eviware.soapui.impl.wsdl.teststeps.assertions.soap.NotSoapFaultAssertion;
    import com.eviware.soapui.impl.wsdl.teststeps.assertions.soap.SoapFaultAssertion;
    import com.eviware.soapui.impl.wsdl.teststeps.assertions.soap.SoapResponseAssertion;
    import com.eviware.soapui.model.testsuite.TestAssertion;
    import org.apache.log4j.Logger;

    public class SomeTestStep
    {
        private WsdlTestRequestStep _step;
        [...]    
        public void AddAssertions() {
            //addSoapResponseAssertion();
            //addNotSoapFaultAssertion();

            // directly manipulating config tree, but only updates UI after project reload  
            WsdlRequestConfig config = _step.getTestRequest().getConfig();
            TestAssertionConfig testAssertionConfig = config.addNewAssertion();
            testAssertionConfig.setType("SOAP Fault Assertion");
            testAssertionConfig.setName("Not SOAP Fault");
            // setConfig did not really change anything in terms of GUI updates, I kept it in anyway
            _step.getTestRequest().setConfig(config);

        }
        private void addSoapResponseAssertion() {
            //<con:assertion type="SOAP Response" name="SOAP Response"/>
           _step.addAssertion(SoapResponseAssertion.ID);
        }

        private void addNotSoapFaultAssertion() {
            // should create:<con:assertion type="SOAP Fault Assertion" name="Not SOAP Fault"/>
            // but creates: <con:assertion type="" />
            _step.addAssertion(SoapResponseAssertion.ID);
        }
}

Upvotes: 2

Views: 808

Answers (1)

Jesko R.
Jesko R.

Reputation: 827

After a lot of code crunching I finally found the solution to my problem.

The trick is to understand that WsdlTestRequestStep.addAssertion requires the label of the Assertion as an argument which is compared with the label that was set in the corresponding Assertion factory. So in my example the easiest way to get to the label was to get it from the NotSoapFaultAssertion.Factory itself. The following code snippet works as required:

private void addNotSoapFaultAssertion() {
    //<con:assertion type="SOAP Fault Assertion" name="Not SOAP Fault"/>
    _step.addAssertion((new NotSoapFaultAssertion.Factory()).getAssertionLabel());
}

I hope this will help anyone with the same issue in the future.

And here is a list of all assertion factories that I could find:

SoapResponseAssertion.Factory
SoapRequestAssertion.Factory
SchemaComplianceAssertion.Factory
SimpleContainsAssertion.Factory
SimpleNotContainsAssertion.Factory
XPathContainsAssertion.Factory
NotSoapFaultAssertion.Factory
SoapFaultAssertion.Factory
ResponseSLAAssertion.Factory
GroovyScriptAssertion.Factory
XQueryContainsAssertion.Factory
WSSStatusAssertion.Factory
WSAResponseAssertion.Factory
WSARequestAssertion.Factory
JMSStatusAssertion.Factory
JMSTimeoutAssertion.Factory
JdbcStatusAssertion.Factory
JdbcTimeoutAssertion.Factory
HttpDownloadAllResourcesAssertion.Factory

Upvotes: 2

Related Questions