Ejemplo n.º 1
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++;
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
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;
  }