use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method updateComment.
@Override
public Answer updateComment(long id, String comment) {
MessageEvent msg = null;
String query = "UPDATE `" + TABLE + "` " + "SET `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now(), `" + COLUMN_COMMENT + "` = ? " + "WHERE `" + COLUMN_ID + "` = ? ;";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.id : " + id);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
int i = 1;
preStat.setString(i++, comment);
preStat.setLong(i++, id);
int updateResult = preStat.executeUpdate();
if (updateResult <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_NOUPDATE);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%DESCRIPTION%", "Unable to update comment for execution in queue " + id + " (update result: " + updateResult + ")."));
LOG.warn("Unable to update comment for execution in queue " + id + " (update result: " + updateResult + ").");
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
}
} 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());
}
}
return new Answer(msg);
}
use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method updateToQueued.
@Override
public Answer updateToQueued(long id, String comment) {
MessageEvent msg = null;
String query = "UPDATE `" + TABLE + "` " + "SET `" + COLUMN_STATE + "` = 'QUEUED', `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now(), `" + COLUMN_COMMENT + "` = ? " + "WHERE `" + COLUMN_ID + "` = ? " + "AND `" + COLUMN_STATE + "` IN ('CANCELLED', 'ERROR')";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.id : " + id);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
int i = 1;
preStat.setString(i++, comment);
preStat.setLong(i++, id);
int updateResult = preStat.executeUpdate();
if (updateResult <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_NOUPDATE);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%DESCRIPTION%", "Unable to move state to QUEUD for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is no longuer in CANCELLED or ERROR ?"));
LOG.warn("Unable to move state to QUEUED for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is no longuer in CANCELLED or ERROR ?");
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
}
} 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());
}
}
return new Answer(msg);
}
use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.
the class TestCaseExecutionQueueDAO method update.
@Override
public Answer update(TestCaseExecutionQueue object) {
MessageEvent msg = null;
String query = "UPDATE testcaseexecutionqueue exq SET `Test` = ?, `TestCase` = ?, `Country` = ?, Environment = ?, Robot = ?, " + "RobotIP = ?, `RobotPort` = ?, Browser = ?, BrowserVersion = ?, `Platform`= ?, `ScreenSize` = ?, " + "ManualURL = ?, `ManualHost` = ?, ManualContextRoot = ?, `ManualLoginRelativeUrl`= ?, `ManualEnvData` = ?, " + "Tag = ?, `Screenshot` = ?, Verbose = ?, `Timeout`= ?, `PageSource` = ?, `debugFlag` = ?, `priority` = ?, " + "SeleniumLog = ?, `Retries`= ?, `ManualExecution` = ?, " + "`UsrModif`= ?, `DateModif` = now() ";
query += " WHERE `ID` = ?";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
LOG.debug("SQL.param.id : " + object.getId());
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
int i = 1;
preStat.setString(i++, object.getTest());
preStat.setString(i++, object.getTestCase());
preStat.setString(i++, object.getCountry());
preStat.setString(i++, object.getEnvironment());
preStat.setString(i++, object.getRobot());
preStat.setString(i++, object.getRobotIP());
preStat.setString(i++, object.getRobotPort());
preStat.setString(i++, object.getBrowser());
preStat.setString(i++, object.getBrowserVersion());
preStat.setString(i++, object.getPlatform());
preStat.setString(i++, object.getScreenSize());
preStat.setInt(i++, object.getManualURL());
preStat.setString(i++, object.getManualHost());
preStat.setString(i++, object.getManualContextRoot());
preStat.setString(i++, object.getManualLoginRelativeURL());
preStat.setString(i++, object.getManualEnvData());
preStat.setString(i++, object.getTag());
preStat.setInt(i++, object.getScreenshot());
preStat.setInt(i++, object.getVerbose());
preStat.setString(i++, object.getTimeout());
preStat.setInt(i++, object.getPageSource());
preStat.setString(i++, object.getDebugFlag());
preStat.setInt(i++, object.getPriority());
preStat.setInt(i++, object.getSeleniumLog());
preStat.setInt(i++, object.getRetries());
preStat.setString(i++, object.getManualExecution());
preStat.setString(i++, object.getUsrModif());
preStat.setLong(i++, object.getId());
preStat.executeUpdate();
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
} 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());
}
}
return new Answer(msg);
}
use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.
the class TestCaseLabelDAO method update.
@Override
public Answer update(TestCaseLabel object) {
Answer response = new Answer();
MessageEvent msg = null;
final String query = "UPDATE testcaselabel SET `test` = ?, `testcase` = ?, `labelId` = ?, `usrModif` = ?, `dateModif` = NOW() WHERE id = ?";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
}
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query.toString())) {
preStat.setString(1, object.getTest());
preStat.setString(2, object.getTestcase());
preStat.setInt(3, object.getLabelId());
preStat.setString(4, object.getUsrModif());
preStat.setInt(5, object.getId());
preStat.executeUpdate();
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
} catch (Exception e) {
LOG.warn("Unable to update TestCaseLabel: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
response.setResultMessage(msg);
}
return response;
}
use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.
the class TestCaseStepActionControlDAO method create.
@Override
public Answer create(TestCaseStepActionControl testCaseStepActionControl) {
Answer ans = new Answer();
MessageEvent msg = null;
StringBuilder query = new StringBuilder();
query.append("INSERT INTO testcasestepactioncontrol (`test`, `testCase`, `step`, `sequence`, `controlSequence`, `sort`, `conditionOper`, `conditionVal1`, `conditionVal2`, `control`, `value1`, `value2`, `fatal`, `Description`, `screenshotfilename`) ");
query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query.toString())) {
// Prepare and execute query
preStat.setString(1, testCaseStepActionControl.getTest());
preStat.setString(2, testCaseStepActionControl.getTestCase());
preStat.setInt(3, testCaseStepActionControl.getStep());
preStat.setInt(4, testCaseStepActionControl.getSequence());
preStat.setInt(5, testCaseStepActionControl.getControlSequence());
preStat.setInt(6, testCaseStepActionControl.getSort());
preStat.setString(7, testCaseStepActionControl.getConditionOper());
preStat.setString(8, testCaseStepActionControl.getConditionVal1());
preStat.setString(9, testCaseStepActionControl.getConditionVal2());
preStat.setString(10, testCaseStepActionControl.getControl());
preStat.setString(11, testCaseStepActionControl.getValue1());
preStat.setString(12, testCaseStepActionControl.getValue2());
preStat.setString(13, testCaseStepActionControl.getFatal());
preStat.setString(14, testCaseStepActionControl.getDescription());
preStat.setString(15, testCaseStepActionControl.getScreenshotFilename());
preStat.executeUpdate();
// Set the final message
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "CREATE");
} catch (Exception e) {
LOG.warn("Unable to TestCaseStepActionControl: " + e.getMessage());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
ans.setResultMessage(msg);
}
return ans;
}
Aggregations