SoapUI Testing Chain

From WebLab Wiki
Jump to navigationJump to search

Install SoapUI and import the resource-validator into it

  • We will use the WebLab Resource Validator to check whether services outputs suit the WebLab requirements. To do so, copy resource-validator into {path_to_your_soapUI }/bin/ext/
  • Restart Soap-UI

Create a project for your services

  • Create a new SoapUI project "TestChain"


NewProject.jpg


  • Add your services in the project

We will use in this example, a chain of three services:

- tika-normaliser/analyser?wsdl

- gate-extraction/analyser?wsdl

- blank-lines-remover/analyser?wsdl

Add the first WSDL:


AddWsdl.jpg


AddWsdl2.jpg


In the same way, add the second and the third WSDL.


ProjectServices.jpg


Add your services requests to a testCase

Add the first request (the TikaExtractor Request) to a TestCase

  • In the request editor, select Add This Request to TestCase.


AddToTestSuite.jpg


  • Adding a request to a TestCase will open the Create TestSuite dialog box. Enter a name for your TestSuite and click OK.
  • After clicking OK, you will be asked to create a TestCase. In the Create TestCase dialog, enter a name for your TestCase and click OK.
  • Next, the dialog box Add Request to TestCase will appear. Enter a name for your Request and Click OK. (You can check the Add Not Soap Fault Assertion box to add the corresponding validation)


AddTestCase.jpg


  • In the same way, add the second and the third requests to the testCase.


TestCase.jpg


You have to enter a valid input data in the code editor of the TikaExtractor request as shown below. (Double Click on your Test Request. This will open the request editor.)


ValidResourceTika.jpg


The next step is to validate the response in your test using the WebLab Resource Validator.

Validate your services responses using the WebLab Resource Validator

Response message of services can be validated by adding a Script Assertion (Groovy script). In this Script, the imported WebLab Resource Validator will be used.


  • In the request editor, click the Add an Assertion to Test Request button. And select Script Assertion from the drop down in the Select Assertion dialog box.


AddAssertion.jpg


  • This brings up a configuration dialog. The top area is a standard soapUI script editor where you will add your Groovy script.


EditAssertion.jpg


The given code allows validating your service response. It selects the resource node, and passes it to the resource-validator.

import org.ow2.weblab.core.helpers.validator.ResourceValidator;
import com.eviware.soapui.support.XmlHolder;

def holder = new XmlHolder( messageExchange.responseContentAsXml )

holder.namespaces["analyser"] = "http://weblab.ow2.org/core/1.2/services/analyser"
def node = holder.getDomNode("//analyser:processReturn/resource[1]" )

assert ResourceValidator.validateXml (node.toString())==true

Notice that the given example concerns an Analyser Service (analyser:processReturn). When testing another type of service, be careful to select the appropriate node with the appropriate namespace. For example, if your test concerns a QueueManager Service, you have to use the following code to select the “nextResourceReturn” node:

holder.namespaces["qm"] = "http://weblab.ow2.org/core/1.2/services/queuemanager"
def node = holder.getDomNode("//qm:nextResourceReturn/resource[1]" )

  • In the request editor, pressing the Run button invokes the service, displays the response and applies the assertions, which gives you:


RunValidation.jpg

Transfer the processed WebLab resource between your services

The purpose here is to transfer automatically the resource node from a service SOAP Response and to insert it into the SOAP Request of the next service. To do so, we are going to use (1) the Property Transfer TestSteps to transfer XML properties using XPath and (2) a Groovy Script to transfert missing xml namespaces (those mentioned in ‘xsi:type’).

Add a property transfer

  • In the Test Step editor, select the Insert Step, and then the Property Transfer from the drop down menu.


AddPropertyTransfer.jpg


  • Adding a Property Transfer will open a dialog box. Enter a name for your Property transfer and click OK.
  • This will open an empty Property Transfer window. You have to fill it as following:


PropertyTransferEditor.jpg


Be careful to use the right namespaces and the right XPaths depending on your services processes (Source and Target).

  • When pressing the Run button, the resource node will get directly extracted from the Response message of the source Service (process – Tika) and written into the resource node of the Request message of the target Service (process – BlankLineremover).

Of course, the Request message of the source Service (process – Tika) must be a valid resource.


PropertyTransferResult.jpg


Add a Groovy Script

  • In the Test Step editor, select the Insert Step, and then the Groovy Script from the drop down menu.


AddGroovyTransfert.jpg


  • Adding a Groovy Script will open a dialog box. Enter a name for your Groovy Script and click OK.
  • This will open a configuration dialog. The top area is a standard soapUI script editor where you will add your Groovy script:


AddGroovyTransferEditor.jpg


import com.eviware.soapui.support.XmlHolder;
import com.eviware.soapui.support.GroovyUtils;
import org.w3c.dom.Element;

def modelUri="http://weblab.ow2.org/core/1.2/model#";

def groovyUtil = new GroovyUtils (context) ;

def holderResp = groovyUtil.getXmlHolder("process - Tika#Response") ;
holderResp.namespaces["analyser"] = "http://weblab.ow2.org/core/1.2/services/analyser";
def nsPrefix=holderResp.getNodeValue("//analyser:processReturn/local-name      (namespace::*[string()=\""+modelUri+"\"])");

def holderReq = groovyUtil.getXmlHolder("process - BlankLineRemover#Request");
holderReq.namespaces["soap"] = "http://schemas.xmlsoap.org/soap/envelope/";
def response = (Element)holderReq.getDomNode("/soap:Envelope[1]");
response.setAttribute("xmlns:"+nsPrefix.toString(),modelUri);

holderReq.setNodeValue("/.",response.toString());
holderReq.updateProperty() ;

Notice that the given example concerns a transfer from an Analyser Service (analyser:processReturn). When testing another type of service, be careful to select the appropriate node with the appropriate namespace.

For example, if your test concerns a transfer from a QueueManager Service, you have to use the following code to select the "nextResourceReturn" node:

holder.namespaces["qm"] = http://weblab.ow2.org/core/1.2/services/queuemanager
def nsPrefix=holderResp.getNodeValue("//qm:nextResourceReturn /local-name      (namespace::*[string()=\""+modelUri+"\"])");

You have also to be careful to use the right names of the two processes. In the example, we use a transfer from "process - Tika#Response" to "process - BlankLineRemover#Request". Use the names you gave to the request followed by "#Response" for the first service and "#Request" for the second one.


LeftMenu.jpg


  • Pressing the Run button extracts the local-name of the missing namespace (http://weblab.ow2.org/core/1.2/model#) from the Response message of the source Service (process – Tika) and add it as a declared namespace in the Envelope node of the Request message of the target Service (process – BlankLineRemover).


SecondTransfer.jpg


  • In the same way, add a transfer of resource from the Second Process to the Third one: You will obtain in the request editor:


FinalMenu.jpg

Execute the TestSteps

The TestCase is all set. Now the actual step-by-step execution of your TestCase takes place starting with the first enabled. A double click on Test Steps in the request editor will open the TestCase editor as shown below. Pressing the Run button will run the step-by-step execution. Notice that you must put a valid resource on your first request Message (in our example: process – Tika Request).


RunTests.jpg