Search in sources :

Example 1 with TestStepResult

use of com.eviware.soapui.model.testsuite.TestStepResult 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 2 with TestStepResult

use of com.eviware.soapui.model.testsuite.TestStepResult in project microcks by microcks.

the class SoapUITestStepsRunner method runOperationTestSteps.

/**
 * Run all the Operation test steps defined into the SoapUI project and having the name
 * contained into testStepNames (if not null nor empty).
 * @param operation The operation to run tests for
 * @param testResult TestResults that aggregate results within.
 * @param endpointUrl The URL of the endpoint to use for request test steps.
 * @param testStepNames A list of test step names to execute
 * @return A list of TestReturn wrapper objects (one by executed test step)
 */
public List<TestReturn> runOperationTestSteps(Operation operation, TestResult testResult, String endpointUrl, List<String> testStepNames) {
    // Remember to force no proxy otherwise SoapUI will use system settings and will
    // make them generally applied to everything going out through Apache Http Client
    // (and maybe also JDK HttpURLConnection ?).
    ProxyUtils.setProxyEnabled(false);
    String operationName = operation.getName();
    List<TestReturn> results = new ArrayList<TestReturn>();
    for (TestSuite testSuite : project.getTestSuiteList()) {
        for (TestCase testCase : testSuite.getTestCaseList()) {
            // Depending on testCase type build an accurate runner.
            TestCaseRunner testCaseRunner = buildTestCaseRunner(testCase);
            if (testCaseRunner != null) {
                for (TestStep testStep : testCase.getTestStepList()) {
                    if (testStep instanceof HttpRequestTestStep && testStep instanceof OperationTestStep && (testStepNames == null || testStepNames.contains(testStep.getName()))) {
                        log.debug("Looking up for testStep for operation '{}'", operationName);
                        if (operationName.equals(((OperationTestStep) testStep).getOperation().getName())) {
                            log.debug("Picking up step '{}' for running SoapUI test", testStep.getName());
                            // Set the endpointUrl using this common interface for Soap and Rest requests.
                            ((HttpRequestTestStep) testStep).getHttpRequest().setEndpoint(endpointUrl);
                            // Add or override existing headers with test specific ones for operation and globals.
                            if (testResult.getOperationsHeaders() != null) {
                                Set<Header> headers = new HashSet<>();
                                if (testResult.getOperationsHeaders().getGlobals() != null) {
                                    headers.addAll(testResult.getOperationsHeaders().getGlobals());
                                }
                                if (testResult.getOperationsHeaders().get(operationName) != null) {
                                    headers.addAll(testResult.getOperationsHeaders().get(operationName));
                                }
                                if (headers.size() > 0) {
                                    StringToStringsMap headersMap = new StringToStringsMap();
                                    for (Header header : headers) {
                                        headersMap.put(header.getName(), new ArrayList<>(header.getValues()));
                                    }
                                    ((HttpRequestTestStep) testStep).getHttpRequest().setRequestHeaders(headersMap);
                                }
                            }
                            // Running tests also checks linked assertions.
                            TestStepResult result = testStep.run(testCaseRunner, testCaseRunner.getRunContext());
                            log.debug("SoapUI test result is " + result.getStatus());
                            results.add(extractTestReturn(testStep.getName(), result));
                        }
                    }
                }
            }
        }
    }
    return results;
}
Also used : TestStepResult(com.eviware.soapui.model.testsuite.TestStepResult) HttpRequestTestStep(com.eviware.soapui.impl.support.http.HttpRequestTestStep) TestReturn(io.github.microcks.domain.TestReturn) ArrayList(java.util.ArrayList) WsdlTestCaseRunner(com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner) StringToStringsMap(com.eviware.soapui.support.types.StringToStringsMap) WsdlTestCase(com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase) HttpRequestTestStep(com.eviware.soapui.impl.support.http.HttpRequestTestStep) HashSet(java.util.HashSet)

Example 3 with TestStepResult

use of com.eviware.soapui.model.testsuite.TestStepResult 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

TestStepResult (com.eviware.soapui.model.testsuite.TestStepResult)3 ArrayList (java.util.ArrayList)3 StandaloneSoapUICore (com.eviware.soapui.StandaloneSoapUICore)2 WsdlProject (com.eviware.soapui.impl.wsdl.WsdlProject)2 MessageExchange (com.eviware.soapui.model.iface.MessageExchange)2 PropertiesMap (com.eviware.soapui.model.support.PropertiesMap)2 TestCase (com.eviware.soapui.model.testsuite.TestCase)2 TestCaseRunner (com.eviware.soapui.model.testsuite.TestCaseRunner)2 TestSuite (com.eviware.soapui.model.testsuite.TestSuite)2 HttpRequestTestStep (com.eviware.soapui.impl.support.http.HttpRequestTestStep)1 WsdlTestCase (com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase)1 WsdlTestCaseRunner (com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner)1 TestRunner (com.eviware.soapui.model.testsuite.TestRunner)1 StringToStringsMap (com.eviware.soapui.support.types.StringToStringsMap)1 SoapUITestCaseRunner (com.eviware.soapui.tools.SoapUITestCaseRunner)1 TestReturn (io.github.microcks.domain.TestReturn)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1