@Override
  public boolean dependsOn(ModelItem modelItem) {
    WsdlRunTestCaseTestStep callStep = getModelItem();

    return modelItem == callStep
        || modelItem == callStep.getTestCase()
        || modelItem == callStep.getTestCase().getTestSuite()
        || modelItem == callStep.getTestCase().getTestSuite().getProject();
  }
  public boolean resolve() {
    WsdlTestCase tCase = testStep.getTestCase().getTestSuite().addNewTestCase("New Test Case");
    testStep.setTargetTestCase(tCase);
    resolved = true;

    Analytics.trackAction(SoapUIActions.CREATE_TEST_CASE.getActionName());

    return resolved;
  }
 public void afterStep(
     TestCaseRunner testRunner, TestCaseRunContext runContext, TestStepResult result) {
   TestStep currentStep = runContext.getCurrentStep();
   if (currentStep instanceof WsdlRunTestCaseTestStep) {
     ((WsdlRunTestCaseTestStep) currentStep).removeTestRunListener(this);
   }
 }
  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));
  }
 public void beforeStep(
     TestCaseRunner testRunner, TestCaseRunContext runContext, TestStep currentStep) {
   if (currentStep instanceof HttpRequestTestStep) {
     prepareRequestStep((HttpRequestTestStep) currentStep);
   } else if (currentStep instanceof WsdlRunTestCaseTestStep) {
     ((WsdlRunTestCaseTestStep) currentStep).addTestRunListener(this);
   }
 }
  @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++;
  }