Search in sources :

Example 1 with TestListDTO

use of org.cerberus.dto.TestListDTO 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)

Example 2 with TestListDTO

use of org.cerberus.dto.TestListDTO 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;
}
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)

Example 3 with TestListDTO

use of org.cerberus.dto.TestListDTO in project cerberus-source by cerberustesting.

the class TestCaseService method findTestCasesThatUseService.

@Override
public AnswerList findTestCasesThatUseService(String service) {
    AnswerList testCaseByServiceByDataLib = testCaseDao.findTestCaseByServiceByDataLib(service);
    AnswerList testCaseByService = testCaseDao.findTestCaseByService(service);
    List<TestListDTO> listOfTestCaseByDataLib = testCaseByServiceByDataLib.getDataList();
    List<TestListDTO> listOfTestCaseByService = testCaseByService.getDataList();
    List<TestListDTO> newTestCase = new ArrayList<TestListDTO>();
    if (!listOfTestCaseByDataLib.isEmpty()) {
        for (TestListDTO datalibList : listOfTestCaseByDataLib) {
            for (TestListDTO serviceList : listOfTestCaseByService) {
                if (datalibList.getTest().equals(serviceList.getTest())) {
                    List<TestCaseListDTO> testCaseDataLibList = datalibList.getTestCaseList();
                    for (TestCaseListDTO testCaseService : serviceList.getTestCaseList()) {
                        if (!containsTestCase(testCaseDataLibList, testCaseService.getTestCaseNumber())) {
                            testCaseDataLibList.add(testCaseService);
                        }
                    }
                } else {
                    newTestCase.add(serviceList);
                }
            }
        }
        listOfTestCaseByDataLib.addAll(newTestCase);
        testCaseByServiceByDataLib.setDataList(listOfTestCaseByDataLib);
        return testCaseByServiceByDataLib;
    } else {
        return testCaseByService;
    }
}
Also used : TestCaseListDTO(org.cerberus.dto.TestCaseListDTO) AnswerList(org.cerberus.util.answer.AnswerList) TestListDTO(org.cerberus.dto.TestListDTO) ArrayList(java.util.ArrayList)

Example 4 with TestListDTO

use of org.cerberus.dto.TestListDTO in project cerberus-source by cerberustesting.

the class ReadAppService method getTestCasesUsingService.

/**
 * Auxiliary method that extracts the list of test cases that are currently
 * using one service.
 *
 * @param appContext - context object used to get the required beans
 * @param service - identifier of the service
 * @return an answer item containing the information about the test cases
 * that use the entry
 * @throws JSONException
 */
private AnswerItem getTestCasesUsingService(String service, ApplicationContext appContext) throws JSONException {
    JSONObject object = new JSONObject();
    JSONArray objectArray = new JSONArray();
    AnswerItem ansItem = new AnswerItem();
    ITestCaseService tcService = appContext.getBean(ITestCaseService.class);
    AnswerList ansList = tcService.findTestCasesThatUseService(service);
    // if the response is success then we can iterate and search for the data
    if (ansList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        List<TestListDTO> listDTO = ansList.getDataList();
        for (TestListDTO l : listDTO) {
            JSONArray jsonArray = new JSONArray();
            JSONArray arrTestCase = new JSONArray();
            for (TestCaseListDTO testCase : l.getTestCaseList()) {
                JSONObject jsonTestCase = new JSONObject();
                jsonTestCase.put("TestCaseNumber", testCase.getTestCaseNumber());
                jsonTestCase.put("TestCaseDescription", testCase.getTestCaseDescription());
                jsonTestCase.put("Creator", testCase.getCreator());
                jsonTestCase.put("Active", testCase.isIsActive());
                jsonTestCase.put("Status", testCase.getStatus());
                jsonTestCase.put("Group", testCase.getGroup());
                jsonTestCase.put("Application", testCase.getApplication());
                arrTestCase.put(jsonTestCase);
            }
            // test details
            jsonArray.put(l.getTest());
            jsonArray.put(l.getDescription());
            jsonArray.put(l.getTestCaseList().size());
            jsonArray.put(arrTestCase);
            // test case details
            objectArray.put(jsonArray);
        }
    }
    object.put("TestCasesList", objectArray);
    ansItem.setItem(object);
    ansItem.setResultMessage(ansList.getResultMessage());
    return ansItem;
}
Also used : TestCaseListDTO(org.cerberus.dto.TestCaseListDTO) AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) TestListDTO(org.cerberus.dto.TestListDTO) JSONArray(org.json.JSONArray) ITestCaseService(org.cerberus.crud.service.ITestCaseService) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 5 with TestListDTO

use of org.cerberus.dto.TestListDTO in project cerberus-source by cerberustesting.

the class ReadTestDataLib method getTestCasesUsingTestDataLib.

/**
 * Auxiliary method that extracts the list of test cases that are currently
 * using one test lib.
 *
 * @param appContext - context object used to get the required beans
 * @param testDataLibId - identifier of the library entry
 * @param name - name of the library entry
 * @param country - country of the library entry
 * @return an answer item containing the information about the test cases
 * that use the entry
 * @throws JSONException
 */
private AnswerItem getTestCasesUsingTestDataLib(int testDataLibId, String name, String country, ApplicationContext appContext, boolean userHasPermissions) throws JSONException {
    JSONObject object = new JSONObject();
    JSONArray objectArray = new JSONArray();
    AnswerItem ansItem = new AnswerItem();
    ITestCaseService tcService = appContext.getBean(ITestCaseService.class);
    AnswerList ansList = tcService.findTestCasesThatUseTestDataLib(testDataLibId, name, country);
    // if the response is success then we can iterate and search for the data
    if (ansList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        List<TestListDTO> listDTO = ansList.getDataList();
        for (TestListDTO l : listDTO) {
            JSONArray jsonArray = new JSONArray();
            JSONArray arrTestCase = new JSONArray();
            for (TestCaseListDTO testCase : l.getTestCaseList()) {
                JSONObject jsonTestCase = new JSONObject();
                jsonTestCase.put("TestCaseNumber", testCase.getTestCaseNumber());
                jsonTestCase.put("TestCaseDescription", testCase.getTestCaseDescription());
                jsonTestCase.put("Creator", testCase.getCreator());
                jsonTestCase.put("Active", testCase.isIsActive());
                jsonTestCase.put("Status", testCase.getStatus());
                jsonTestCase.put("Group", testCase.getGroup());
                jsonTestCase.put("Application", testCase.getApplication());
                jsonTestCase.put("NrProperties", testCase.getPropertiesList().size());
                arrTestCase.put(jsonTestCase);
            }
            // test details
            jsonArray.put(l.getTest());
            jsonArray.put(l.getDescription());
            jsonArray.put(l.getTestCaseList().size());
            jsonArray.put(arrTestCase);
            // test case details
            objectArray.put(jsonArray);
        }
    }
    object.put("TestCasesList", objectArray);
    object.put("hasPermissions", userHasPermissions);
    ansItem.setItem(object);
    ansItem.setResultMessage(ansList.getResultMessage());
    return ansItem;
}
Also used : TestCaseListDTO(org.cerberus.dto.TestCaseListDTO) AnswerList(org.cerberus.util.answer.AnswerList) JSONObject(org.json.JSONObject) TestListDTO(org.cerberus.dto.TestListDTO) JSONArray(org.json.JSONArray) ITestCaseService(org.cerberus.crud.service.ITestCaseService) AnswerItem(org.cerberus.util.answer.AnswerItem)

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