Forum Discussion

PaulDonny's avatar
PaulDonny
Regular Contributor
11 years ago

Favorite SoapUI Script

Just to see what all cool stuff people have done with SoapUI. I have quite a few that I use. A lot of mine are external to SoapUI but use it for the backend. I will post some of my Java code and some of my SoapUI code as well.


First, my Java stuff because I love these:

This one is still in development right now, it is going to be a tester that continuously runs and checks the status, ping etc etc of about 30 web services. Currently I am setting up the Admin panel which will allow the user to select a node and assign it's XPath to a property from a file or database. This project I should be wrapping up in the next week or so. I am just going to post the portions that build the project from a folder of WSDLs.

import com.eviware.soapui.config.TestStepConfig;
import com.eviware.soapui.impl.WsdlInterfaceFactory;
import com.eviware.soapui.impl.wsdl.*;
import com.eviware.soapui.impl.wsdl.testcase.*;
import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory;
import com.eviware.soapui.model.iface.Interface;
import com.eviware.soapui.model.iface.Operation;
import com.eviware.soapui.model.iface.Request;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import javax.swing.tree.DefaultTreeModel;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

/**
*
* @author Paul.Muir
*/
public class EndPointTester {

/**
* @param args the command line arguments
* @throws Exception
*/
public static void main(String[] args) throws Exception {
Map<String,NodeList> nodes = new HashMap<String,NodeList>();
WsdlProject project = buildProject();
buildTestCases(project);
for (Interface iface:project.getInterfaceList()) {
for (Operation op:iface.getOperationList()) {
for (Request req:op.getRequestList()) {
Document doc = loadXMLFromString(req.getRequestContent());
nodes.put(req.getOperation().getName(),doc.getChildNodes());
//This is where the document parsing would be done
}
}
}
project.saveAs("Test.xml");
System.exit(0);
}

private static WsdlProject buildProject() throws Exception {
File WSDLDir = new File(new File("").getAbsolutePath() + "\\Data\\WSDLs\\");
WsdlProject project = new WsdlProject();
project.setName("This is a new project");
WsdlInterface iface = null;
for (File wsdl : WSDLDir.listFiles()) {
iface = WsdlInterfaceFactory.importWsdl(project, wsdl.toString(), true)[0];
}
return project;
}

private static void buildTestCases(WsdlProject project) {
WsdlTestSuite TS = project.addNewTestSuite("Test");
WsdlTestCase TC = TS.addNewTestCase("Test");
TS.setName("Test");
for (Interface inface : project.getInterfaceList()) {
for (Operation op : inface.getAllOperations()) {
TestStepConfig TStepC = WsdlTestRequestStepFactory.createConfig((WsdlOperation) op, op.getName());
TC.addTestStep(TStepC);
}
}
}

private static Document loadXMLFromString(String xml) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
return builder.parse(new ByteArrayInputStream(xml.getBytes()));
}
}



This portion will scan a directory (currentDirectory\Data\WSDLs) and create a SoapUI project (Test.xml) with a test step for every single operation. My favorite within SoapUI itself has a lot of proprietary stuff in it that I sadly can not release, second favorite is likely my UI system:

viewtopic.php?f=5&t=22445