Пример #1
0
  /** We need to check that we are not pointing at testcase in original testsuite */
  public void afterCopy(WsdlTestSuite oldTestSuite, WsdlTestCase oldTestCase) {
    super.afterCopy(oldTestSuite, oldTestCase);

    if (targetTestCase != null && oldTestSuite == targetTestCase.getTestSuite()) {
      setTargetTestCase(getTestCase().getTestSuite().getTestCaseByName(targetTestCase.getName()));
    }
  }
  public WsdlRunTestCaseStepDesktopPanel(WsdlRunTestCaseTestStep modelItem) {
    super(modelItem);

    project = getModelItem().getTestCase().getTestSuite().getProject();

    getModelItem().addPropertyChangeListener(WsdlRunTestCaseTestStep.TARGET_TESTCASE, this);
    WsdlTestCase targetTestCase = getModelItem().getTargetTestCase();
    if (targetTestCase != null) {
      targetTestCase.addPropertyChangeListener(WsdlTestCase.NAME_PROPERTY, this);
      targetTestCase.getTestSuite().addPropertyChangeListener(WsdlTestCase.NAME_PROPERTY, this);
    }

    buildUI();
    setEnabledState();

    if (modelItem.getTargetTestCase() == null) {
      SwingUtilities.invokeLater(
          new Runnable() {

            public void run() {
              optionsAction.actionPerformed(null);
            }
          });
    }

    setPreferredSize(new Dimension(400, 600));
  }
 private String createTitleForBorder() {
   WsdlTestCase targetTestCase = getModelItem().getTargetTestCase();
   return "TestCase ["
       + (targetTestCase == null
           ? "- none selected -"
           : targetTestCase.getTestSuite().getName() + ":" + targetTestCase.getName())
       + "] Run Properties";
 }
Пример #4
0
  private void syncProperties() {
    for (String name : propertyHolderSupport.getPropertyNames()) {
      if (!targetTestCase.hasProperty(name)) propertyHolderSupport.removeProperty(name);
    }

    for (String name : targetTestCase.getPropertyNames()) {
      if (!propertyHolderSupport.hasProperty(name)) propertyHolderSupport.addProperty(name);
    }
  }
Пример #5
0
  @Override
  public void release() {
    if (targetTestCase != null) {
      targetTestCase.getTestSuite().removeTestSuiteListener(testSuiteListener);
      targetTestCase.removeTestPropertyListener(testPropertyListener);
    }

    super.release();
  }
