コード例 #1
0
  @Override
  public void afterRun(TestCaseRunner testRunner, SecurityTestRunContext runContext) {
    TestCase testCase = testRunner.getTestCase();

    SecurityTest securityTest = ((SecurityTestRunner) testRunner).getSecurityTest();

    JUnitReport report = new JUnitReport();
    report.setIncludeTestProperties(includeTestPropertiesInReport);

    String reportName = securityTest.getName();
    report.setTestSuiteName(reportName);
    report.setPackage(testCase.getTestSuite().getProject().getName());
    int errorCount = 0;

    for (TestStep ts : testCase.getTestStepList()) {
      SecurityTestStepResult secuTestStepResult =
          securityTest.getSecurityTestStepResultMap().get(ts);
      if (secuTestStepResult != null) {
        for (SecurityScanResult scanResult : secuTestStepResult.getSecurityScanResultList()) {

          HashMap<String, String> testProperties = getTestPropertiesAsHashMap(securityTest);

          List<SecurityScanRequestResult> resultList = scanResult.getSecurityRequestResultList();
          Testcase secTestCase =
              report.addTestCase(
                  ts.getName() + " - " + scanResult.getSecurityScanName(),
                  scanResult.getTimeTaken(),
                  testProperties);

          secTestCase.setPackage(testCase.getTestSuite().getProject().getName());

          for (int i = 0; i < resultList.size(); i++) {
            SecurityScanRequestResult scanRequestResult = resultList.get(i);
            if (scanRequestResult.getStatus() == ResultStatus.FAILED) {
              StringBuffer result = new StringBuffer();
              result
                  .append("<pre>")
                  .append(XmlUtils.entitize(scanRequestResult.getChangedParamsInfo(i + 1)))
                  .append("</pre>");

              for (String message : scanRequestResult.getMessages()) {
                result.append("<pre>").append(XmlUtils.entitize(message)).append("</pre>");
              }

              secTestCase.addNewError().setStringValue(result.toString());
              errorCount++;
            }
          }
        }
      }

      report.setNoofErrorsInTestSuite(errorCount);
      report.setTotalTime(testRunner.getTimeTaken());

      reports.put(reportName, report);
    }
  }
コード例 #2
0
  @Override
  public void afterRun(TestCaseRunner testRunner, TestCaseRunContext runContext) {
    log.info(
        "Finished running SoapUI testcase ["
            + testRunner.getTestCase().getName()
            + "], time taken: "
            + testRunner.getTimeTaken()
            + "ms, status: "
            + testRunner.getStatus());

    if (testRunner.getStatus() == Status.FAILED) {
      failedTests.add(testRunner.getTestCase());
    }

    testCaseCount++;
  }
コード例 #3
0
  public TestStepResult run(TestCaseRunner testRunner, TestCaseRunContext context) {
    SoapUI.ensureGroovyLog();

    WsdlTestStepResult result = new WsdlTestStepResult(this);
    Logger log = (Logger) context.getProperty("log");
    if (log == null) log = logger;

    try {
      if (scriptText.trim().length() > 0)
        synchronized (this) {
          scriptEngine.setVariable("context", context);
          scriptEngine.setVariable("testRunner", testRunner);
          scriptEngine.setVariable("log", log);

          result.setTimeStamp(System.currentTimeMillis());
          result.startTimer();
          scriptResult = scriptEngine.run();
          result.stopTimer();

          if (scriptResult != null) {
            result.addMessage("Script-result: " + scriptResult.toString());
            // FIXME The property should not me hard coded
            firePropertyValueChanged("result", null, String.valueOf(result));
          }
        }

      // testRunner status may have been changed by script..
      Status testRunnerStatus = testRunner.getStatus();
      if (testRunnerStatus == Status.FAILED) result.setStatus(TestStepStatus.FAILED);
      else if (testRunnerStatus == Status.CANCELED) result.setStatus(TestStepStatus.CANCELED);
      else result.setStatus(TestStepStatus.OK);
    } catch (Throwable e) {
      String errorLineNumber = GroovyUtils.extractErrorLineNumber(e);

      SoapUI.logError(e);
      result.stopTimer();
      result.addMessage(e.toString());
      if (errorLineNumber != null) result.addMessage("error at line: " + errorLineNumber);
      result.setError(e);
      result.setStatus(TestStepStatus.FAILED);
    } finally {
      if (!isForLoadTest())
        setIcon(result.getStatus() == TestStepStatus.FAILED ? failedIcon : okIcon);

      if (scriptEngine != null) scriptEngine.clearVariables();
    }

    return result;
  }
