use of org.cerberus.crud.entity.TestCase in project cerberus-source by cerberustesting.
the class TestCaseDAO method findTestCaseByKey.
@Override
public TestCase findTestCaseByKey(String test, String testCase) throws CerberusException {
boolean throwExcep = false;
TestCase result = null;
final String query = "SELECT * FROM testcase tec LEFT OUTER JOIN application app on app.application = tec.application WHERE test = ? AND testcase = ?";
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query);
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
preStat.setString(1, test);
preStat.setString(2, testCase);
ResultSet resultSet = preStat.executeQuery();
try {
if (resultSet.next()) {
result = this.loadFromResultSet(resultSet);
} else {
result = null;
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
if (throwExcep) {
throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
}
return result;
}
use of org.cerberus.crud.entity.TestCase in project cerberus-source by cerberustesting.
the class TestCaseDAO method findTestCaseByCriteria.
@Override
public List<TestCase> findTestCaseByCriteria(TestCase testCase, String text, String system) {
List<TestCase> list = null;
String query = new StringBuilder().append("SELECT tec.* FROM testcase tec ").append("LEFT OUTER JOIN application app ON app.application=tec.application ").append(" WHERE (tec.test LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.test", testCase.getTest())).append(") AND (tec.project LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.project", testCase.getProject())).append(") AND (tec.ticket LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.ticket", testCase.getTicket())).append(") AND (tec.bugid LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.bugid", testCase.getBugID())).append(") AND (tec.origine LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.origine", testCase.getOrigine())).append(") AND (app.system LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("app.system", system)).append(") AND (tec.application LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.application", testCase.getApplication())).append(") AND (tec.priority LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfMinusOne("tec.priority", testCase.getPriority())).append(") AND (tec.status LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.status", testCase.getStatus())).append(") AND (tec.group LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.group", testCase.getGroup())).append(") AND (tec.activePROD LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.activePROD", testCase.getActivePROD())).append(") AND (tec.activeUAT LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.activeUAT", testCase.getActiveUAT())).append(") AND (tec.activeQA LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.activeQA", testCase.getActiveQA())).append(") AND (tec.description LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.description", text)).append(" OR tec.howto LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.howto", text)).append(" OR tec.behaviororvalueexpected LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.behaviororvalueexpected", text)).append(" OR tec.comment LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.comment", text)).append(") AND (tec.TcActive LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.TcActive", testCase.getTcActive())).append(") AND (tec.frombuild LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.frombuild", testCase.getFromBuild())).append(") AND (tec.fromrev LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.fromrev", testCase.getFromRev())).append(") AND (tec.tobuild LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.tobuild", testCase.getToBuild())).append(") AND (tec.torev LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.torev", testCase.getToRev())).append(") AND (tec.targetbuild LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.targetbuild", testCase.getTargetBuild())).append(") AND (tec.targetrev LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.targetrev", testCase.getTargetRev())).append(") AND (tec.testcase LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.testcase", testCase.getTestCase())).append(") AND (tec.function LIKE ").append(ParameterParserUtil.wildcardOrIsNullIfEmpty("tec.function", testCase.getFunction())).append(")").toString();
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query);
try {
ResultSet resultSet = preStat.executeQuery();
list = new ArrayList<TestCase>();
try {
while (resultSet.next()) {
list.add(this.loadFromResultSet(resultSet));
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
resultSet.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
preStat.close();
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
return list;
}
use of org.cerberus.crud.entity.TestCase in project cerberus-source by cerberustesting.
the class TestCaseDAO method findTestCaseByServiceByDataLib.
@Override
public AnswerList findTestCaseByServiceByDataLib(String service) {
AnswerList ansList = new AnswerList();
MessageEvent rs;
List<TestListDTO> listOfTests = new ArrayList<TestListDTO>();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<TestCase> testCaseList = new ArrayList<TestCase>();
final String sql = " select count(*) as total, t.Test, tc.TestCase, t.Description as testDescription, tc.Description as testCaseDescription, tc.Application," + "tc.TcActive as Active, tc.`Group`, tc.UsrCreated, tc.`Status` " + " from testcase tc INNER JOIN test t ON t.test = tc.test" + " INNER JOIN testcasecountryproperties tccp ON tccp.Test = t.Test AND tccp.TestCase = tc.TestCase" + " INNER JOIN testdatalib td ON td.Name = tccp.Value1 AND (tccp.Country = td.Country or td.country='') and tccp.test = t.test and tccp.testcase = tc.testcase" + " INNER JOIN appservice ser on ser.Service = td.Service" + " WHERE ser.Service = ?" + " group by tc.test, tc.TestCase";
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(sql.toString());
try {
preStat.setString(1, service);
HashMap<String, TestListDTO> map = new HashMap<String, TestListDTO>();
String key, test, testCase;
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
TestListDTO testList;
TestCaseListDTO testCaseDTO;
test = resultSet.getString("Test");
testCase = resultSet.getString("TestCase");
if (map.containsKey(test)) {
testList = map.get(test);
} else {
testList = new TestListDTO();
testList.setDescription(resultSet.getString("testDescription"));
testList.setTest(test);
}
testCaseDTO = new TestCaseListDTO();
testCaseDTO.setTestCaseDescription(resultSet.getString("testCaseDescription"));
testCaseDTO.setTestCaseNumber(testCase);
testCaseDTO.setApplication(resultSet.getString("Application"));
testCaseDTO.setCreator(resultSet.getString("tc.UsrCreated"));
testCaseDTO.setStatus(resultSet.getString("Status"));
testCaseDTO.setGroup(resultSet.getString("Group"));
testCaseDTO.setIsActive(resultSet.getString("Active"));
testList.getTestCaseList().add(testCaseDTO);
map.put(test, testList);
}
listOfTests = new ArrayList<TestListDTO>(map.values());
if (listOfTests.isEmpty()) {
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
} else {
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
rs.setDescription(rs.getDescription().replace("%ITEM%", "List of Test Cases").replace("%OPERATION%", "Select"));
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
rs.setDescription(rs.getDescription().replace("%DESCRIPTION%", "Unable to get the list of test cases."));
} finally {
if (resultSet != null) {
resultSet.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
rs.setDescription(rs.getDescription().replace("%DESCRIPTION%", "Unable to get the list of test cases."));
} finally {
if (preStat != null) {
preStat.close();
}
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
rs.setDescription(rs.getDescription().replace("%DESCRIPTION%", "Unable to get the list of test cases."));
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
LOG.warn(e.toString());
}
}
ansList.setResultMessage(rs);
ansList.setDataList(listOfTests);
return ansList;
}
use of org.cerberus.crud.entity.TestCase in project cerberus-source by cerberustesting.
the class TestCaseDAO method loadFromResultSet.
/**
* Uses data of ResultSet to create object {@link TestCase}
*
* @param resultSet ResultSet relative to select from table TestCase
* @return object {@link TestCase}
* @throws SQLException when trying to get value from
* {@link java.sql.ResultSet#getString(String)}
* @see FactoryTestCase
*/
@Override
public TestCase loadFromResultSet(ResultSet resultSet) throws SQLException {
String test = resultSet.getString("tec.Test");
String testCase = resultSet.getString("tec.TestCase");
String tcapplication = resultSet.getString("tec.Application");
String project = resultSet.getString("tec.Project");
String ticket = resultSet.getString("tec.Ticket");
String description = resultSet.getString("tec.Description");
String behavior = resultSet.getString("tec.BehaviorOrValueExpected");
int priority = resultSet.getInt("tec.Priority");
int testCaseVersion = resultSet.getInt("tec.TestCaseVersion");
String status = resultSet.getString("tec.Status");
String tcactive = resultSet.getString("tec.TcActive");
String conditionOper = resultSet.getString("tec.ConditionOper");
String conditionVal1 = resultSet.getString("tec.ConditionVal1");
String conditionVal2 = resultSet.getString("tec.ConditionVal2");
String group = resultSet.getString("tec.Group");
String origin = resultSet.getString("tec.Origine");
String refOrigin = resultSet.getString("tec.RefOrigine");
String howTo = resultSet.getString("tec.HowTo");
String comment = resultSet.getString("tec.Comment");
String fromSprint = resultSet.getString("tec.FromBuild");
String fromRevision = resultSet.getString("tec.FromRev");
String toSprint = resultSet.getString("tec.ToBuild");
String toRevision = resultSet.getString("tec.ToRev");
String bugID = resultSet.getString("tec.BugID");
String targetSprint = resultSet.getString("tec.TargetBuild");
String targetRevision = resultSet.getString("tec.TargetRev");
String implementer = resultSet.getString("tec.Implementer");
String runQA = resultSet.getString("tec.activeQA");
String runUAT = resultSet.getString("tec.activeUAT");
String runPROD = resultSet.getString("tec.activePROD");
String function = resultSet.getString("tec.function");
String usrCreated = resultSet.getString("tec.UsrCreated");
String dateCreated = resultSet.getString("tec.DateCreated");
String usrModif = resultSet.getString("tec.UsrModif");
Timestamp dateModif = resultSet.getTimestamp("tec.DateModif");
String userAgent = resultSet.getString("tec.useragent");
String screenSize = resultSet.getString("tec.screensize");
String system = null;
try {
system = resultSet.getString("app.system");
} catch (SQLException e) {
LOG.debug("Column system does not Exist.");
}
TestCase newTestCase = new TestCase();
newTestCase = factoryTestCase.create(test, testCase, origin, refOrigin, usrCreated, implementer, usrModif, project, ticket, function, tcapplication, runQA, runUAT, runPROD, priority, group, status, description, behavior, howTo, tcactive, conditionOper, conditionVal1, conditionVal2, fromSprint, fromRevision, toSprint, toRevision, status, bugID, targetSprint, targetRevision, comment, dateCreated, userAgent, screenSize, dateModif, testCaseVersion);
newTestCase.setSystem(system);
return newTestCase;
}
use of org.cerberus.crud.entity.TestCase in project cerberus-source by cerberustesting.
the class TestCaseDAO method readByTestByCriteria.
@Override
public AnswerList readByTestByCriteria(String system, String test, int start, int amount, String sortInformation, String searchTerm, Map<String, List<String>> individualSearch) {
AnswerList answer = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<TestCase> testCaseList = new ArrayList<TestCase>();
StringBuilder searchSQL = new StringBuilder();
List<String> individalColumnSearchValues = new ArrayList<String>();
StringBuilder query = new StringBuilder();
// SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
// were applied -- used for pagination p
query.append("SELECT SQL_CALC_FOUND_ROWS * FROM testcase tec ");
query.append(" LEFT OUTER JOIN testcaselabel tel on tec.test = tel.test AND tec.testcase = tel.testcase ");
query.append(" LEFT OUTER JOIN label lab on tel.labelId = lab.id ");
query.append(" LEFT OUTER JOIN application app on app.application = tec.application ");
searchSQL.append("WHERE 1=1");
if (!StringUtil.isNullOrEmpty(system)) {
searchSQL.append(" AND app.`system` = ? ");
}
if (!StringUtil.isNullOrEmpty(test)) {
searchSQL.append(" AND tec.`test` = ?");
}
if (!StringUtil.isNullOrEmpty(searchTerm)) {
searchSQL.append(" and (tec.`testcase` like ?");
searchSQL.append(" or tec.`test` like ?");
searchSQL.append(" or tec.`application` like ?");
searchSQL.append(" or tec.`project` like ?");
searchSQL.append(" or tec.`usrCreated` like ?");
searchSQL.append(" or tec.`usrModif` like ?");
searchSQL.append(" or tec.`tcactive` like ?");
searchSQL.append(" or tec.`status` like ?");
searchSQL.append(" or tec.`group` like ?");
searchSQL.append(" or tec.`priority` like ?");
searchSQL.append(" or tec.`dateCreated` like ?");
searchSQL.append(" or tec.`description` like ?");
searchSQL.append(" or lab.`label` like ?)");
}
if (individualSearch != null && !individualSearch.isEmpty()) {
searchSQL.append(" and ( 1=1 ");
for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
searchSQL.append(" and ");
searchSQL.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));
individalColumnSearchValues.addAll(entry.getValue());
}
searchSQL.append(" )");
}
query.append(searchSQL);
query.append(" group by tec.test, tec.testcase ");
if (!StringUtil.isNullOrEmpty(sortInformation)) {
query.append(" order by ").append(sortInformation);
}
if (amount != 0) {
query.append(" limit ").append(start).append(" , ").append(amount);
} else {
query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);
}
// 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 {
int i = 1;
if (!StringUtil.isNullOrEmpty(system)) {
preStat.setString(i++, system);
}
if (!StringUtil.isNullOrEmpty(test)) {
preStat.setString(i++, test);
}
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 + "%");
preStat.setString(i++, "%" + 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);
}
ResultSet resultSet = preStat.executeQuery();
try {
// gets the data
while (resultSet.next()) {
testCaseList.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 (testCaseList.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));
answer = new AnswerList(testCaseList, nrTotalRows);
} else if (testCaseList.size() <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
answer = new AnswerList(testCaseList, nrTotalRows);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
answer = new AnswerList(testCaseList, nrTotalRows);
}
} 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 {
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%", exception.toString()));
} 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%", exception.toString()));
} finally {
try {
if (!this.databaseSpring.isOnTransaction()) {
if (connection != null) {
connection.close();
}
}
} catch (SQLException exception) {
LOG.warn("Unable to close connection : " + exception.toString());
}
}
answer.setResultMessage(msg);
answer.setDataList(testCaseList);
return answer;
}
Aggregations