Пример #6
0
 /**
  * Runs the specified TestCase
  *
  * @param testCase the testcase to run
  * @param context
  */
 protected void runTestCase(WsdlTestCase testCase) {
   try {
     log.info("Running TestCase [" + testCase.getName() + "]");
     WsdlTestCaseRunner runner = testCase.run(new StringToObjectMap(), false);
     log.info(
         "TestCase ["
             + testCase.getName()
             + "] finished with status ["
             + runner.getStatus()
             + "] in "
             + (runner.getTimeTaken())
             + "ms");
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 public void perform(ModelItem[] targets, Object param) {
   for (ModelItem target : targets) {
     if (target instanceof WsdlTestStep) ((WsdlTestStep) target).setDisabled(false);
     else if (target instanceof WsdlTestCase) ((WsdlTestCase) target).setDisabled(false);
     else if (target instanceof WsdlTestSuite) ((WsdlTestSuite) target).setDisabled(false);
   }
 }
Пример #8
0
  @Override
  public void resolve(ResolveContext<?> context) {
    super.resolve(context);

    if (targetTestCase == null) {
      if (context.hasThisModelItem(
          this, "Missing Test Case", getTestStepTitle() + "/" + stepConfig.getTargetTestCase()))
        return;
      context
          .addPathToResolve(
              this, "Missing Test Case", getTestStepTitle() + "/" + stepConfig.getTargetTestCase())
          .addResolvers(
              new RunTestCaseRemoveResolver(this),
              new ChooseAnotherTestCase(this),
              new CreateNewEmptyTestCase(this));
    } else {
      targetTestCase.resolve(context);
      if (context.hasThisModelItem(
          this, "Missing Test Case", getTestStepTitle() + "/" + stepConfig.getTargetTestCase())) {
        context
            .getPath(
                this,
                "Missing Test Case",
                getTestStepTitle() + "/" + stepConfig.getTargetTestCase())
            .setSolved(true);
      }
    }
  }
Пример #9
0
  /**
   * Creates a copy of the underlying WsdlTestCase with all LoadTests removed and configured for
   * LoadTesting
   */
  private WsdlTestCase createTestCase(WsdlTestCase testCase) {
    // clone config and remove and loadtests
    testCase.beforeSave();

    try {
      TestCaseConfig config = TestCaseConfig.Factory.parse(testCase.getConfig().xmlText());
      config.setLoadTestArray(new LoadTestConfig[0]);

      // clone entire testCase
      WsdlTestCase wsdlTestCase = testCase.getTestSuite().buildTestCase(config, true);
      wsdlTestCase.afterLoad();
      return wsdlTestCase;
    } catch (Throwable e) {
      SoapUI.logError(e);
    }

    return null;
  }
  public boolean onClose(boolean canCancel) {
    getModelItem().removePropertyChangeListener(WsdlRunTestCaseTestStep.TARGET_TESTCASE, this);

    WsdlTestCase targetTestCase = getModelItem().getTargetTestCase();
    if (targetTestCase != null) {
      targetTestCase.removePropertyChangeListener(WsdlTestCase.NAME_PROPERTY, this);
      targetTestCase.getTestSuite().removePropertyChangeListener(WsdlTestCase.NAME_PROPERTY, this);
    }

    testRunLog.release();
    if (optionsDialog != null) {
      optionsDialog.release();
      optionsDialog = null;
    }

    propertiesTable.release();
    inspectorPanel.release();

    return release();
  }
Пример #11
0
  public void setTargetTestCase(WsdlTestCase testCase) {
    if (targetTestCase != null) {
      targetTestCase.getTestSuite().removeTestSuiteListener(testSuiteListener);
      targetTestCase.removeTestPropertyListener(testPropertyListener);
    }

    WsdlTestCase oldTestCase = this.targetTestCase;
    this.targetTestCase = testCase;

    if (testCase != null) {
      stepConfig.setTargetTestCase(testCase.getId());

      targetTestCase.getTestSuite().addTestSuiteListener(testSuiteListener);
      targetTestCase.addTestPropertyListener(testPropertyListener);

      syncProperties();
    }

    notifyPropertyChanged(TARGET_TESTCASE, oldTestCase, testCase);
  }
  public void propertyChange(PropertyChangeEvent evt) {
    super.propertyChange(evt);

    if (evt.getPropertyName().equals(WsdlRunTestCaseTestStep.TARGET_TESTCASE)) {
      WsdlTestCase targetTestCase = (WsdlTestCase) evt.getOldValue();
      if (targetTestCase != null) {
        targetTestCase.removePropertyChangeListener(WsdlTestCase.NAME_PROPERTY, this);
        targetTestCase
            .getTestSuite()
            .removePropertyChangeListener(WsdlTestCase.NAME_PROPERTY, this);
      }

      targetTestCase = (WsdlTestCase) evt.getNewValue();
      if (targetTestCase != null) {
        targetTestCase.addPropertyChangeListener(WsdlTestCase.NAME_PROPERTY, this);
        targetTestCase.getTestSuite().addPropertyChangeListener(WsdlTestCase.NAME_PROPERTY, this);
      }
    }

    setEnabledState();
    titledBorder.setTitle(createTitleForBorder());
    repaint();
  }
  protected void createTransfer(StringToStringMap values) {
    String propertyTransfer = values.get(TRANSFER_STEP);

    WsdlTestCase testCase = (WsdlTestCase) request.getTestCase();
    TransferResponseValuesTestStep transferStep =
        (TransferResponseValuesTestStep) testCase.getTestStepByName(propertyTransfer);

    if (transferStep == null) {
      int index = testCase.getIndexOfTestStep(request.getRequestStep());
      transferStep =
          (TransferResponseValuesTestStep)
              testCase.insertTestStep(
                  TransferValuesStepFactory.TRANSFER_TYPE, propertyTransfer, index);
    }

    if (transferStep == null) {
      UISupport.showErrorMessage("Missing transfer step [" + propertyTransfer + "]");
      return;
    }

    PropertyTransfer transfer = transferStep.getTransferByName(values.get(TRANSFER_NAME));
    if (transfer == null) transfer = transferStep.addTransfer(values.get(TRANSFER_NAME));

    transfer.setTargetStepName(request.getRequestStep().getName());
    transfer.setTargetPropertyName("Request");
    transfer.setTargetPath(values.get(TARGET_XPATH));

    String sourceStepName = values.get(SOURCE_STEP);
    transfer.setSourceStepName(sourceStepName);

    TestStep sourceStep = testCase.getTestStepByName(sourceStepName);
    if (sourceStep == null) {
      sourceStep =
          (WsdlPropertiesTestStep)
              testCase.insertTestStep(PropertiesStepFactory.PROPERTIES_TYPE, sourceStepName, 0);
    }

    String sourcePropertyName = values.get(SOURCE_PROPERTY);

    if (sourceStep.getProperty(sourcePropertyName) == null
        && sourceStep instanceof WsdlPropertiesTestStep) {
      ((WsdlPropertiesTestStep) sourceStep).addProperty(sourcePropertyName);
    }

    transfer.setSourcePropertyName(sourcePropertyName);

    if (values.getBoolean(OPEN_EDITOR)) {
      TransferResponseValuesDesktopPanel panel =
          (TransferResponseValuesDesktopPanel) UISupport.showDesktopPanel(transferStep);

      panel.selectTransfer(transfer);
    }
  }
Пример #14
0
  public void perform(WsdlTestCase testCase, Object param) {
    String name =
        UISupport.prompt("Specify name of TestCase", "Rename TestCase", testCase.getName());
    if (name == null || name.equals(testCase.getName())) return;
    while (testCase.getTestSuite().getTestCaseByName(name.trim()) != null) {
      name =
          UISupport.prompt(
              "Specify unique name of TestCase", "Rename TestCase", testCase.getName());
      if (name == null || name.equals(testCase.getName())) return;
    }

    testCase.setName(name);
  }
Пример #15
0
  public void perform(WsdlTestCase testCase, Object param) {
    if (dialog == null) {
      dialog = ADialogBuilder.buildDialog(Form.class);
      dialog
          .getFormField(Form.PROJECT)
          .addFormFieldListener(
              new XFormFieldListener() {

                public void valueChanged(XFormField sourceField, String newValue, String oldValue) {
                  if (newValue.equals(CREATE_NEW_OPTION))
                    dialog.setOptions(Form.TESTSUITE, new String[] {CREATE_NEW_OPTION});
                  else {
                    Project project = SoapUI.getWorkspace().getProjectByName(newValue);
                    dialog.setOptions(
                        Form.TESTSUITE,
                        ModelSupport.getNames(
                            project.getTestSuiteList(), new String[] {CREATE_NEW_OPTION}));
                  }
                }
              });
      dialog
          .getFormField(Form.CLONE_DESCRIPTION)
          .addFormFieldListener(
              new XFormFieldListener() {

                public void valueChanged(XFormField sourceField, String newValue, String oldValue) {
                  if (dialog.getBooleanValue(Form.CLONE_DESCRIPTION)) {
                    dialog.getFormField(Form.DESCRIPTION).setEnabled(false);
                  } else {
                    dialog.getFormField(Form.DESCRIPTION).setEnabled(true);
                  }
                }
              });
    }

    dialog.setBooleanValue(Form.MOVE, false);
    dialog.setBooleanValue(Form.CLONE_DESCRIPTION, true);
    dialog.getFormField(Form.DESCRIPTION).setEnabled(false);
    dialog.setValue(Form.DESCRIPTION, testCase.getDescription());
    dialog.setValue(Form.NAME, "Copy of " + testCase.getName());
    WorkspaceImpl workspace = testCase.getTestSuite().getProject().getWorkspace();
    dialog.setOptions(
        Form.PROJECT,
        ModelSupport.getNames(workspace.getOpenProjectList(), new String[] {CREATE_NEW_OPTION}));

    dialog.setValue(Form.PROJECT, testCase.getTestSuite().getProject().getName());

    dialog.setOptions(
        Form.TESTSUITE,
        ModelSupport.getNames(
            testCase.getTestSuite().getProject().getTestSuiteList(),
            new String[] {CREATE_NEW_OPTION}));

    dialog.setValue(Form.TESTSUITE, testCase.getTestSuite().getName());
    boolean hasLoadTests = testCase.getLoadTestCount() > 0;
    dialog.setBooleanValue(Form.CLONE_LOADTESTS, hasLoadTests);
    dialog.getFormField(Form.CLONE_LOADTESTS).setEnabled(hasLoadTests);

    if (dialog.show()) {
      String targetProjectName = dialog.getValue(Form.PROJECT);
      String targetTestSuiteName = dialog.getValue(Form.TESTSUITE);
      String name = dialog.getValue(Form.NAME);

      WsdlProject project = testCase.getTestSuite().getProject();
      WsdlTestSuite targetTestSuite = null;
      Set<Interface> requiredInterfaces = new HashSet<Interface>();

      // to another project project?
      if (!targetProjectName.equals(project.getName())) {
        // get required interfaces
        for (int y = 0; y < testCase.getTestStepCount(); y++) {
          WsdlTestStep testStep = testCase.getTestStepAt(y);
          requiredInterfaces.addAll(testStep.getRequiredInterfaces());
        }

        project = (WsdlProject) workspace.getProjectByName(targetProjectName);
        if (project == null) {
          targetProjectName = UISupport.prompt("Enter name for new Project", "Clone TestCase", "");
          if (targetProjectName == null) return;

          try {
            project = workspace.createProject(targetProjectName, null);
          } catch (SoapUIException e) {
            UISupport.showErrorMessage(e);
          }

          if (project == null) return;
        }

        if (requiredInterfaces.size() > 0 && project.getInterfaceCount() > 0) {
          Map<String, Interface> bindings = new HashMap<String, Interface>();
          for (Interface iface : requiredInterfaces) {
            bindings.put(iface.getTechnicalId(), iface);
          }

          for (Interface iface : project.getInterfaceList()) {
            bindings.remove(iface.getTechnicalId());
          }

          requiredInterfaces.retainAll(bindings.values());
        }

        if (requiredInterfaces.size() > 0) {
          String msg =
              "Target project [" + targetProjectName + "] is missing required Interfaces;\r\n\r\n";
          for (Interface iface : requiredInterfaces) {
            msg += iface.getName() + " [" + iface.getTechnicalId() + "]\r\n";
          }
          msg += "\r\nThese will be cloned to the targetProject as well";

          if (!UISupport.confirm(msg, "Clone TestCase")) return;

          for (Interface iface : requiredInterfaces) {
            project.importInterface((AbstractInterface<?>) iface, true, true);
          }
        }
      }

      targetTestSuite = project.getTestSuiteByName(targetTestSuiteName);
      if (targetTestSuite == null) {
        targetTestSuiteName =
            UISupport.prompt(
                "Specify name for new TestSuite",
                "Clone TestCase",
                "Copy of " + testCase.getTestSuite().getName());
        if (targetTestSuiteName == null) return;

        targetTestSuite = project.addNewTestSuite(targetTestSuiteName);
      }

      boolean move = dialog.getBooleanValue(Form.MOVE);
      WsdlTestCase newTestCase =
          targetTestSuite.importTestCase(
              testCase, name, -1, dialog.getBooleanValue(Form.CLONE_LOADTESTS), !move);
      UISupport.select(newTestCase);

      if (move) {
        testCase.getTestSuite().removeTestCase(testCase);
      }
      boolean cloneDescription = dialog.getBooleanValue(Form.CLONE_DESCRIPTION);
      if (!cloneDescription) {
        newTestCase.setDescription(dialog.getValue(Form.DESCRIPTION));
      }
    }
  }
 @Override
 String getCopyAfterInfo(WsdlMockResponse source, WsdlTestCase target) {
   return "Add MockResponse TestStep to TestCase [" + target.getName() + "]";
 }
 @Override
 boolean canCopyAfter(WsdlMockResponse source, WsdlTestCase target) {
   return source.getMockOperation().getMockService().getProject()
       == target.getTestSuite().getProject();
 }
Пример #18
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;
  }
    public void actionPerformed(ActionEvent e) {
      if (optionsDialog == null) {
        optionsDialog = ADialogBuilder.buildDialog(OptionsForm.class);
        optionsDialog
            .getFormField(OptionsForm.TESTSUITE)
            .addFormFieldListener(
                new XFormFieldListener() {

                  public void valueChanged(
                      XFormField sourceField, String newValue, String oldValue) {
                    List<TestCase> testCaseList =
                        project.getTestSuiteByName(newValue).getTestCaseList();
                    testCaseList.remove(getModelItem().getTestCase());
                    optionsDialog.setOptions(
                        OptionsForm.TESTCASE, ModelSupport.getNames(testCaseList));

                    if (testCaseList.size() > 0) {
                      WsdlTestCase testCase = project.getTestSuiteByName(newValue).getTestCaseAt(0);
                      optionsDialog.setOptions(
                          OptionsForm.RETURN_PROPERTIES, testCase.getPropertyNames());
                      ((XFormMultiSelectList)
                              optionsDialog.getFormField(OptionsForm.RETURN_PROPERTIES))
                          .setSelectedOptions(getModelItem().getReturnProperties().toStringArray());
                    }
                  }
                });
        optionsDialog
            .getFormField(OptionsForm.TESTCASE)
            .addFormFieldListener(
                new XFormFieldListener() {

                  public void valueChanged(
                      XFormField sourceField, String newValue, String oldValue) {
                    WsdlTestSuite testSuite =
                        project.getTestSuiteByName(optionsDialog.getValue(OptionsForm.TESTSUITE));
                    WsdlTestCase testCase = testSuite.getTestCaseByName(newValue);
                    optionsDialog.setOptions(
                        OptionsForm.RETURN_PROPERTIES, testCase.getPropertyNames());
                    ((XFormMultiSelectList)
                            optionsDialog.getFormField(OptionsForm.RETURN_PROPERTIES))
                        .setSelectedOptions(getModelItem().getReturnProperties().toStringArray());
                  }
                });
      }

      WsdlTestCase targetTestCase = getModelItem().getTargetTestCase();

      optionsDialog.setOptions(
          OptionsForm.TESTSUITE, ModelSupport.getNames(project.getTestSuiteList()));
      if (targetTestCase != null) {
        optionsDialog.setValue(OptionsForm.TESTSUITE, targetTestCase.getTestSuite().getName());

        List<TestCase> testCaseList = targetTestCase.getTestSuite().getTestCaseList();
        testCaseList.remove(getModelItem().getTestCase());

        optionsDialog.setOptions(OptionsForm.TESTCASE, ModelSupport.getNames(testCaseList));
        optionsDialog.setValue(OptionsForm.TESTCASE, targetTestCase.getName());

        optionsDialog.setOptions(OptionsForm.RETURN_PROPERTIES, targetTestCase.getPropertyNames());
        ((XFormMultiSelectList) optionsDialog.getFormField(OptionsForm.RETURN_PROPERTIES))
            .setSelectedOptions(getModelItem().getReturnProperties().toStringArray());
      } else {
        if (project.getTestSuiteCount() == 0) {
          optionsDialog.setOptions(OptionsForm.TESTCASE, new String[0]);
          optionsDialog.setOptions(OptionsForm.RETURN_PROPERTIES, new String[0]);
        } else {
          List<TestCase> testCaseList = project.getTestSuiteAt(0).getTestCaseList();
          testCaseList.remove(getModelItem().getTestCase());
          optionsDialog.setOptions(OptionsForm.TESTCASE, ModelSupport.getNames(testCaseList));

          if (testCaseList.isEmpty())
            optionsDialog.setOptions(OptionsForm.RETURN_PROPERTIES, new String[0]);
          else
            optionsDialog.setOptions(
                OptionsForm.RETURN_PROPERTIES, testCaseList.get(0).getPropertyNames());
        }
      }

      switch (getModelItem().getRunMode().intValue()) {
        case RunTestCaseRunModeTypeConfig.INT_PARALLELL:
          optionsDialog.setValue(
              OptionsForm.RUN_MODE, OptionsForm.CREATE_ISOLATED_COPY_FOR_EACH_RUN);
          break;
        case RunTestCaseRunModeTypeConfig.INT_SINGLETON_AND_FAIL:
          optionsDialog.setValue(OptionsForm.RUN_MODE, OptionsForm.RUN_PRIMARY_TEST_CASE);
          break;
        case RunTestCaseRunModeTypeConfig.INT_SINGLETON_AND_WAIT:
          optionsDialog.setValue(OptionsForm.RUN_MODE, OptionsForm.RUN_SYNCHRONIZED_TESTCASE);
          break;
      }

      optionsDialog.setBooleanValue(
          OptionsForm.COPY_HTTP_SESSION, getModelItem().isCopyHttpSession());
      optionsDialog.setBooleanValue(
          OptionsForm.COPY_LOADTEST_PROPERTIES, getModelItem().isCopyLoadTestProperties());
      optionsDialog.setBooleanValue(
          OptionsForm.IGNORE_EMPTY_PROPERTIES, getModelItem().isIgnoreEmptyProperties());

      if (optionsDialog.show()) {
        WsdlTestSuite testSuite =
            project.getTestSuiteByName(optionsDialog.getValue(OptionsForm.TESTSUITE));
        getModelItem()
            .setTargetTestCase(
                testSuite == null
                    ? null
                    : testSuite.getTestCaseByName(optionsDialog.getValue(OptionsForm.TESTCASE)));
        getModelItem()
            .setReturnProperties(
                new StringList(
                    ((XFormMultiSelectList)
                            optionsDialog.getFormField(OptionsForm.RETURN_PROPERTIES))
                        .getSelectedOptions()));

        switch (optionsDialog.getValueIndex(OptionsForm.RUN_MODE)) {
          case 0:
            getModelItem().setRunMode(RunTestCaseRunModeTypeConfig.PARALLELL);
            break;
          case 1:
            getModelItem().setRunMode(RunTestCaseRunModeTypeConfig.SINGLETON_AND_FAIL);
            break;
          case 2:
            getModelItem().setRunMode(RunTestCaseRunModeTypeConfig.SINGLETON_AND_WAIT);
            break;
        }

        getModelItem()
            .setCopyHttpSession(optionsDialog.getBooleanValue(OptionsForm.COPY_HTTP_SESSION));
        getModelItem()
            .setCopyLoadTestProperties(
                optionsDialog.getBooleanValue(OptionsForm.COPY_LOADTEST_PROPERTIES));
        getModelItem()
            .setIgnoreEmptyProperties(
                optionsDialog.getBooleanValue(OptionsForm.IGNORE_EMPTY_PROPERTIES));

        titledBorder.setTitle(createTitleForBorder());
      }
    }
Пример #20
0
  @Override
  public void afterStep(
      TestCaseRunner testRunner, TestCaseRunContext runContext, TestStepResult result) {
    super.afterStep(testRunner, runContext, result);
    TestStep currentStep = runContext.getCurrentStep();

    if (currentStep instanceof Assertable) {
      Assertable requestStep = (Assertable) currentStep;
      for (int c = 0; c < requestStep.getAssertionCount(); c++) {
        TestAssertion assertion = requestStep.getAssertionAt(c);
        log.info("Assertion [" + assertion.getName() + "] has status " + assertion.getStatus());
        if (assertion.getStatus() == AssertionStatus.FAILED) {
          for (AssertionError error : assertion.getErrors()) {
            log.error("ASSERTION FAILED -> " + error.getMessage());
          }

          assertions.add(assertion);
          assertionResults.put(assertion, (WsdlTestStepResult) result);
        }

        testAssertionCount++;
      }
    }

    String countPropertyName = currentStep.getName() + " run count";
    Long count = (Long) runContext.getProperty(countPropertyName);
    if (count == null) {
      count = new Long(0);
    }

    runContext.setProperty(countPropertyName, new Long(count.longValue() + 1));

    if (result.getStatus() == TestStepStatus.FAILED || exportAll) {
      try {
        String exportSeparator = System.getProperty(SOAPUI_EXPORT_SEPARATOR, "-");

        TestCase tc = currentStep.getTestCase();
        String nameBase =
            StringUtils.createFileName(tc.getTestSuite().getName(), '_')
                + exportSeparator
                + StringUtils.createFileName(tc.getName(), '_')
                + exportSeparator
                + StringUtils.createFileName(currentStep.getName(), '_')
                + "-"
                + count.longValue()
                + "-"
                + result.getStatus();

        WsdlTestCaseRunner callingTestCaseRunner =
            (WsdlTestCaseRunner) runContext.getProperty("#CallingTestCaseRunner#");

        if (callingTestCaseRunner != null) {
          WsdlTestCase ctc = callingTestCaseRunner.getTestCase();
          WsdlRunTestCaseTestStep runTestCaseTestStep =
              (WsdlRunTestCaseTestStep) runContext.getProperty("#CallingRunTestCaseStep#");

          nameBase =
              StringUtils.createFileName(ctc.getTestSuite().getName(), '_')
                  + exportSeparator
                  + StringUtils.createFileName(ctc.getName(), '_')
                  + exportSeparator
                  + StringUtils.createFileName(runTestCaseTestStep.getName(), '_')
                  + exportSeparator
                  + StringUtils.createFileName(tc.getTestSuite().getName(), '_')
                  + exportSeparator
                  + StringUtils.createFileName(tc.getName(), '_')
                  + exportSeparator
                  + StringUtils.createFileName(currentStep.getName(), '_')
                  + "-"
                  + count.longValue()
                  + "-"
                  + result.getStatus();
        }

        String absoluteOutputFolder = getAbsoluteOutputFolder(ModelSupport.getModelItemProject(tc));
        String fileName = absoluteOutputFolder + File.separator + nameBase + ".txt";

        if (result.getStatus() == TestStepStatus.FAILED) {
          log.error(currentStep.getName() + " failed, exporting to [" + fileName + "]");
        }

        new File(fileName).getParentFile().mkdirs();

        PrintWriter writer = new PrintWriter(fileName);
        result.writeTo(writer);
        writer.close();

        // write attachments
        if (result instanceof MessageExchange) {
          Attachment[] attachments = ((MessageExchange) result).getResponseAttachments();
          if (attachments != null && attachments.length > 0) {
            for (int c = 0; c < attachments.length; c++) {
              fileName = nameBase + "-attachment-" + (c + 1) + ".";

              Attachment attachment = attachments[c];
              String contentType = attachment.getContentType();
              if (!"application/octet-stream".equals(contentType)
                  && contentType != null
                  && contentType.indexOf('/') != -1) {
                fileName += contentType.substring(contentType.lastIndexOf('/') + 1);
              } else {
                fileName += "dat";
              }

              fileName = absoluteOutputFolder + File.separator + fileName;

              FileOutputStream outFile = new FileOutputStream(fileName);
              Tools.writeAll(outFile, attachment.getInputStream());
              outFile.close();
            }
          }
        }

        exportCount++;
      } catch (Exception e) {
        log.error("Error saving failed result: " + e, e);
      }
    }

    testStepCount++;
  }