/* +----------------------------------------------------------------------+ | Class: CLauncher | | | | Developper: Eric Gavaldo (egavaldo@xqual.com) | | YehudaM (exe -> XML/ResultsRead) | | YehudaM (exe -> OffLine/ResultsRead) | | YehudaM (parse results) | | YehudaM (Attributes) | | YehudaM (NOT_EXECUTED) | | YehudaM (testId) | | Version: 1.9 | +----------------------------------------------------------------------+ */ package com.xqual.xlauncher.offline; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; 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.xagent.launcher.runner.CRunner; import com.xqual.xagent.launcher.runner.IRunner; import com.xqual.xcommon.CAttribute; import com.xqual.xcommon.IConstantsResults; /** * The CLauncherImpl implementation of ILauncher for Executables. * @author egavaldo */ public class CLauncherImpl extends CLauncher implements IConstantsResults { // +==============================================================+ // | Attributes | // +==============================================================+ static final String TRACE_HEADER = "{offline } "; // parameters impacting executing at run time set by the test operator private String testRootPath; private String testFileName; private File workingDir; private String attribs[][]; // +==============================================================+ // | Constructors | // +==============================================================+ public CLauncherImpl() { super(TRACE_HEADER); } // +==============================================================+ // | Methods | // +==============================================================+ @Override public CReturnStatus initialize(int sutId, String sutName, String sutVersion) { setSutDetails(sutId, sutName, sutVersion); // check the configuration sent by the manager printConfiguration(); Vector executionSteps = new Vector(); try { // retrieve the parameters we need testRootPath = getStringParamValue("General", "Test root path"); testFileName = getStringParamValue("General", "Result file name"); } catch (CParamParsingException e) { traceln(LOG_PRIORITY_SEVERE, "parsing error during initialization"); executionSteps.add(new CExecutionStep(RESULT_FAILURE, "Exception during initialize: " + e.getMessage())); return new CReturnStatus(RESULT_FAILURE, executionSteps); } return new CReturnStatus(RESULT_SUCCESS, 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 + "]..."); traceln(LOG_PRIORITY_INFO, "preRun (ver 1.9) Attributes=" + attributes.size() + " testPath=" + testPath + " [" + testName + "]..."); attribs = new String[attributes.size()][2]; for (int i=0; i executionSteps = new Vector(); executionSteps.add(new CExecutionStep(RESULT_SUCCESS, "postRun: succeeded")); return new CReturnStatus(RESULT_SUCCESS, executionSteps); } @Override public CReturnStatus terminate() { Vector executionSteps = new Vector(); executionSteps.add(new CExecutionStep(RESULT_SUCCESS, "Terminate")); return new CReturnStatus(RESULT_SUCCESS, executionSteps); } // +--------------------------+ // ¦ Utilities ¦ // +--------------------------+ private CReturnStatus parseResultFile(Vector executionSteps) { // parse the result file to get the result and the execution steps File resultFile = new File(workingDir + "/log.txt"); if (!resultFile.exists()) { traceln(LOG_PRIORITY_SEVERE, "Result file not found!"); executionSteps.add(new CExecutionStep(RESULT_FAILURE, "run: result file not found!")); return new CReturnStatus(RESULT_FAILURE, executionSteps); } else { //executionSteps.add(new CExecutionStep(RESULT_SUCCESS, "run: result file found")); } String line, message; boolean failDetected = false; boolean passDetected = false; try { FileInputStream fileInputStream = new FileInputStream(resultFile); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream)); while ((line = bufferedReader.readLine()) != null) { line = line.trim(); System.out.println(">" + line); if (line.indexOf("[Success]")>=0) { message = line.substring(10, line.length()); // [Success] length = 9 executionSteps.add(new CExecutionStep(RESULT_SUCCESS, message)); passDetected = true; } else if (line.indexOf("[Failure]")>=0) { message = line.substring(10, line.length()); executionSteps.add(new CExecutionStep(RESULT_FAILURE, message)); failDetected = true; } else if (line.indexOf("[Log]")>=0) { message = line.substring(6, line.length()); executionSteps.add(new CExecutionStep(RESULT_UNKNOWN, message)); // no pass or fail change } else { //traceln(LOG_PRIORITY_SEVERE, "unknown tag!"); } } } catch (Exception e) { traceln(LOG_PRIORITY_SEVERE, "exception whle parsing the result file: " + e); executionSteps.add(new CExecutionStep(RESULT_FAILURE, "Exception whle parsing the result file: " + e)); failDetected = true; } if (failDetected) { return new CReturnStatus(RESULT_FAILURE, executionSteps); } else { if (passDetected) { return new CReturnStatus(RESULT_SUCCESS, executionSteps); } else { return new CReturnStatus(RESULT_NOT_EXECUTED, executionSteps); } } } }