コード例 #4
0
  public TestStepResult run(TestCaseRunner testRunner, TestCaseRunContext testRunContext) {
    WsdlMessageExchangeTestStepResult result = new WsdlMessageExchangeTestStepResult(this);

    testCaseRunner = null;

    if (targetTestCase != null) {
      Enum runMode = getRunMode();

      if (runMode == RunTestCaseRunModeTypeConfig.PARALLELL) {
        runningTestCase = createTestCase(targetTestCase);
      } else {
        runningTestCase = targetTestCase;

        TestCaseRunner targetTestRunner = SoapUI.getTestMonitor().getTestRunner(targetTestCase);
        if (targetTestRunner != null && targetTestRunner.getStatus() == TestRunner.Status.RUNNING) {
          if (runMode == RunTestCaseRunModeTypeConfig.SINGLETON_AND_FAIL) {
            result.setStatus(TestStepStatus.FAILED);
            result.addMessage("Target TestCase is already running");
            result.stopTimer();
            runningTestCase = null;
          } else {
            targetTestRunner.waitUntilFinished();
          }
        }
      }

      if (runningTestCase != null) {
        synchronized (runningTestCase) {
          for (TestRunListener listener : testRunListeners)
            runningTestCase.addTestRunListener(listener);

          StringList returnProperties = getReturnProperties();
          Map<String, TestProperty> props = getProperties();
          for (String key : props.keySet()) {
            if (runningTestCase.hasProperty(key) && !returnProperties.contains(key)) {
              String value = props.get(key).getValue();
              runningTestCase.setPropertyValue(
                  key, PropertyExpander.expandProperties(testRunContext, value));
            }
          }

          currentLabel = getLabel();
          runningTestCase.addTestRunListener(testRunListener);

          // StringToObjectMap properties = new StringToObjectMap();
          // for( String name : testRunContext.getPropertyNames() )
          // properties.put( name, testRunContext.getProperty( name ));

          result.startTimer();
          testCaseRunner = runningTestCase.run(new StringToObjectMap(), true);
          testCaseRunner.waitUntilFinished();
          result.stopTimer();

          for (String key : returnProperties) {
            if (runningTestCase.hasProperty(key))
              setPropertyValue(key, runningTestCase.getPropertyValue(key));
          }

          // aggregate results
          for (TestStepResult testStepResult : testCaseRunner.getResults()) {
            result.addMessage(
                testStepResult.getTestStep().getName()
                    + " - "
                    + testStepResult.getStatus()
                    + " - "
                    + testStepResult.getTimeTaken());
            for (String msg : testStepResult.getMessages()) {
              result.addMessage("- " + msg);
            }

            if (testStepResult instanceof MessageExchangeTestStepResult) {
              result.addMessages(
                  ((MessageExchangeTestStepResult) testStepResult).getMessageExchanges());
            }
          }

          switch (testCaseRunner.getStatus()) {
            case CANCELED:
              result.setStatus(TestStepStatus.CANCELED);
              break;
            case FAILED:
              result.setStatus(TestStepStatus.FAILED);
              break;
            case FINISHED:
              result.setStatus(TestStepStatus.OK);
              break;
            default:
              result.setStatus(TestStepStatus.UNKNOWN);
              break;
          }

          for (TestRunListener listener : testRunListeners)
            runningTestCase.removeTestRunListener(listener);

          if (runMode == RunTestCaseRunModeTypeConfig.PARALLELL) runningTestCase.release();

          runningTestCase = null;
          testCaseRunner = null;
        }
      }
    } else {
      result.setStatus(TestStepStatus.FAILED);
      result.addMessage("Missing testCase in project");
      result.stopTimer();
    }

    return result;
  }
コード例 #5
0
 @Override
 public void beforeRun(TestCaseRunner testRunner, TestCaseRunContext runContext) {
   log.info("Running SoapUI testcase [" + testRunner.getTestCase().getName() + "]");
 }
コード例 #6
0
 public void testCaseStarted(TestCaseRunner runner) {
   if (runner.getTestCase() == getModelItem().getTestCase()) {
     setEnabled(false);
   }
 }