/* +----------------------------------------------------------------------+ | Class: CLauncher | | | | Developper: Eric Gavaldo (eric.gavaldo@xqual.com) | | Version: 1.3 | +----------------------------------------------------------------------+ */ package com.xqual.xlauncher.random; 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 = "{random } "; // parameters impacting executing at run time set by the test operator private int maxTestcaseDelay; private boolean preRunAndPostRunTakeTime; private int preRunDelay; private int postRunDelay; Vector attributes = null; // +==============================================================+ // | 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 maxTestcaseDelay = getIntegerParamValue("Timing", "max 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 + "]..."); this.attributes = attributes; 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) { long rand; traceln(LOG_PRIORITY_INFO, "run testId=" + testId + " testPath=" + testPath + " [" + testName + "] testcaseIndex=" + testcaseIndex + "..."); // retrieve the static and dynamic attributes of the current test /* try { Vector listOfNumbers = getIntegerAttributeValues(attributes, "list_of_numbers"); Vector listOfStrings = getStringAttributeValues(attributes, "list_of_strings"); traceln(LOG_PRIORITY_INFO, "list of numbers dynamically passed by the operator " + listOfNumbers); traceln(LOG_PRIORITY_INFO, "list of strings dynamically passed by the operator " + listOfStrings); } catch (CAttributeParsingException e1) { e1.printStackTrace(); } */ // simulate time spending rand = Math.round(Math.random()*maxTestcaseDelay); // from 0 to maxTestcaseDelay CUtils.sleep(100 + rand); // simulate different type of results rand = Math.round(Math.random()*3); // from 0 to 3 short result = (short)rand; Vector executionSteps = new Vector(); executionSteps.add(new CExecutionStep(result, "operation result: " + CUtils.resultToUserString(result))); return new CReturnStatus(result, 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); } }