use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseCountryPropertiesDAO method findTestCaseCountryPropertiesByValue1.
@Override
public AnswerList findTestCaseCountryPropertiesByValue1(int testDataLib, String name, String country, String propertyType) {
AnswerList ansList = new AnswerList();
MessageEvent rs;
List<TestListDTO> listOfTests = new ArrayList<TestListDTO>();
StringBuilder query = new StringBuilder();
query.append("select count(*) as total, tccp.property, t.Test, tc.TestCase, t.Description as testDescription, tc.Description as testCaseDescription, tc.Application, ");
query.append("tc.TcActive as Active, tc.`Group`, tc.UsrCreated, tc.`Status` ");
query.append("from testcasecountryproperties tccp ");
query.append("inner join test t on t.test = tccp.test ");
query.append("inner join testcase tc on t.test = tccp.test and t.test = tc.test ");
query.append("inner join testdatalib tdl on tdl.`name` = tccp.value1 and ");
query.append("(tccp.Country = tdl.Country or tdl.country='') and tccp.test = t.test and tccp.testcase = tc.testcase ");
query.append("where tccp.`Type` LIKE ? and tdl.TestDataLibID = ? ");
query.append("and tdl.`Name` LIKE ? and (tdl.Country = ? or tdl.country='') ");
query.append("group by tccp.test, tccp.testcase, tccp.property ");
Connection connection = this.databaseSpring.connect();
try {
PreparedStatement preStat = connection.prepareStatement(query.toString());
try {
preStat.setString(1, propertyType);
preStat.setInt(2, testDataLib);
preStat.setString(3, name);
preStat.setString(4, country);
HashMap<String, TestListDTO> map = new HashMap<String, TestListDTO>();
// the key is the test + ":" +testcasenumber
HashMap<String, List<PropertyListDTO>> auxiliaryMap = new HashMap<String, List<PropertyListDTO>>();
String key, test, testCase;
ResultSet resultSet = preStat.executeQuery();
try {
while (resultSet.next()) {
TestListDTO testList;
TestCaseListDTO testCaseDTO;
List<PropertyListDTO> propertiesList;
test = resultSet.getString("Test");
testCase = resultSet.getString("TestCase");
// gets the info from test cases that match the desired information
if (map.containsKey(test)) {
testList = map.get(test);
} else {
testList = new TestListDTO();
testList.setDescription(resultSet.getString("testDescription"));
testList.setTest(test);
}
// TESTCASE
key = test + ":" + testCase;
if (!auxiliaryMap.containsKey(key)) {
// means that we must associate a new test case with a 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);
propertiesList = new ArrayList<PropertyListDTO>();
} else {
propertiesList = auxiliaryMap.get(key);
}
PropertyListDTO prop = new PropertyListDTO();
prop.setNrCountries(resultSet.getInt("total"));
prop.setPropertyName(resultSet.getString("property"));
propertiesList.add(prop);
// stores the information about the properties
auxiliaryMap.put(key, propertiesList);
}
// assigns the list of tests retrieved by the query to the list
listOfTests = new ArrayList<TestListDTO>(map.values());
// assigns the list of properties to the correct testcaselist
for (TestListDTO list : listOfTests) {
for (TestCaseListDTO cases : list.getTestCaseList()) {
cases.setPropertiesList(auxiliaryMap.get(list.getTest() + ":" + cases.getTestCaseNumber()));
}
}
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.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseCountryPropertiesDAO method create.
@Override
public Answer create(TestCaseCountryProperties object) {
MessageEvent msg = null;
StringBuilder query = new StringBuilder();
query.append("INSERT INTO testcasecountryproperties (`Test`,`TestCase`,`Country`,`Property`,`Description`,`Type`");
query.append(",`Database`,`Value1`,`Value2`,`Length`,`RowLimit`,`Nature`,`RetryNb`,`RetryPeriod`,`CacheExpire`) ");
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.setString(1, object.getTest());
preStat.setString(2, object.getTestCase());
preStat.setString(3, object.getCountry());
preStat.setString(4, object.getProperty());
preStat.setString(5, object.getDescription());
preStat.setString(6, object.getType());
preStat.setString(7, object.getDatabase());
preStat.setString(8, object.getValue1());
preStat.setString(9, object.getValue2());
preStat.setString(10, object.getLength());
preStat.setInt(11, object.getRowLimit());
preStat.setString(12, object.getNature());
preStat.setInt(13, object.getRetryNb());
preStat.setInt(14, object.getRetryPeriod());
preStat.setInt(15, object.getCacheExpire());
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.engine.entity.MessageEvent 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.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseDAO method readDistinctValuesByCriteria.
@Override
public AnswerList<List<String>> readDistinctValuesByCriteria(String system, String test, String searchTerm, Map<String, List<String>> individualSearch, String columnName) {
AnswerList answer = new AnswerList();
MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
List<String> distinctValues = new ArrayList<>();
StringBuilder searchSQL = new StringBuilder();
List<String> individalColumnSearchValues = new ArrayList<String>();
StringBuilder query = new StringBuilder();
query.append("SELECT distinct ");
query.append(columnName);
query.append(" as distinctValues 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 lab.`label` like ?");
searchSQL.append(" or tec.`description` 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(" order by ").append(columnName).append(" asc");
// Debug message on SQL.
if (LOG.isDebugEnabled()) {
LOG.debug("SQL : " + query.toString());
}
try (Connection connection = databaseSpring.connect();
PreparedStatement preStat = connection.prepareStatement(query.toString());
Statement stm = connection.createStatement()) {
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 + "%");
}
for (String individualColumnSearchValue : individalColumnSearchValues) {
preStat.setString(i++, individualColumnSearchValue);
}
try (ResultSet resultSet = preStat.executeQuery();
ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()")) {
// gets the data
while (resultSet.next()) {
distinctValues.add(resultSet.getString("distinctValues") == null ? "" : resultSet.getString("distinctValues"));
}
// get the total number of rows
int nrTotalRows = 0;
if (rowSet != null && rowSet.next()) {
nrTotalRows = rowSet.getInt(1);
}
if (distinctValues.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(distinctValues, nrTotalRows);
} else if (distinctValues.size() <= 0) {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
answer = new AnswerList(distinctValues, nrTotalRows);
} else {
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
answer = new AnswerList(distinctValues, 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()));
}
} catch (Exception e) {
LOG.warn("Unable to execute query : " + e.toString());
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
} finally {
// We always set the result message
answer.setResultMessage(msg);
}
answer.setResultMessage(msg);
answer.setDataList(distinctValues);
return answer;
}
use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.
the class TestCaseDAO method delete.
@Override
public Answer delete(TestCase testCase) {
MessageEvent msg = null;
final String query = "DELETE FROM testcase 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, testCase.getTest());
preStat.setString(2, testCase.getTestCase());
preStat.executeUpdate();
msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "DELETE"));
} 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