// handle optional config file name
if ((pArgs.length != 0) && (pArgs.length != 2) && (pArgs.length != 4) && (pArgs.length != 6) && (pArgs.length != 8)) {
showUsage();
}
GUIConfiguration guiConfiguration = GUIConfiguration.getInstance();
boolean testBedArgumentPresent = false;
String testSuiteDir = null;
int numberLoops = 1;
boolean loopsInHours = false;
// String sutVersion = null;
for (int i = 0; i < pArgs.length; i = i + 2) {
if (pArgs[i].equals("-testsuite")) {
LOGGER.info("Using " + pArgs[i + 1] + " as test suite directory");
testSuiteDir = pArgs[i + 1];
} else if (pArgs[i].equals("-testbed")) {
String testbedFileName = pArgs[i + 1];
LOGGER.info("Using " + testbedFileName + " as testbed configuration file");
TestBedConfiguration.setConfigFile(testbedFileName);
// save testbed
testbedFileName = new File(testbedFileName).getName();
String testbed = testbedFileName.substring(0, testbedFileName.lastIndexOf('.'));
guiConfiguration.setProperty(StaticConfiguration.LAST_SELECTED_TESTBED_PROPERTY, testbed);
testBedArgumentPresent = true;
} else if (pArgs[i].equals("-engine")) {
LOGGER.info("Using " + pArgs[i + 1] + " as engine configuration file");
TestEngineConfiguration.setConfigFile(pArgs[i + 1]);
} else if (pArgs[i].equals("-loop")) {
// String message = "Running test suite in loop";
numberLoops = -1;
if ((i + 1 < pArgs.length)) {
// more arguments, check if next argument is a loop argument
if (pArgs[i + 1].startsWith("-")) {
i++;
} else {
String countOrHoursStr;
if (pArgs[i + 1].endsWith("h")) {
loopsInHours = true;
countOrHoursStr = pArgs[i + 1].substring(0, pArgs[i + 1].length() - 1);
} else {
loopsInHours = false;
countOrHoursStr = pArgs[i + 1];
}
try {
numberLoops = Integer.parseInt(countOrHoursStr);
if (numberLoops <= 0) {
throw new NumberFormatException();
}
// message += (loopsInHours ? " during " : " ") + numberLoops + " " + (loopsInHours ? "hour" : "time") + (numberLoops > 1 ? "s" : "");
i += 2;
} catch (NumberFormatException e) {
showUsage();
}
}
}
} else if (pArgs[i].equals("-sutversion") && (i + 1 < pArgs.length)) {
LOGGER.info("Using " + pArgs[i + 1] + " as sutversion");
TestBedConfiguration.setSUTVersion(pArgs[i + 1]);
i += 2;
} else {
// no more arguments
i++;
}
}
if (!testBedArgumentPresent) {
String lastSelectedTestbed = guiConfiguration.getString(StaticConfiguration.LAST_SELECTED_TESTBED_PROPERTY, "default");
String testbedConfigFileName = StaticConfiguration.TESTBED_CONFIG_DIRECTORY + "/" + lastSelectedTestbed + "." + StaticConfiguration.TESTBED_CONFIG_FILE_EXTENSION;
if (!new File(testbedConfigFileName).exists()) {
// if last selected testbed doesn't exist use the first one found
File[] testbedConfigFiles = FileUtilities.listSortedFiles(new File(StaticConfiguration.TESTBED_CONFIG_DIRECTORY),new FileFilter() {
public boolean accept(File pathname) {
return pathname.getName().toLowerCase().endsWith(".xml");
}
});
if (testbedConfigFiles == null) {
throw new RuntimeException("Testbed configuration directory (" + StaticConfiguration.TESTBED_CONFIG_DIRECTORY + ") not found.");
}
if (testbedConfigFiles.length > 0) {
testbedConfigFileName = testbedConfigFiles[0].getCanonicalPath();
// save testbed
final String testbedFileName = testbedConfigFiles[0].getName();
guiConfiguration.setProperty(StaticConfiguration.LAST_SELECTED_TESTBED_PROPERTY, testbedFileName.substring(0, testbedFileName.lastIndexOf('.')));
} else {
throw new RuntimeException("No testbed config file available.");
}
}
TestBedConfiguration.setConfigFile(testbedConfigFileName);