/*
+----------------------------------------------------------------------+
| Class: CLauncher |
| |
| Developper: Eric Gavaldo (eric.gavaldo@xqual.com) |
| Version: 1.2 |
+----------------------------------------------------------------------+
*/
package com.xqual.xlauncher.success;
import java.util.Vector;
import com.xqual.xagent.launcher.CExecutionStep;
import com.xqual.xagent.launcher.CLauncher;
import com.xqual.xagent.launcher.CParamParsingException;
import com.xqual.xagent.launcher.CReturnStatus;
import com.xqual.xcommon.CAttribute;
import com.xqual.xcommon.IConstantsResults;
import com.xqual.xcommon.utils.CUtils;
/**
* The CLauncherImpl implementation of ILauncher for a fake launcher.
* @author egavaldo
*/
public class CLauncherImpl extends CLauncher implements IConstantsResults {
// +==============================================================+
// | Attributes |
// +==============================================================+
static final String TRACE_HEADER = "{succcess } ";
// parameters impacting executing at run time set by the test operator
private int testcaseDelay;
private boolean preRunAndPostRunTakeTime;
private int preRunDelay;
private int postRunDelay;
// +==============================================================+
// | Constructors |
// +==============================================================+
public CLauncherImpl() {
super(TRACE_HEADER);
}
// +==============================================================+
// | Methods |
// +==============================================================+
@Override
public CReturnStatus initialize(int sutId, String sutName, String sutVersion) {
// check the configuration sent by the manager
printConfiguration();
try {
// retrieve the parameters we need
testcaseDelay = getIntegerParamValue("Timing", "time between testcases (ms)");
preRunAndPostRunTakeTime = getBooleanParamValue("Timing", "prerun and postrun take time to execute");
preRunDelay = getIntegerParamValue("Timing", "time to execute prerun (ms)");
postRunDelay = getIntegerParamValue("Timing", "time to execute postrun (ms)");
return new CReturnStatus(RESULT_SUCCESS, null);
} catch (CParamParsingException e) {
traceln(LOG_PRIORITY_SEVERE, "parsing error during initialization");
Vector executionSteps = new Vector();
executionSteps.add(new CExecutionStep(RESULT_FAILURE, e.getMessage()));
return new CReturnStatus(RESULT_FAILURE, executionSteps);
}
}
@Override
public CReturnStatus preRun(int testId, String testPath, String testName, Vector attributes, String additionalInfo) {
traceln(LOG_PRIORITY_INFO, "preRun testId=" + testId + " testPath=" + testPath + " [" + testName + "]...");
printAttributes(attributes);
if (preRunAndPostRunTakeTime) {
CUtils.sleep(preRunDelay);
}
return new CReturnStatus(RESULT_SUCCESS, null);
}
@Override
public CReturnStatus run(int testId, String testPath, String testName, int testcaseIndex, String testcaseName, String additionalInfo) {
traceln(LOG_PRIORITY_INFO, "run testId=" + testId + " testPath=" + testPath + ":" + testName + " testcaseIndex=" + testcaseIndex + "...");
// simulate time spending
CUtils.sleep(testcaseDelay);
Vector executionSteps = new Vector();
executionSteps.add(new CExecutionStep(RESULT_SUCCESS, "\"success\"operation succeeded"));
return new CReturnStatus(RESULT_SUCCESS, executionSteps);
}
@Override
public CReturnStatus postRun(int testId, String testPath, String testName) {
traceln(LOG_PRIORITY_INFO, "postRun testId=" + testId + " testPath=" + testPath + ":" + testName + "...");
if (preRunAndPostRunTakeTime) {
CUtils.sleep(postRunDelay);
}
return new CReturnStatus(RESULT_SUCCESS, null);
}
@Override
public CReturnStatus terminate() {
return new CReturnStatus(RESULT_SUCCESS, null);
}
}