Search in sources :

Example 21 with TestCaseLabel

use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.

the class FactoryTestCaseLabel method create.

@Override
public TestCaseLabel create(Integer id, String test, String testCase, Integer labelId, String usrCreated, Timestamp dateCreated, String usrModif, Timestamp dateModif, Label label) {
    TestCaseLabel testCaseLabel = new TestCaseLabel();
    testCaseLabel.setDateCreated(dateCreated);
    testCaseLabel.setDateModif(dateModif);
    testCaseLabel.setId(id);
    testCaseLabel.setLabelId(labelId);
    testCaseLabel.setTest(test);
    testCaseLabel.setTestcase(testCase);
    testCaseLabel.setUsrCreated(usrCreated);
    testCaseLabel.setUsrModif(usrModif);
    testCaseLabel.setLabel(label);
    return testCaseLabel;
}
Also used : TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) IFactoryTestCaseLabel(org.cerberus.crud.factory.IFactoryTestCaseLabel)

Example 22 with TestCaseLabel

use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.

the class TestCaseLabelDAO method readByKeyTech.

@Override
public AnswerItem<TestCaseLabel> readByKeyTech(Integer id) {
    AnswerItem<TestCaseLabel> ans = new AnswerItem();
    TestCaseLabel result = null;
    final String query = "SELECT * FROM `testcaselabel` tel WHERE `id` = ?";
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
        LOG.debug("SQL.param.label : " + id);
    }
    try (Connection connection = databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        // prepare and execute query
        preStat.setInt(1, id);
        try (ResultSet resultSet = preStat.executeQuery()) {
            // parse query
            if (resultSet.first()) {
                result = loadFromResultSet(resultSet, null);
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
                ans.setItem(result);
            } else {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
            }
        } 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 readByKey TestCaseLabel: " + e.getMessage());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
    } finally {
        ans.setResultMessage(msg);
    }
    return ans;
}
Also used : SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) IFactoryTestCaseLabel(org.cerberus.crud.factory.IFactoryTestCaseLabel) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) AnswerItem(org.cerberus.util.answer.AnswerItem) SQLException(java.sql.SQLException)

Example 23 with TestCaseLabel

use of org.cerberus.crud.entity.TestCaseLabel in project cerberus-source by cerberustesting.

the class TestCaseLabelDAO method readByTestTestCase.

@Override
public AnswerList readByTestTestCase(String test, String testCase) {
    AnswerList response = new AnswerList();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    List<TestCaseLabel> objectList = new ArrayList<>();
    StringBuilder query = new StringBuilder();
    // SQL_CALC_FOUND_ROWS allows to retrieve the total number of columns by disrearding the limit clauses that
    // were applied -- used for pagination p
    query.append("SELECT SQL_CALC_FOUND_ROWS * FROM testcaselabel tel ");
    query.append(" LEFT OUTER JOIN label lab on lab.id = tel.labelId  ");
    query.append(" WHERE 1=1");
    if (!Strings.isNullOrEmpty(test)) {
        query.append(" AND tel.test = ?");
    }
    if (testCase != null) {
        query.append(" AND tel.testcase = ?");
    }
    // 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 (!Strings.isNullOrEmpty(test)) {
            preStat.setString(i++, test);
        }
        if (testCase != null) {
            preStat.setString(i++, testCase);
        }
        try (ResultSet resultSet = preStat.executeQuery();
            ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()")) {
            // gets the data
            while (resultSet.next()) {
                Label label = labelDAO.loadFromResultSet(resultSet);
                TestCaseLabel tcl = this.loadFromResultSet(resultSet, label);
                objectList.add(tcl);
            }
            // get the total number of rows
            int nrTotalRows = 0;
            if (rowSet != null && rowSet.next()) {
                nrTotalRows = rowSet.getInt(1);
            }
            if (objectList.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));
                response = new AnswerList(objectList, nrTotalRows);
            } else if (objectList.size() <= 0) {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                response = new AnswerList(objectList, nrTotalRows);
            } else {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
                response = new AnswerList(objectList, nrTotalRows);
            }
            response.setDataList(objectList);
        } 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 readByTestTestCase TestCaseLabel: " + e.getMessage());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
    } finally {
        response.setResultMessage(msg);
    }
    return response;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) IFactoryTestCaseLabel(org.cerberus.crud.factory.IFactoryTestCaseLabel) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) Label(org.cerberus.crud.entity.Label) IFactoryTestCaseLabel(org.cerberus.crud.factory.IFactoryTestCaseLabel) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Aggregations

TestCaseLabel (org.cerberus.crud.entity.TestCaseLabel)23 ArrayList (java.util.ArrayList)17 JSONObject (org.json.JSONObject)16 ITestCaseLabelService (org.cerberus.crud.service.ITestCaseLabelService)14 IFactoryTestCaseLabel (org.cerberus.crud.factory.IFactoryTestCaseLabel)12 MessageEvent (org.cerberus.engine.entity.MessageEvent)12 AnswerItem (org.cerberus.util.answer.AnswerItem)12 AnswerList (org.cerberus.util.answer.AnswerList)9 JSONArray (org.json.JSONArray)9 List (java.util.List)8 Answer (org.cerberus.util.answer.Answer)8 TestCase (org.cerberus.crud.entity.TestCase)6 PolicyFactory (org.owasp.html.PolicyFactory)6 ApplicationContext (org.springframework.context.ApplicationContext)6 TestCaseCountry (org.cerberus.crud.entity.TestCaseCountry)5 ILogEventService (org.cerberus.crud.service.ILogEventService)5 ITestCaseCountryService (org.cerberus.crud.service.ITestCaseCountryService)5 ITestCaseService (org.cerberus.crud.service.ITestCaseService)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4