use of org.cerberus.crud.entity.TestCaseStepAction in project cerberus-source by cerberustesting.
the class TestCaseStepActionDAO method readByTestTestCase.
@Override
public AnswerList readByTestTestCase(String test, String testcase) {
AnswerList response = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<TestCaseStepAction> actionList = new ArrayList<TestCaseStepAction>();
StringBuilder query = new StringBuilder();
query.append("SELECT * FROM testcasestepaction tca WHERE tca.test = ? AND tca.testcase = ?");
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
preStat.setString(1, test);
preStat.setString(2, testcase);
ResultSet resultSet = preStat.executeQuery();
try {
// gets the data
while (resultSet.next()) {
actionList.add(this.loadFromResultSet(resultSet));
}
// get the total number of rows
resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");
int nrTotalRows = 0;
if (resultSet != null && resultSet.next()) {
nrTotalRows = resultSet.getInt(1);
}
if (actionList.size() >= MAX_ROW_SELECTED) {
// Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.
LOG.error("Partial Result in the query.");
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
response = new AnswerList(actionList, actionList.size());
} else if (actionList.size() <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
response = new AnswerList(actionList, actionList.size());
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
response = new AnswerList(actionList, actionList.size());
}
} 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%", "Unable to retrieve the list of entries!"));
} finally {
if (resultSet != null) {
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%", "Unable to retrieve the list of entries!"));
} finally {
if (preStat != null) {
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%", "Unable to retrieve the list of entries!"));
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
response.setResultMessage(msg);
return response;
}
use of org.cerberus.crud.entity.TestCaseStepAction in project cerberus-source by cerberustesting.
the class LoadTestCaseService method loadTestCaseStepAction.
public List<TestCaseStepAction> loadTestCaseStepAction(TestCaseStep testCaseStep, TestCaseStep UsedTestCaseStep) {
List<TestCaseStepAction> result = new ArrayList<TestCaseStepAction>();
List<TestCaseStepAction> tcsaToAdd;
/**
* If use Step, take the List of action and control of the used step
*/
boolean useStep = (UsedTestCaseStep != null);
if (!useStep) {
tcsaToAdd = this.testCaseStepActionService.getListOfAction(testCaseStep.getTest(), testCaseStep.getTestCase(), testCaseStep.getStep());
} else {
tcsaToAdd = this.testCaseStepActionService.getListOfAction(UsedTestCaseStep.getTest(), UsedTestCaseStep.getTestCase(), UsedTestCaseStep.getStep());
}
/**
* Iterate on the list of action to get the control
* In case of useStep, print the test,testcase,step of the executed test instead of the used step
*/
for (TestCaseStepAction testCaseStepAction : tcsaToAdd) {
LOG.debug("set list of action :" + testCaseStepAction.getAction());
/**
*/
List<TestCaseStepActionControl> tcsacList = this.loadTestCaseStepActionControl(testCaseStep, testCaseStepAction);
if (tcsacList != null) {
testCaseStepAction.setTestCaseStepActionControl(tcsacList);
}
/**
* Update the test, Testcase, Step in case of useStep
*/
testCaseStepAction.setTest(testCaseStep.getTest());
testCaseStepAction.setTestCase(testCaseStep.getTestCase());
testCaseStepAction.setStep(testCaseStep.getStep());
LOG.debug("adding testCaseStepAction" + testCaseStepAction.getAction());
result.add(testCaseStepAction);
LOG.debug("added testCaseStepAction" + testCaseStepAction.getAction());
}
LOG.debug("return List<TestCaseStepAction>");
return result;
}
Aggregations