/** * 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); }
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"); }