use of org.cerberus.crud.entity.TestCase in project cerberus-source by cerberustesting.
the class TestCaseDAO method findTestCaseByCampaignNameAndCountries.
@Override
public AnswerItem<List<TestCase>> findTestCaseByCampaignNameAndCountries(String campaign, String[] countries, boolean withLabelOrBattery, String[] status, String[] system, String[] application, String[] priority, String[] group, Integer maxReturn) {
List<TestCase> list = null;
AnswerItem answer = new AnswerItem();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
HashMap<String, String[]> tcParameters = new HashMap<String, String[]>();
tcParameters.put("status", status);
tcParameters.put("system", system);
tcParameters.put("application", application);
tcParameters.put("priority", priority);
tcParameters.put("countries", countries);
tcParameters.put("group", group);
StringBuilder query = new StringBuilder("SELECT tec.*, app.system FROM testcase tec ");
if (withLabelOrBattery) {
query.append("LEFT OUTER JOIN application app ON app.application = tec.application ").append("INNER JOIN testcasecountry tcc ON tcc.Test = tec.Test and tcc.TestCase = tec.TestCase ").append("LEFT JOIN testcaselabel tel ON tec.test = tel.test AND tec.testcase = tel.testcase ").append("LEFT JOIN campaignlabel cpl ON cpl.labelId = tel.labelId ").append("WHERE (cpl.campaign = ? )");
} else if (!withLabelOrBattery && (status != null || system != null || application != null || priority != null)) {
query.append("LEFT OUTER JOIN application app ON app.application = tec.application ").append("INNER JOIN testcasecountry tcc ON tcc.Test = tec.Test and tcc.TestCase = tec.TestCase ").append("WHERE 1=1");
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_VALIDATIONS_ERROR);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "You have a problem in your campaign definition"));
answer.setResultMessage(msg);
return answer;
}
for (Entry<String, String[]> entry : tcParameters.entrySet()) {
String cle = entry.getKey();
String[] valeur = entry.getValue();
if (valeur != null && valeur.length > 0) {
if (!cle.equals("system") && !cle.equals("countries")) {
query.append(" AND tec." + cle + " in (?");
} else if (cle.equals("system")) {
query.append(" AND app.system in (?");
} else {
query.append(" AND tcc.Country in (?");
}
if (valeur.length > 1) {
for (int i = 0; i < valeur.length - 1; i++) {
query.append(",?");
}
}
query.append(")");
}
}
query.append(" GROUP BY tec.test, tec.testcase LIMIT ?");
// 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 (withLabelOrBattery) {
preStat.setString(i++, campaign);
}
for (Entry<String, String[]> entry : tcParameters.entrySet()) {
String[] valeur = entry.getValue();
if (valeur != null && valeur.length > 0) {
for (String c : valeur) {
preStat.setString(i++, c);
}
}
}
preStat.setInt(i++, maxReturn);
ResultSet resultSet = preStat.executeQuery();
list = new ArrayList<TestCase>();
try {
while (resultSet.next()) {
list.add(this.loadFromResultSet(resultSet));
}
if (list.size() >= maxReturn) {
// 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 : " + maxReturn));
answer = new AnswerItem(list);
} else if (list.size() <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
answer = new AnswerItem(list);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
answer = new AnswerItem(list);
}
} catch (SQLException exception) {
LOG.error("Unable to execute query : " + exception.toString());
} finally {
answer.setResultMessage(msg);
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 answer;
}
use of org.cerberus.crud.entity.TestCase in project cerberus-source by cerberustesting.
the class TestCaseDAO method findTestCaseByCriteria.
@Override
public List<TestCase> findTestCaseByCriteria(String test, String application, String country, String active) {
List<TestCase> list = null;
final String query = "SELECT tec.* FROM testcase tec " + "JOIN testcasecountry tcc " + "LEFT OUTER JOIN application app on app.application = tec.application " + "WHERE tec.test=tcc.test AND tec.testcase=tcc.testcase " + "AND tec.test = ? AND tec.application = ? AND tcc.country = ? AND tec.tcactive = ? ";
// 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, application);
preStat.setString(3, country);
preStat.setString(4, active);
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 findTestCaseByApplication.
@Override
public List<TestCase> findTestCaseByApplication(final String application) {
List<TestCase> testCases = null;
try (final Connection connection = databaseSpring.connect();
final PreparedStatement statement = connection.prepareStatement(Query.FIND_BY_APPLICATION)) {
statement.setString(1, application);
testCases = new ArrayList<>();
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
testCases.add(loadFromResultSet(resultSet));
}
}
} catch (SQLException e) {
LOG.warn("Unable to get test cases for application " + application, e);
}
return testCases;
}
use of org.cerberus.crud.entity.TestCase in project cerberus-source by cerberustesting.
the class TestCaseDAO method findTestCaseByCriteria.
@Override
public List<TestCase> findTestCaseByCriteria(String[] test, String[] project, String[] app, String[] active, String[] priority, String[] status, String[] group, String[] targetBuild, String[] targetRev, String[] creator, String[] implementer, String[] function, String[] campaign) {
List<TestCase> list = null;
StringBuilder sb = new StringBuilder();
sb.append("SELECT * FROM testcase tec join application app on tec.application=app.application ");
sb.append(" WHERE 1=1 ");
sb.append(SqlUtil.createWhereInClause(" AND tec.Test", test == null ? null : Arrays.asList(test), true));
sb.append(SqlUtil.createWhereInClause(" AND tec.Project", project == null ? null : Arrays.asList(project), true));
sb.append(SqlUtil.createWhereInClause(" AND tec.Application", app == null ? null : Arrays.asList(app), true));
sb.append(SqlUtil.createWhereInClause(" AND tec.tcactive", active == null ? null : Arrays.asList(active), true));
sb.append(SqlUtil.createWhereInClause(" AND tec.priority", priority == null ? null : Arrays.asList(priority), true));
sb.append(SqlUtil.createWhereInClause(" AND tec.status", status == null ? null : Arrays.asList(status), true));
sb.append(SqlUtil.createWhereInClause(" AND tec.group", group == null ? null : Arrays.asList(group), true));
sb.append(SqlUtil.createWhereInClause(" AND tec.targetBuild", targetBuild == null ? null : Arrays.asList(targetBuild), true));
sb.append(SqlUtil.createWhereInClause(" AND tec.targetRev", targetRev == null ? null : Arrays.asList(targetRev), true));
sb.append(SqlUtil.createWhereInClause(" AND tec.creator", creator == null ? null : Arrays.asList(creator), true));
sb.append(SqlUtil.createWhereInClause(" AND tec.implementer", implementer == null ? null : Arrays.asList(implementer), true));
sb.append(SqlUtil.createWhereInClause(" AND tec.funtion", function == null ? null : Arrays.asList(function), true));
sb.append(" GROUP BY tec.test, tec.testcase ");
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + sb.toString());
}
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(sb.toString());
try {
ResultSet resultSet = preStat.executeQuery();
try {
list = new ArrayList<TestCase>();
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 findTestCaseByService.
@Override
public AnswerList findTestCaseByService(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 testcasestepaction tcsa ON tcsa.TestCase = tc.TestCase AND tcsa.Test = t.Test " + " INNER JOIN appservice ser ON ser.Service = tcsa.Value1 " + " 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;
}
Aggregations