/*
+----------------------------------------------------------------------+
| Class: CLauncherImpl |
| |
| Developper: Eric Gavaldo (eric.gavaldo@xqual.com) |
| Version: 1.3 |
+----------------------------------------------------------------------+
*/
package com.xqual.xlauncher.testpartner;
import java.io.File;
import java.util.Vector;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
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.CXmlDocumentFactory;
import com.xqual.xcommon.IConstantsResults;
import com.xqual.xcommon.utils.CFileUtils;
/**
* The CLauncherImpl implementation of ILauncher for Compuware TestPartner.
* The command line interface is as following:
* C:\Program Files\TestPartner\tc.exe -d -u -p -r -s
* * @author egavaldo
*/
public class CLauncherImpl extends CLauncher implements IConstantsResults {
// +==============================================================+
// | Attributes |
// +==============================================================+
static final String TRACE_HEADER = "{test_partner } ";
// parameters impacting executing at run time set by the test operator
private String testRootPath;
private String projectName;
private String username;
private String password;
private String dsn;
private String detailedLogPath;
// +==============================================================+
// | Constructors |
// +==============================================================+
public CLauncherImpl() {
super(TRACE_HEADER);
}
// +==============================================================+
// | Methods |
// +==============================================================+
@Override
public CReturnStatus initialize(int sutId, String sutName, String sutVersion) {
setDefaultTestcaseMustBeCreated(true); // if there is not testcase, let the systems create a default one
// check the configuration sent by the manager
printConfiguration();
try {
// retrieve the parameters we need
testRootPath = getStringParamValue("TestPartner", "testRootPath");
projectName = getStringParamValue("TestPartner", "projectName");
username = getStringParamValue("TestPartner", "username");
password = getStringParamValue("TestPartner", "password");
dsn = getStringParamValue("TestPartner", "dsn");
detailedLogPath = getStringParamValue("TestPartner", "detailedLogPath");
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);
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 + "...");
// +------------------------------------+
// | run the test partner script |
// +------------------------------------+
CRunner testPartnerRunner = new CRunner("[" + testId + "] "+ testPath + ":" + testName + "." + testcaseIndex,
CFileUtils.quoteFilePath("C:/Program Files/TestPartner/tc.exe") + " -d " + dsn + " -u " + username + " -p " + password + " -r " + projectName + " -s " + testRootPath + "/" + testName);
short result = testPartnerRunner.requestAction(IRunner.START_PROCESS, IRunner.WAIT_END_OF_EXECUTION);
addAttachment(new File(detailedLogPath));
return parseResultFile(new File(detailedLogPath));
}
@Override
public CReturnStatus postRun(int testId, String testPath, String testName) {
traceln(LOG_PRIORITY_INFO, "postRun testId=" + testId + " testPath=" + testPath + ":" + testName + "...");
return new CReturnStatus(RESULT_SUCCESS, null);
}
@Override
public CReturnStatus terminate() {
return new CReturnStatus(RESULT_SUCCESS, null);
}
// +--------------------------+
// ¦ Utilities ¦
// +--------------------------+
private CReturnStatus parseResultFile(File resultFile) {
Vector executionSteps = new Vector();
// parse the result file to get the result and the execution steps
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"));
}
boolean errorDetected = false;
Document xmlDocument = CXmlDocumentFactory.createXMLDoc(resultFile);
NodeList nodeList = CXmlDocumentFactory.getNodeObjListFromXPath(xmlDocument, "ExternalReferenceModel/Execution/ResultObject");
for (int i=0; i