示例#1
0
  /**
   * Creates project copy and save it in temporary directory. Set copy's project path and resource
   * root to ${projectDir}
   *
   * @return
   * @throws IOException
   * @throws SoapUIException
   * @throws XmlException
   */
  private boolean createProjectCopy() throws IOException, XmlException, SoapUIException {
    project.saveIn(new File(tmpDir, project.getName() + "-soapui-project.xml"));

    projectCopy =
        (WsdlProject)
            ProjectFactoryRegistry.getProjectFactory("wsdl")
                .createNew(
                    new File(tmpDir, project.getName() + "-soapui-project.xml")
                        .getAbsolutePath()); // new WsdlProject( new File( tmpDir, project.getName()
                                             // + ".xml" ).getAbsolutePath() );

    return projectCopy != null;
  }
  @Override
  protected boolean runRunner() throws Exception {
    WsdlProject project =
        (WsdlProject)
            ProjectFactoryRegistry.getProjectFactory("wsdl")
                .createNew(getProjectFile(), getProjectPassword());

    String pFile = getProjectFile();

    project.getSettings().setString(ProjectSettings.SHADOW_PASSWORD, null);

    File tmpProjectFile = new File(System.getProperty("java.io.tmpdir"));
    tmpProjectFile = new File(tmpProjectFile, project.getName() + "-project.xml");

    project.beforeSave();
    project.saveIn(tmpProjectFile);

    pFile = tmpProjectFile.getAbsolutePath();

    String endpoint = StringUtils.hasContent(localEndpoint) ? localEndpoint : project.getName();

    log.info("Creating WAR file with endpoint [" + endpoint + "]");

    MockAsWar mockAsWar =
        new MockAsWar(
            pFile,
            getSettingsFile(),
            getOutputFolder(),
            warFile,
            includeLibraries,
            includeActions,
            includeListeners,
            endpoint,
            enableWebUI,
            project);

    mockAsWar.createMockAsWarArchive();
    log.info("WAR Generation complete");
    return true;
  }
  protected void runProject(WsdlProject project) {
    // add listener for counting..
    InternalProjectRunListener projectRunListener = new InternalProjectRunListener();
    project.addProjectRunListener(projectRunListener);

    try {
      log.info(("Running Project [" + project.getName() + "], runType = " + project.getRunType()));
      WsdlProjectRunner runner = project.run(new StringToObjectMap(), false);
      log.info(
          "Project ["
              + project.getName()
              + "] finished with status ["
              + runner.getStatus()
              + "] in "
              + runner.getTimeTaken()
              + "ms");
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      project.removeProjectRunListener(projectRunListener);
    }
  }
示例#4
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
  public boolean runRunner() throws Exception {
    AnalyticsHelper.initializeAnalytics();
    Analytics.trackSessionStart();

    initGroovyLog();

    assertions.clear();

    String projectFile = getProjectFile();

    WsdlProject project =
        (WsdlProject)
            ProjectFactoryRegistry.getProjectFactory("wsdl")
                .createNew(projectFile, getProjectPassword());

    if (project.isDisabled()) {
      throw new Exception("Failed to load SoapUI project file [" + projectFile + "]");
    }

    initProject(project);
    ensureOutputFolder(project);

    if (this.printAlertSiteReport) {
      testCaseRunLogReport = new TestCaseRunLogReport(getAbsoluteOutputFolder(project));
    }

    log.info("Running SoapUI tests in project [" + project.getName() + "]");

    long startTime = System.nanoTime();

    List<TestCase> testCasesToRun = new ArrayList<TestCase>();

    // validate testSuite argument
    if (testSuite != null && project.getTestSuiteByName(testSuite) == null) {
      throw new Exception(
          "TestSuite with name ["
              + testSuite
              + "] is missing in Project ["
              + project.getName()
              + "]");
    }

    // start by listening to all testcases.. (since one testcase can call
    // another)
    for (int c = 0; c < project.getTestSuiteCount(); c++) {
      TestSuite suite = project.getTestSuiteAt(c);
      for (int i = 0; i < suite.getTestCaseCount(); i++) {
        TestCase tc = suite.getTestCaseAt(i);
        if ((testSuite == null || suite.getName().equals(testSuite))
            && testCase != null
            && tc.getName().equals(testCase)) {
          testCasesToRun.add(tc);
        }

        addListeners(tc);
      }
    }

    try {
      // validate testSuite argument
      if (testCase != null && testCasesToRun.size() == 0) {
        if (testSuite == null) {
          throw new Exception(
              "TestCase with name ["
                  + testCase
                  + "] is missing in Project ["
                  + project.getName()
                  + "]");
        } else {
          throw new Exception(
              "TestCase with name ["
                  + testCase
                  + "] in TestSuite ["
                  + testSuite
                  + "] is missing in Project ["
                  + project.getName()
                  + "]");
        }
      }

      // decide what to run
      if (testCasesToRun.size() > 0) {
        for (TestCase testCase : testCasesToRun) {
          runTestCase((WsdlTestCase) testCase);
        }
      } else if (testSuite != null) {
        WsdlTestSuite ts = project.getTestSuiteByName(testSuite);
        if (ts == null) {
          throw new Exception("TestSuite with name [" + testSuite + "] not found in project");
        } else {
          runSuite(ts);
        }
      } else {
        runProject(project);
      }

      long timeTaken = (System.nanoTime() - startTime) / 1000000;

      if (printReport) {
        printReport(timeTaken);
      }

      exportReports(project);

      if (saveAfterRun && !project.isRemote()) {
        try {
          project.save();
        } catch (Throwable t) {
          log.error("Failed to save project", t);
        }
      }

      if ((assertions.size() > 0 || failedTests.size() > 0) && !ignoreErrors) {
        throwFailureException();
      }

      return true;
    } finally {
      for (int c = 0; c < project.getTestSuiteCount(); c++) {
        TestSuite suite = project.getTestSuiteAt(c);
        for (int i = 0; i < suite.getTestCaseCount(); i++) {
          TestCase tc = suite.getTestCaseAt(i);
          removeListeners(tc);
        }
      }
    }
  }