Search in sources :

Example 6 with TestCaseListDTO

use of org.cerberus.dto.TestCaseListDTO 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;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) TestCaseListDTO(org.cerberus.dto.TestCaseListDTO) TestListDTO(org.cerberus.dto.TestListDTO) TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) ResultSet(java.sql.ResultSet)

Aggregations

TestCaseListDTO (org.cerberus.dto.TestCaseListDTO)6 TestListDTO (org.cerberus.dto.TestListDTO)6 AnswerList (org.cerberus.util.answer.AnswerList)6 ArrayList (java.util.ArrayList)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 HashMap (java.util.HashMap)3 MessageEvent (org.cerberus.engine.entity.MessageEvent)3 TestCase (org.cerberus.crud.entity.TestCase)2 IFactoryTestCase (org.cerberus.crud.factory.IFactoryTestCase)2 ITestCaseService (org.cerberus.crud.service.ITestCaseService)2 AnswerItem (org.cerberus.util.answer.AnswerItem)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 List (java.util.List)1 PropertyListDTO (org.cerberus.dto.PropertyListDTO)1