use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class RecorderService method recordExecutionInformationAfterStepActionandControl.
@Override
public List<TestCaseExecutionFile> recordExecutionInformationAfterStepActionandControl(TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution) {
List<TestCaseExecutionFile> objectFileList = new ArrayList<TestCaseExecutionFile>();
TestCaseExecutionFile objectFile = null;
// Used for logging purposes
String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
TestCaseExecution myExecution;
boolean doScreenshot;
boolean getPageSource;
String applicationType;
String returnCode;
Integer controlNumber = 0;
if (testCaseStepActionControlExecution == null) {
myExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();
doScreenshot = testCaseStepActionExecution.getActionResultMessage().isDoScreenshot();
getPageSource = testCaseStepActionExecution.getActionResultMessage().isGetPageSource();
applicationType = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType();
returnCode = testCaseStepActionExecution.getReturnCode();
} else {
myExecution = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution();
doScreenshot = testCaseStepActionControlExecution.getControlResultMessage().isDoScreenshot();
getPageSource = testCaseStepActionControlExecution.getControlResultMessage().isGetPageSource();
applicationType = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution().getApplicationObj().getType();
returnCode = testCaseStepActionControlExecution.getReturnCode();
controlNumber = testCaseStepActionControlExecution.getControlSequence();
}
/**
* SCREENSHOT Management. Screenshot only done when : screenshot
* parameter is eq to 2 or screenshot parameter is eq to 1 with the
* correct doScreenshot flag on the last action MessageEvent.
*/
if ((myExecution.getScreenshot() == 2) || ((myExecution.getScreenshot() == 1) && (doScreenshot))) {
if (applicationType.equals(Application.TYPE_GUI) || applicationType.equals(Application.TYPE_APK) || applicationType.equals(Application.TYPE_IPA) || applicationType.equals(Application.TYPE_FAT)) {
/**
* Only if the return code is not equal to Cancel, meaning lost
* connectivity with selenium.
*/
if (!returnCode.equals("CA")) {
objectFile = this.recordScreenshot(myExecution, testCaseStepActionExecution, controlNumber);
if (objectFile != null) {
objectFileList.add(objectFile);
}
} else {
LOG.debug(logPrefix + "Not Doing screenshot because connectivity with selenium server lost.");
}
}
} else {
LOG.debug(logPrefix + "Not Doing screenshot because of the screenshot parameter or flag on the last Action result.");
}
/**
* PAGESOURCE management. Get PageSource if requested by the last Action
* MessageEvent.
*/
if ((myExecution.getPageSource() == 2) || ((myExecution.getPageSource() == 1) && (getPageSource))) {
if (applicationType.equals(Application.TYPE_GUI) || applicationType.equals(Application.TYPE_APK) || applicationType.equals(Application.TYPE_IPA)) {
/**
* Only if the return code is not equal to Cancel, meaning lost
* connectivity with selenium.
*/
if (!returnCode.equals("CA")) {
objectFile = this.recordPageSource(myExecution, testCaseStepActionExecution, controlNumber);
if (objectFile != null) {
objectFileList.add(objectFile);
}
} else {
LOG.debug(logPrefix + "Not Doing screenshot because connectivity with selenium server lost.");
}
}
} else {
LOG.debug(logPrefix + "Not getting page source because of the pageSource parameter or flag on the last Action result.");
}
/**
* Last call XML SOURCE management. Get Source of the XML if requested
* by the last Action or control MessageEvent.
*/
if (applicationType.equals(Application.TYPE_SRV) && ((myExecution.getPageSource() == 2) || ((myExecution.getPageSource() == 1) && (getPageSource)) || (myExecution.getScreenshot() == 2) || ((myExecution.getScreenshot() == 1) && (doScreenshot)))) {
// Record the Request and Response.
AppService se = (AppService) testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getLastServiceCalled();
if (se != null) {
// No Calls were performed previously
List<TestCaseExecutionFile> objectFileSOAPList = new ArrayList<TestCaseExecutionFile>();
objectFileSOAPList = this.recordServiceCall(myExecution, testCaseStepActionExecution, controlNumber, null, se);
if (objectFileSOAPList.isEmpty() != true) {
for (TestCaseExecutionFile testCaseExecutionFile : objectFileSOAPList) {
objectFileList.add(testCaseExecutionFile);
}
}
}
}
return objectFileList;
}
use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class TestCaseExecutionDAO method readByKey.
@Override
public AnswerItem readByKey(long executionId) {
AnswerItem ans = new AnswerItem();
TestCaseExecution result = null;
final String query = "SELECT * FROM `testcaseexecution` exe WHERE exe.`id` = ?";
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setLong(1, executionId);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.first()) {
result = loadFromResultSet(resultSet);
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
ans.setItem(result);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
// sets the message
ans.setResultMessage(msg);
return ans;
}
use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class TestCaseExecutionDAO method loadTestCaseExecutionAndApplicationFromResultSet.
private TestCaseExecution loadTestCaseExecutionAndApplicationFromResultSet(ResultSet resultSet) throws SQLException {
TestCaseExecution testCaseExecution = new TestCaseExecution();
testCaseExecution = this.loadFromResultSet(resultSet);
testCaseExecution.setApplicationObj(applicationDAO.loadFromResultSet(resultSet));
return testCaseExecution;
}
use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class TestCaseExecutionDAO method findLastTestCaseExecutionNotPE.
@Override
public TestCaseExecution findLastTestCaseExecutionNotPE(String test, String testCase) throws CerberusException {
TestCaseExecution result = null;
StringBuilder query = new StringBuilder();
query.append("SELECT exe.* FROM `testcaseexecution` exe ");
query.append(" WHERE Test = ? and TestCase= ? and ID = ");
query.append(" (SELECT MAX(ID) from `testcaseexecution` ");
query.append("WHERE Test= ? and TestCase= ? and ControlStatus!='PE')");
try (Connection connection = this.databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query.toString())) {
preStat.setString(1, test);
preStat.setString(2, testCase);
preStat.setString(3, test);
preStat.setString(4, testCase);
try (ResultSet resultSet = preStat.executeQuery()) {
if (resultSet.first()) {
result = loadFromResultSet(resultSet);
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
}
return result;
}
use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class TestCaseExecutionDAO method readByTagByCriteria.
@Override
public AnswerList readByTagByCriteria(String tag, int start, int amount, String sort, String searchTerm, Map<String, List<String>> individualSearch) throws CerberusException {
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
AnswerList answer = new AnswerList();
List<String> individalColumnSearchValues = new ArrayList<String>();
final StringBuffer query = new StringBuffer();
query.append("SELECT * FROM testcaseexecution exe ");
query.append("left join testcase tec on exe.Test = tec.Test and exe.TestCase = tec.TestCase ");
query.append("left join application app on tec.application = app.application ");
query.append("where exe.ID IN ");
query.append("(select MAX(exe.ID) from testcaseexecution exe ");
query.append("where 1=1 ");
if (!StringUtil.isNullOrEmpty(tag)) {
query.append("and exe.tag = ? ");
}
query.append("group by exe.test, exe.testcase, exe.Environment, exe.Browser, exe.Country) ");
if (!StringUtil.isNullOrEmpty(searchTerm)) {
query.append("and (exe.`test` like ? ");
query.append(" or exe.`testCase` like ? ");
query.append(" or exe.`application` like ? ");
query.append(" or tec.`bugid` like ? ");
query.append(" or tec.`priority` like ? ");
query.append(" or tec.`description` like ? )");
}
if (individualSearch != null && !individualSearch.isEmpty()) {
query.append(" and ( 1=1 ");
for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
query.append(" and ");
query.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));
individalColumnSearchValues.addAll(entry.getValue());
}
query.append(" ) ");
}
if (!StringUtil.isNullOrEmpty(sort)) {
query.append(" order by ").append(sort);
}
if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {
query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);
} else {
query.append(" limit ").append(start).append(" , ").append(amount);
}
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
LOG.debug("SQL.param.tag : " + tag);
}
List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>();
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
int i = 1;
if (!StringUtil.isNullOrEmpty(tag)) {
preStat.setString(i++, tag);
}
if (!Strings.isNullOrEmpty(searchTerm)) {
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
preStat.setString(i++, "%" + searchTerm + "%");
}
for (String individualColumnSearchValue : individalColumnSearchValues) {
preStat.setString(i++, individualColumnSearchValue);
}
try {
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
testCaseExecutionList.add(this.loadWithDependenciesFromResultSet(resultSet));
}
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));
// answer = new AnswerList(testCaseExecutionList, testCaseExecutionList.size());
answer.setTotalRows(testCaseExecutionList.size());
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
testCaseExecutionList = null;
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
testCaseExecutionList = null;
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.warn("Unable to execute query : " + exception.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
testCaseExecutionList = null;
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
}
}
answer.setResultMessage(msg);
answer.setDataList(testCaseExecutionList);
return answer;
}
Aggregations