示例#1
0
  /**
   * get the current sut file<br>
   *
   * @param needToOpenSUTCombo if True and sut is not found, opens a comboBox of suts NOTE: if the
   *     runner was closed, do not use true!
   * @return
   */
  public File getSutFile(boolean needToOpenSUTCombo) {
    String sutFileName =
        JSystemProperties.getInstance().getPreference(FrameworkOptions.USED_SUT_FILE);
    File sutDirectory = getSutDirectory();
    File sutFile;
    if (StringUtils.isEmpty(
        sutFileName)) { // patch in case the entry was deleted only in the current
                        // jsystem.properties file
      JSystemProperties.getInstance().restoreFromBackup();
      sutFileName = JSystemProperties.getInstance().getPreference(FrameworkOptions.USED_SUT_FILE);
    }
    if (!StringUtils.isEmpty(sutFileName)) {
      File _sutFileName = new File(sutFileName);
      if (_sutFileName.exists()) {
        return _sutFileName;
      }
      sutFile = new File(sutDirectory, sutFileName);
      if (sutFile.exists() && sutFile.isFile()) {
        return sutFile;
      }
      log.warning("Can't find sut file: " + sutFile.getPath());
    }

    Vector<String> v = getOptionalSuts();
    if (v.size() == 0 || (v.size() == 1 && CREATE_A_NEW_SUT_FILE.equals(v.get(0)))) {
      try {
        return createDefaultSUT();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    sutFileName = null;
    if (needToOpenSUTCombo && !getSuppressGUI()) {
      sutFileName =
          (String)
              JOptionPane.showInputDialog(
                  TestRunnerFrame.guiMainFrame,
                  "Select SUT File from list",
                  "Select SUT",
                  JOptionPane.INFORMATION_MESSAGE,
                  null,
                  v.toArray(),
                  v.elementAt(0));
    }

    if (sutFileName == null) {
      try {
        return createDefaultSUT();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }

    return new File(sutDirectory, sutFileName);
  }
 public boolean getRunOnStart() {
   Properties p = loadProps();
   String val = p.getProperty(RUN_ON_START);
   if (StringUtils.isEmpty(val)) {
     return false;
   }
   return Boolean.parseBoolean(val);
 }
 public int getActiveTestIndex() {
   Properties p = loadProps();
   String val = p.getProperty(TEST_INDEX);
   if (StringUtils.isEmpty(val)) {
     return -1;
   }
   return Integer.parseInt(val);
 }
 public boolean getLoadReporters() {
   Properties p = loadProps();
   String val = p.getProperty(LOAD_REPORTERS_STATE);
   if (StringUtils.isEmpty(val)) {
     return false;
   }
   return Boolean.parseBoolean(val);
 }
示例#5
0
 /**
  * Get a getter method for this member
  *
  * @return a getter method
  */
 public Method getGetter() {
   Method m = new Method();
   m.setAccess(Access.PUBLIC);
   m.setJavadoc("get the " + name);
   m.setMethodName("get" + StringUtils.firstCharToUpper(name));
   m.setMethodCode("return " + name + ";");
   m.setReturnType(type);
   m.setThrowsName(null);
   m.setReturnArray(isArray);
   return m;
 }
示例#6
0
 /**
  * Get a setter method for this member
  *
  * @return a setter method
  */
 public Method getSetter() {
   Method m = new Method();
   m.setAccess(Access.PUBLIC);
   m.setJavadoc("set the " + name);
   m.setMethodName("set" + StringUtils.firstCharToUpper(name));
   m.setMethodCode("this." + name + " = " + name + ";");
   m.addParameter(this);
   m.setReturnType("void");
   m.setThrowsName(null);
   // m.setReturnArray(isArray);
   return m;
 }
  public void setEnabledTests(int[] selectedTests) {
    Properties p = loadProps();
    if (selectedTests == null) {
      p.remove(SELECTED_TESTS);
    } else {
      String[] res = new String[selectedTests.length];
      for (int i = 0; i < selectedTests.length; i++) {
        res[i] = Integer.toString(selectedTests[i]);
      }

      String selectedTestsString = StringUtils.objectArrayToString(",", (Object[]) res);
      p.setProperty(SELECTED_TESTS, selectedTestsString);
    }
    saveProps(p);
  }
 public int[] getEnabledTests(boolean reset) {
   Properties p = loadProps();
   String val = p.getProperty(SELECTED_TESTS);
   if (reset) {
     setEnabledTests(null);
   }
   if (val == null) {
     return null;
   }
   String[] resTmp = StringUtils.split(val, ",");
   int[] res = new int[resTmp.length];
   for (int i = 0; i < resTmp.length; i++) {
     res[i] = Integer.parseInt(resTmp[i]);
   }
   return res;
 }
示例#9
0
  public void execute() throws MojoExecutionException, MojoFailureException {
    if (null == scenario) {
      getLog().error("Please specify a valid scenario name. Scenario can't be " + scenario);
      throw new MojoExecutionException(
          "Please specify a valid scenario name. Scenario can't be " + scenario);
    }
    if (null == sut) {
      getLog().error("Please specify a valid sut name. Sut can't be " + sut);
      throw new MojoExecutionException("Please specify a valid sut name. Sut can't be " + sut);
    }

    getLog().info("Changing user working dir to: " + mavenProject.getBasedir().getAbsolutePath());
    // This line is for setting the current folder to the project root
    // folder. This is very important if we want to run the plug-in from the
    // parent folder.
    System.setProperty("user.dir", mavenProject.getBasedir().getAbsolutePath());

    final File scenariosPath = new File(mavenProject.getBasedir(), SCENARIO_PATH);
    // Collect parameters that are required for the execution
    if (!StringUtils.isEmpty(xmlFile)) {
      xmlFileToParameters();
    }

    final File[] sutFilesArr = sutParameterToFileArray();
    final File[] scenarioFilesArr = scenarioParameterToFileArray(scenariosPath);

    // Check input correction
    if (sutFilesArr == null
        || sutFilesArr.length == 0
        || scenarioFilesArr == null
        || scenarioFilesArr.length == 0) {
      throw new MojoFailureException("Sut or scenario parameters was not specified");
    }

    if (sutFilesArr.length != scenarioFilesArr.length) {
      throw new MojoFailureException(
          "Number of scenarios must be equals to the number of sut files");
    }

    try {
      // This file is mandatory for scenario execution
      createEmptyTestPropertiesFile(scenariosPath);
    } catch (IOException e) {
      getLog().error("Failed to create new empty scenario properties file");
      getLog().error(e);
      throw new MojoFailureException("Failed to create new empty scenario properties file");
    }

    getLog().info("--------------------------Jsystem Maven Plugin--------------------------");
    getLog().info("About to execute scenarios " + scenario + " with sut files " + sut);
    getLog().info("of project=" + mavenProject.getBasedir());
    getLog().info("------------------------------------------------------------------------");

    for (int i = 0; i < scenarioFilesArr.length; i++) {
      if (!scenarioFilesArr[i].exists()) {
        throw new MojoFailureException("Scenario file " + scenarioFilesArr[i] + " is not exist");
      }
      if (!sutFilesArr[i].exists()) {
        throw new MojoFailureException("Sut file " + sutFilesArr[i] + " is not exist");
      }
      String scenarioName = scenario.split(DELIMITER)[i];
      if (!scenarioName.startsWith("scenarios/")) {
        scenarioName = "scenarios/" + scenarioName;
      }
      final Project p =
          createNewAntProject(
              scenariosPath, scenarioFilesArr[i], scenarioName, sut.split(DELIMITER)[i]);

      updateJSystemProperties(
          sutFilesArr[i], sut.split(DELIMITER)[i], scenarioFilesArr[i], scenarioName);
      executeSingleScenario(scenarioFilesArr[i], p);
    }
    getLog().info("------------------------------------------------------------------------");
    getLog().info("Execution of scenarios " + scenario + " ended ");
    getLog()
        .info(
            "Reports can be found in "
                + mavenProject.getBasedir().getAbsolutePath()
                + File.separator
                + "log"
                + File.separator
                + "current");
  }