Search in sources :

Example 1 with PropertyListDTO

use of org.cerberus.dto.PropertyListDTO 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;
}
Also used : PropertyListDTO(org.cerberus.dto.PropertyListDTO) 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) ResultSet(java.sql.ResultSet) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 PropertyListDTO (org.cerberus.dto.PropertyListDTO)1 TestCaseListDTO (org.cerberus.dto.TestCaseListDTO)1 TestListDTO (org.cerberus.dto.TestListDTO)1 MessageEvent (org.cerberus.engine.entity.MessageEvent)1 AnswerList (org.cerberus.util.answer.AnswerList)1