use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.
the class TestCaseDAO method create.
@Override
public Answer create(TestCase testCase) {
MessageEvent msg = null;
final StringBuffer sql = new StringBuffer("INSERT INTO `testcase` ").append(" ( `Test`, `TestCase`, `Application`, `Project`, `Ticket`, ").append("`Description`, `BehaviorOrValueExpected`, ").append("`Priority`, `Status`, `TcActive`, ").append("`Group`, `Origine`, `RefOrigine`, `HowTo`, `Comment`, ").append("`FromBuild`, `FromRev`, `ToBuild`, `ToRev`, ").append("`BugID`, `TargetBuild`, `TargetRev`, `UsrCreated`, ").append("`Implementer`, `function`, `activeQA`, `activeUAT`, `activePROD`, `useragent`, `screenSize`, `conditionOper`, `conditionVal1`, `conditionVal2`, `testCaseVersion`) ").append("VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ").append("?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ); ");
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + sql.toString());
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(sql.toString());
try {
int i = 1;
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTest(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTestCase(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getApplication(), ""));
preStat.setString(i++, testCase.getProject());
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTicket(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getDescription(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getBehaviorOrValueExpected(), ""));
preStat.setString(i++, Integer.toString(testCase.getPriority()));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getStatus(), ""));
preStat.setString(i++, testCase.getTcActive() != null && !testCase.getTcActive().equals("Y") ? "N" : "Y");
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getGroup(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getOrigine(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getRefOrigine(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getHowTo(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getComment(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFromBuild(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFromRev(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getToBuild(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getToRev(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getBugID(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTargetBuild(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTargetRev(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getUsrCreated(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getImplementer(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFunction(), ""));
preStat.setString(i++, testCase.getActiveQA() != null && !testCase.getActiveQA().equals("Y") ? "N" : "Y");
preStat.setString(i++, testCase.getActiveUAT() != null && !testCase.getActiveUAT().equals("Y") ? "N" : "Y");
preStat.setString(i++, testCase.getActivePROD() != null && !testCase.getActivePROD().equals("N") ? "Y" : "N");
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getUserAgent(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getScreenSize(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionOper(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionVal1(), ""));
preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionVal2(), ""));
preStat.setInt(i++, ParameterParserUtil.parseIntegerParam(testCase.getTestCaseVersion(), 0));
preStat.executeUpdate();
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString(), exception);
if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) {
// 23000 is the sql state for duplicate entries
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));
} else {
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 TestCaseExecutionFileDAO method create.
@Override
public Answer create(TestCaseExecutionFile object) {
MessageEvent msg = null;
StringBuilder query = new StringBuilder();
query.append("INSERT INTO testcaseexecutionfile (`exeid`, `level`, `fileDesc`, `fileName`, `fileType`, `usrcreated`) ");
query.append("VALUES (?,?,?,?,?,?)");
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
preStat.setLong(1, object.getExeId());
preStat.setString(2, object.getLevel());
preStat.setString(3, object.getFileDesc());
preStat.setString(4, object.getFileName());
preStat.setString(5, object.getFileType());
preStat.setString(6, object.getUsrCreated());
preStat.executeUpdate();
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) {
// 23000 is the sql state for duplicate entries
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));
} else {
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.error("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 TestCaseExecutionFileDAO method update.
@Override
public Answer update(TestCaseExecutionFile object) {
MessageEvent msg = null;
final String query = "UPDATE testcaseexecutionfile SET exeid = ?, level = ?, `filedesc` = ?, `filename` = ?, filetype = ?, usrmodif = ?, datemodif = ? WHERE id = ?";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setLong(1, object.getExeId());
preStat.setString(2, object.getLevel());
preStat.setString(3, object.getFileDesc());
preStat.setString(4, object.getFileName());
preStat.setString(5, object.getFileType());
preStat.setString(6, object.getUsrModif());
preStat.setTimestamp(7, object.getDateModif());
preStat.setLong(8, 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 TestCaseExecutionQueueDAO method updateToCancelled.
@Override
public Answer updateToCancelled(long id, String comment) {
MessageEvent msg = null;
String query = "UPDATE `" + TABLE + "` " + "SET `" + COLUMN_STATE + "` = 'CANCELLED', `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now(), `" + COLUMN_COMMENT + "` = ? " + "WHERE `" + COLUMN_ID + "` = ? " + "AND `" + COLUMN_STATE + "` IN ('ERROR','QUEUED')";
// 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 CANCELLED for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is no longuer in ERROR or QUEUED ?"));
LOG.warn("Unable to move state to CANCELLED for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is no longuer in ERROR or QUEUED ?");
// throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_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 updateToCancelledForce.
@Override
public Answer updateToCancelledForce(long id, String comment) {
MessageEvent msg = null;
String query = "UPDATE `" + TABLE + "` " + "SET `" + COLUMN_STATE + "` = 'CANCELLED', `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now(), `" + COLUMN_COMMENT + "` = ? " + "WHERE `" + COLUMN_ID + "` = ? " + "AND `" + COLUMN_STATE + "` IN ('WAITING','STARTING','EXECUTING')";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
}
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 CANCELLED (forced) for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is no longuer in WAITING or STARTING or EXECUTING ?"));
LOG.warn("Unable to move state to CANCELLED (forced) for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is no longuer in WAITING or STARTING or EXECUTING ?");
// throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_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);
}
Aggregations