use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class TestCaseExecutionDAO method readDistinctColumnByTag.
@Override
public AnswerList readDistinctColumnByTag(String tag, boolean env, boolean country, boolean browser, boolean app) {
AnswerList answer = new AnswerList();
StringBuilder query = new StringBuilder();
StringBuilder distinct = new StringBuilder();
int prev = 0;
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
if (!(!env && !country && !app && !browser)) {
if (env) {
distinct.append("Environment");
prev++;
}
if (country) {
if (prev != 0) {
prev = 0;
distinct.append(",");
}
distinct.append("Country");
prev++;
}
if (browser) {
if (prev != 0) {
prev = 0;
distinct.append(",");
}
distinct.append("Browser");
prev++;
}
if (app) {
if (prev != 0) {
prev = 0;
distinct.append(",");
}
distinct.append("Application");
}
query.append("SELECT ");
query.append(distinct.toString());
query.append(" FROM testcaseexecution exe WHERE exe.tag = ? GROUP BY ");
query.append(distinct.toString());
} else {
// If there is no distinct, select nothing
query.append("SELECT * FROM testcaseexecution exe WHERE 1 = 0 AND exe.tag = ?");
}
Connection connection = this.databaseSpring.connect();
List<TestCaseExecution> column = new ArrayList<TestCaseExecution>();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
preStat.setString(1, tag);
try {
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
TestCaseExecution tmp = new TestCaseExecution();
if (env) {
tmp.setEnvironment(resultSet.getString("Environment"));
} else {
tmp.setEnvironment("");
}
if (country) {
tmp.setCountry(resultSet.getString("Country"));
} else {
tmp.setCountry("");
}
if (browser) {
tmp.setBrowser(resultSet.getString("Browser"));
} else {
tmp.setBrowser("");
}
if (app) {
tmp.setApplication(resultSet.getString("Application"));
} else {
tmp.setApplication("");
}
column.add(tmp);
}
msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));
answer = new AnswerList(column, column.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!"));
column = null;
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException ex) {
LOG.warn("Unable to execute query : " + ex.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
column = null;
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException ex) {
LOG.warn(ex.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
LOG.warn("Unable to execute query : " + ex.toString());
}
}
answer.setResultMessage(msg);
return answer;
}
use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class TestCaseExecutionDAO method readByTag.
@Override
public AnswerList readByTag(String tag) throws CerberusException {
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
AnswerList answer = new AnswerList();
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 as app on tec.application = app.application ");
query.append("where 1=1 and exe.tag = ? ");
// 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());
preStat.setString(1, tag);
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.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;
}
use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class TestCaseExecutionDAO method loadWithDependenciesFromResultSet.
private TestCaseExecution loadWithDependenciesFromResultSet(ResultSet resultSet) throws SQLException {
TestCaseExecution testCaseExecution = new TestCaseExecution();
testCaseExecution = this.loadFromResultSet(resultSet);
testCaseExecution.setTestCaseObj(testCaseDAO.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 loadFromResultSet.
@Override
public TestCaseExecution loadFromResultSet(ResultSet resultSet) throws SQLException {
long id = ParameterParserUtil.parseLongParam(resultSet.getString("exe.ID"), 0);
String test = ParameterParserUtil.parseStringParam(resultSet.getString("exe.test"), "");
String testcase = ParameterParserUtil.parseStringParam(resultSet.getString("exe.testcase"), "");
String description = ParameterParserUtil.parseStringParam(resultSet.getString("exe.description"), "");
String build = ParameterParserUtil.parseStringParam(resultSet.getString("exe.build"), "");
String revision = ParameterParserUtil.parseStringParam(resultSet.getString("exe.revision"), "");
String environment = ParameterParserUtil.parseStringParam(resultSet.getString("exe.environment"), "");
String environmentData = ParameterParserUtil.parseStringParam(resultSet.getString("exe.environmentData"), "");
String country = ParameterParserUtil.parseStringParam(resultSet.getString("exe.country"), "");
String browser = ParameterParserUtil.parseStringParam(resultSet.getString("exe.browser"), "");
String version = ParameterParserUtil.parseStringParam(resultSet.getString("exe.version"), "");
String platform = ParameterParserUtil.parseStringParam(resultSet.getString("exe.platform"), "");
String browserFullVersion = ParameterParserUtil.parseStringParam(resultSet.getString("exe.browserFullVersion"), "");
long start = ParameterParserUtil.parseLongParam(String.valueOf(resultSet.getTimestamp("exe.start").getTime()), 0);
long end = ParameterParserUtil.parseLongParam(String.valueOf(resultSet.getTimestamp("exe.end").getTime()), 0);
String controlStatus = ParameterParserUtil.parseStringParam(resultSet.getString("exe.controlStatus"), "");
String controlMessage = ParameterParserUtil.parseStringParam(resultSet.getString("exe.controlMessage"), "");
String application = ParameterParserUtil.parseStringParam(resultSet.getString("exe.application"), "");
// Host the Selenium IP
String ip = ParameterParserUtil.parseStringParam(resultSet.getString("exe.ip"), "");
String url = ParameterParserUtil.parseStringParam(resultSet.getString("exe.url"), "");
// host the Selenium Port
String port = ParameterParserUtil.parseStringParam(resultSet.getString("exe.port"), "");
String tag = ParameterParserUtil.parseStringParam(resultSet.getString("exe.tag"), "");
String status = ParameterParserUtil.parseStringParam(resultSet.getString("exe.status"), "");
String crbVersion = ParameterParserUtil.parseStringParam(resultSet.getString("exe.crbVersion"), "");
String executor = ParameterParserUtil.parseStringParam(resultSet.getString("exe.executor"), "");
String screenSize = ParameterParserUtil.parseStringParam(resultSet.getString("exe.screensize"), "");
String conditionOper = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionOper"), "");
String conditionVal1 = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal1"), "");
String conditionVal1Init = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal1Init"), "");
String conditionVal2 = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal2"), "");
String conditionVal2Init = ParameterParserUtil.parseStringParam(resultSet.getString("exe.conditionVal2Init"), "");
String manualExecution = ParameterParserUtil.parseStringParam(resultSet.getString("exe.manualExecution"), "N");
String userAgent = ParameterParserUtil.parseStringParam(resultSet.getString("exe.userAgent"), "");
String system = ParameterParserUtil.parseStringParam(resultSet.getString("exe.system"), "");
String robotDecli = ParameterParserUtil.parseStringParam(resultSet.getString("exe.robotdecli"), "");
long queueId = ParameterParserUtil.parseLongParam(resultSet.getString("exe.queueId"), 0);
int testCaseVersion = ParameterParserUtil.parseIntegerParam(resultSet.getInt("exe.testCaseVersion"), 0);
TestCaseExecution result = factoryTCExecution.create(id, test, testcase, description, build, revision, environment, country, browser, version, platform, browserFullVersion, start, end, controlStatus, controlMessage, application, null, ip, url, port, tag, 0, 0, 0, 0, true, "", "", status, crbVersion, null, null, null, false, null, null, null, environmentData, null, null, null, null, executor, 0, screenSize, null, conditionOper, conditionVal1Init, conditionVal2Init, conditionVal1, conditionVal2, manualExecution, userAgent, testCaseVersion, system, robotDecli);
result.setQueueID(queueId);
return result;
}
use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.
the class TestCaseExecutionDAO method findTCExecutionByKey.
@Override
public TestCaseExecution findTCExecutionByKey(long id) throws CerberusException {
TestCaseExecution result = null;
final String query = "SELECT * FROM testcaseexecution exe, application app WHERE exe.application = app.application AND ID = ?";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
}
try (Connection connection = this.databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query)) {
preStat.setLong(1, id);
try (ResultSet resultSet = preStat.executeQuery()) {
if (resultSet.first()) {
result = this.loadTestCaseExecutionAndApplicationFromResultSet(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;
}
Aggregations