Search in sources :

Example 1 with WsdlProject

use of com.eviware.soapui.impl.wsdl.WsdlProject in project iesi by metadew.

the class SOAPUIIntegration method main.

public static void main(String[] args) {
    try {
        getTestSuite();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.exit(0);
    // https://www.soapui.org/test-automation/junit/junit-integration.html#_ga=2.157007227.1117033134.1563254348-690893157.1557407813
    // out-app-analytics-provider-5.5.0.jar causes issues in eclipse on the build
    // path
    SoapUITestCaseRunner runner = new SoapUITestCaseRunner();
    runner.setProjectFile("c:/Data/ApiCase-soapui-project.xml");
    try {
        runner.run();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    WsdlProject project;
    try {
        project = new WsdlProject("c:/Data/ApiCase-soapui-project.xml");
        TestSuite testSuite = project.getTestSuiteByName("https://sandbox.api.belfius.be:8443 TestSuite");
        // TestCase testCase = testSuite.getTestCaseByName( "Test Conversions" );
        // create empty properties and run synchronously
        TestRunner runner2 = testSuite.run(new PropertiesMap(), false);
        System.out.println(runner2.getStatus());
    } catch (XmlException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SoapUIException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : TestSuite(com.eviware.soapui.model.testsuite.TestSuite) TestRunner(com.eviware.soapui.model.testsuite.TestRunner) XmlException(org.apache.xmlbeans.XmlException) SoapUITestCaseRunner(com.eviware.soapui.tools.SoapUITestCaseRunner) PropertiesMap(com.eviware.soapui.model.support.PropertiesMap) IOException(java.io.IOException) WsdlProject(com.eviware.soapui.impl.wsdl.WsdlProject) IOException(java.io.IOException) SoapUIException(com.eviware.soapui.support.SoapUIException) XmlException(org.apache.xmlbeans.XmlException) SoapUIException(com.eviware.soapui.support.SoapUIException)

Example 2 with WsdlProject

use of com.eviware.soapui.impl.wsdl.WsdlProject in project iesi by metadew.

the class SOAPUIIntegration method getTestSuite.

public static void getTestSuite() throws Exception {
    String suiteName = "";
    String reportStr = "";
    // variables for getting duration
    long startTime = 0;
    long duration = 0;
    TestRunner runner = null;
    List<TestSuite> suiteList = new ArrayList<TestSuite>();
    List<TestCase> caseList = new ArrayList<TestCase>();
    SoapUI.setSoapUICore(new StandaloneSoapUICore(true));
    // specified soapUI project
    WsdlProject project = new WsdlProject("c:/Data/ApiCase-soapui-project.xml");
    // get a list of all test suites on the project
    suiteList = project.getTestSuiteList();
    // you can use for each loop
    for (int i = 0; i < suiteList.size(); i++) {
        // get name of the "i" element in the list of a test suites
        suiteName = suiteList.get(i).getName();
        reportStr = reportStr + "\nTest Suite: " + suiteName;
        // get a list of all test cases on the "i"-test suite
        caseList = suiteList.get(i).getTestCaseList();
        for (int k = 0; k < caseList.size(); k++) {
            startTime = System.currentTimeMillis();
            // run "k"-test case in the "i"-test suite
            TestCaseRunner tcr = null;
            // runner =
            // project.getTestSuiteByName(suiteName).getTestCaseByName(caseList.get(k).getName()).run(new
            // PropertiesMap(), false);
            tcr = project.getTestSuiteByName(suiteName).getTestCaseByName(caseList.get(k).getName()).run(new PropertiesMap(), false);
            duration = System.currentTimeMillis() - startTime;
            // reportStr = reportStr + "\n\tTestCase: " + caseList.get(k).getName() +
            // "\tStatus: " + runner.getStatus() + "\tReason: " + runner.getReason() +
            // "\tDuration: " + duration;
            reportStr = reportStr + "\n\tTestCase: " + caseList.get(k).getName() + "\tStatus: " + tcr.getStatus() + "\tReason: " + tcr.getReason() + "\tDuration: " + tcr.getTimeTaken();
            for (TestStepResult tsr : tcr.getResults()) {
                String request = ((MessageExchange) tsr).getRequestContent();
                String response = ((MessageExchange) tsr).getResponseContent();
                System.out.println(response);
            }
        }
    }
    // string of the results
    System.out.println(reportStr);
}
Also used : TestStepResult(com.eviware.soapui.model.testsuite.TestStepResult) TestRunner(com.eviware.soapui.model.testsuite.TestRunner) ArrayList(java.util.ArrayList) TestCaseRunner(com.eviware.soapui.model.testsuite.TestCaseRunner) SoapUITestCaseRunner(com.eviware.soapui.tools.SoapUITestCaseRunner) PropertiesMap(com.eviware.soapui.model.support.PropertiesMap) WsdlProject(com.eviware.soapui.impl.wsdl.WsdlProject) TestSuite(com.eviware.soapui.model.testsuite.TestSuite) StandaloneSoapUICore(com.eviware.soapui.StandaloneSoapUICore) TestCase(com.eviware.soapui.model.testsuite.TestCase) MessageExchange(com.eviware.soapui.model.iface.MessageExchange)

Example 3 with WsdlProject

use of com.eviware.soapui.impl.wsdl.WsdlProject in project convertigo by convertigo.

the class WsReference method importSoapWebService.

private static HttpConnector importSoapWebService(Project project, WebServiceReference soapServiceReference) throws Exception {
    List<HttpConnector> connectors = new ArrayList<HttpConnector>();
    HttpConnector firstConnector = null;
    String wsdlUrl = soapServiceReference.getUrlpath();
    WsdlProject wsdlProject = new WsdlProject();
    WsdlInterface[] wsdls = WsdlImporter.importWsdl(wsdlProject, wsdlUrl);
    int len = wsdls.length;
    if (len > 0) {
        WsdlInterface iface = wsdls[len - 1];
        if (iface != null) {
            // Retrieve definition name or first service name
            String definitionName = null;
            try {
                Definition definition = iface.getWsdlContext().getDefinition();
                QName qname = definition.getQName();
                qname = (qname == null ? (QName) definition.getAllServices().keySet().iterator().next() : qname);
                definitionName = qname.getLocalPart();
            } catch (Exception e1) {
                throw new Exception("No service found !");
            }
            // Modify reference's name
            if (soapServiceReference.bNew) {
                // Note : new reference may have already been added to the project (new object wizard)
                // its name must be replaced with a non existing one !
                String newDatabaseObjectName = project.getChildBeanName(project.getReferenceList(), StringUtils.normalize("Import_WS_" + definitionName), true);
                soapServiceReference.setName(newDatabaseObjectName);
            }
            // Retrieve directory for WSDLs to download
            File exportDir = null;
            /* For further use...
				if (!webServiceReference.getFilepath().isEmpty()) {	// for update case
					try {
						exportDir = webServiceReference.getFile().getParentFile();
						if (exportDir.exists()) {
							File destDir = exportDir;
					   		for (int index = 0; destDir.exists(); index++) {
					   			destDir = new File(exportDir.getPath()+ "/v" + index);
					   		}
							Collection<File> files = GenericUtils.cast(FileUtils.listFiles(exportDir, null, false));
							for (File file: files) {
								FileUtils.copyFileToDirectory(file, destDir);
							}
						}
					} catch (Exception ex) {}
				}*/
            if (soapServiceReference.bNew || exportDir == null) {
                // for other cases
                String projectDir = project.getDirPath();
                exportDir = new File(projectDir + "/wsdl/" + definitionName);
                for (int index = 1; exportDir.exists(); index++) {
                    exportDir = new File(projectDir + "/wsdl/" + definitionName + index);
                }
            }
            // Download all needed WSDLs (main one and imported/included ones)
            String wsdlPath = iface.getWsdlContext().export(exportDir.getPath());
            // Modify reference's filePath : path to local main WSDL
            String wsdlUriPath = new File(wsdlPath).toURI().getPath();
            String wsdlLocalPath = ".//" + wsdlUriPath.substring(wsdlUriPath.indexOf("/wsdl") + 1);
            soapServiceReference.setFilepath(wsdlLocalPath);
            soapServiceReference.hasChanged = true;
            // Add reference to project
            if (soapServiceReference.getParent() == null) {
                project.add(soapServiceReference);
            }
            // create an HTTP connector for each binding
            if (soapServiceReference.bNew) {
                for (int i = 0; i < wsdls.length; i++) {
                    iface = wsdls[i];
                    if (iface != null) {
                        Definition definition = iface.getWsdlContext().getDefinition();
                        XmlSchemaCollection xmlSchemaCollection = WSDLUtils.readSchemas(definition);
                        XmlSchema xmlSchema = xmlSchemaCollection.schemaForNamespace(definition.getTargetNamespace());
                        HttpConnector httpConnector = createSoapConnector(iface);
                        if (httpConnector != null) {
                            String bindingName = iface.getBindingName().getLocalPart();
                            String newDatabaseObjectName = project.getChildBeanName(project.getConnectorsList(), StringUtils.normalize(bindingName), true);
                            httpConnector.setName(newDatabaseObjectName);
                            boolean hasDefaultTransaction = false;
                            for (int j = 0; j < iface.getOperationCount(); j++) {
                                WsdlOperation wsdlOperation = (WsdlOperation) iface.getOperationAt(j);
                                XmlHttpTransaction xmlHttpTransaction = createSoapTransaction(xmlSchema, iface, wsdlOperation, project, httpConnector);
                                // Adds transaction
                                if (xmlHttpTransaction != null) {
                                    httpConnector.add(xmlHttpTransaction);
                                    if (!hasDefaultTransaction) {
                                        xmlHttpTransaction.setByDefault();
                                        hasDefaultTransaction = true;
                                    }
                                }
                            }
                            connectors.add(httpConnector);
                        }
                    }
                }
                // add connector(s) to project
                for (HttpConnector httpConnector : connectors) {
                    project.add(httpConnector);
                    if (firstConnector == null) {
                        firstConnector = httpConnector;
                    }
                }
            }
        }
    } else {
        throw new Exception("No interface found !");
    }
    return firstConnector;
}
Also used : HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) XmlQName(com.twinsoft.convertigo.beans.common.XmlQName) QName(javax.xml.namespace.QName) XmlHttpTransaction(com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction) ArrayList(java.util.ArrayList) Definition(javax.wsdl.Definition) WsdlProject(com.eviware.soapui.impl.wsdl.WsdlProject) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) SAXException(org.xml.sax.SAXException) EngineException(com.twinsoft.convertigo.engine.EngineException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) WsdlOperation(com.eviware.soapui.impl.wsdl.WsdlOperation) XmlSchema(org.apache.ws.commons.schema.XmlSchema) WsdlInterface(com.eviware.soapui.impl.wsdl.WsdlInterface) File(java.io.File)

Example 4 with WsdlProject

use of com.eviware.soapui.impl.wsdl.WsdlProject in project iesi by metadew.

the class SoapUiExecution method execute.

public void execute() {
    try {
        String suiteName = "";
        String reportStr = "";
        // variables for getting duration
        long startTime = 0;
        long duration = 0;
        List<TestSuite> suiteList = new ArrayList<TestSuite>();
        List<TestCase> caseList = new ArrayList<TestCase>();
        SoapUI.setSoapUICore(new StandaloneSoapUICore(true));
        // specified soapUI project
        WsdlProject wsdlProject = new WsdlProject(this.getProject());
        // Define test suite scope
        if (this.getTestSuite().isEmpty()) {
            suiteList = wsdlProject.getTestSuiteList();
        } else {
            suiteList.add(wsdlProject.getTestSuiteByName(this.getTestSuite()));
        }
        // Loop test suites
        for (int i = 0; i < suiteList.size(); i++) {
            // get name of the "i" element in the list of a test suites
            suiteName = suiteList.get(i).getName();
            reportStr = reportStr + "\nTest Suite: " + suiteName;
            // get a list of all test cases on the "i"-test suite
            caseList = suiteList.get(i).getTestCaseList();
            for (int k = 0; k < caseList.size(); k++) {
                startTime = System.currentTimeMillis();
                // run "k"-test case in the "i"-test suite
                TestCaseRunner testCaseRunner = wsdlProject.getTestSuiteByName(suiteName).getTestCaseByName(caseList.get(k).getName()).run(new PropertiesMap(), false);
                duration = System.currentTimeMillis() - startTime;
                reportStr = reportStr + "\n\tTestCase: " + caseList.get(k).getName() + "\tStatus: " + testCaseRunner.getStatus() + "\tReason: " + testCaseRunner.getReason() + "\tDuration: " + testCaseRunner.getTimeTaken() + "\tCalculated Duration: " + duration;
                ;
                int l = 1;
                for (TestStepResult tsr : testCaseRunner.getResults()) {
                    String request = ((MessageExchange) tsr).getRequestContent();
                    this.writeToFile("request." + k + "." + l + ".out", request);
                    String response = ((MessageExchange) tsr).getResponseContent();
                    this.writeToFile("response." + k + "." + l + ".out", response);
                    l++;
                }
            }
        }
        // string of the results
        // System.out.println(reportStr);
        this.writeToFile("project.out", reportStr);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : TestStepResult(com.eviware.soapui.model.testsuite.TestStepResult) ArrayList(java.util.ArrayList) TestCaseRunner(com.eviware.soapui.model.testsuite.TestCaseRunner) PropertiesMap(com.eviware.soapui.model.support.PropertiesMap) WsdlProject(com.eviware.soapui.impl.wsdl.WsdlProject) IOException(java.io.IOException) TestSuite(com.eviware.soapui.model.testsuite.TestSuite) StandaloneSoapUICore(com.eviware.soapui.StandaloneSoapUICore) TestCase(com.eviware.soapui.model.testsuite.TestCase) MessageExchange(com.eviware.soapui.model.iface.MessageExchange)

Aggregations

WsdlProject (com.eviware.soapui.impl.wsdl.WsdlProject)4 PropertiesMap (com.eviware.soapui.model.support.PropertiesMap)3 TestSuite (com.eviware.soapui.model.testsuite.TestSuite)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 StandaloneSoapUICore (com.eviware.soapui.StandaloneSoapUICore)2 MessageExchange (com.eviware.soapui.model.iface.MessageExchange)2 TestCase (com.eviware.soapui.model.testsuite.TestCase)2 TestCaseRunner (com.eviware.soapui.model.testsuite.TestCaseRunner)2 TestRunner (com.eviware.soapui.model.testsuite.TestRunner)2 TestStepResult (com.eviware.soapui.model.testsuite.TestStepResult)2 SoapUITestCaseRunner (com.eviware.soapui.tools.SoapUITestCaseRunner)2 WsdlInterface (com.eviware.soapui.impl.wsdl.WsdlInterface)1 WsdlOperation (com.eviware.soapui.impl.wsdl.WsdlOperation)1 SoapUIException (com.eviware.soapui.support.SoapUIException)1 XmlQName (com.twinsoft.convertigo.beans.common.XmlQName)1 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)1 XmlHttpTransaction (com.twinsoft.convertigo.beans.transactions.XmlHttpTransaction)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 File (java.io.File)1