Search in sources :

Example 11 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class TestCaseStepDAO method deleteTestCaseStep.

@Override
public void deleteTestCaseStep(TestCaseStep tcs) throws CerberusException {
    boolean throwExcep = false;
    final String query = "DELETE FROM testcasestep WHERE test = ? and testcase = ? and step = ?";
    // 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, tcs.getTest());
            preStat.setString(2, tcs.getTestCase());
            preStat.setInt(3, tcs.getStep());
            throwExcep = preStat.executeUpdate() == 0;
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn("Exception Closing the connection : " + e.toString());
        }
    }
    if (throwExcep) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 12 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class ParameterDAO method findAllParameter.

@Override
public List<Parameter> findAllParameter() throws CerberusException {
    boolean throwExep = true;
    List<Parameter> result = null;
    Parameter paramet;
    final String query = "SELECT * FROM parameter p ";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                result = new ArrayList<Parameter>();
                while (resultSet.next()) {
                    String system = resultSet.getString("system");
                    String param = resultSet.getString("param");
                    String value = resultSet.getString("value");
                    String desc = resultSet.getString("description");
                    paramet = factoryParameter.create(system, param, value, desc);
                    result.add(paramet);
                    throwExep = false;
                }
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwExep) {
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND);
        mes.setDescription(mes.getDescription() + " Parameter table empty.");
        throw new CerberusException(mes);
    }
    return result;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Parameter(org.cerberus.crud.entity.Parameter) IFactoryParameter(org.cerberus.crud.factory.IFactoryParameter) FactoryParameter(org.cerberus.crud.factory.impl.FactoryParameter) PreparedStatement(java.sql.PreparedStatement)

Example 13 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class ParameterDAO method findAllParameterWithSystem1.

@Override
public List<Parameter> findAllParameterWithSystem1(String mySystem, String mySystem1) throws CerberusException {
    boolean throwExep = true;
    List<Parameter> result = null;
    Parameter paramet;
    StringBuilder mySQL = new StringBuilder();
    mySQL.append("SELECT par.param param, par.`value` valC, par2.`value` valS, par2.description FROM parameter par ");
    mySQL.append("LEFT OUTER JOIN ( SELECT * from parameter par2 WHERE par2.system= ? ) as par2 ON par.param = par.param ");
    mySQL.append(" WHERE par.system= ?; ");
    final String query = mySQL.toString();
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        preStat.setString(1, mySystem1);
        preStat.setString(1, mySystem);
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                result = new ArrayList<Parameter>();
                while (resultSet.next()) {
                    String param = resultSet.getString("param");
                    String valueC = resultSet.getString("valC");
                    String valueS = resultSet.getString("valS");
                    String desc = resultSet.getString("description");
                    paramet = factoryParameter.create(param, "", valueC, desc, mySystem, valueS);
                    result.add(paramet);
                    throwExep = false;
                }
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwExep) {
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND);
        mes.setDescription(mes.getDescription() + " Parameter table empty.");
        throw new CerberusException(mes);
    }
    return result;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Parameter(org.cerberus.crud.entity.Parameter) IFactoryParameter(org.cerberus.crud.factory.IFactoryParameter) FactoryParameter(org.cerberus.crud.factory.impl.FactoryParameter) PreparedStatement(java.sql.PreparedStatement)

Example 14 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class SqlLibraryDAO method createSqlLibrary.

@Override
public void createSqlLibrary(SqlLibrary sqlLibrary) throws CerberusException {
    boolean throwExcep = false;
    StringBuilder query = new StringBuilder();
    query.append("INSERT INTO sqllibrary (`type`, `name`, `script`, `description`, `database`) ");
    query.append("VALUES (?,?,?,?,?)");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, sqlLibrary.getType());
            preStat.setString(2, sqlLibrary.getName());
            preStat.setString(3, sqlLibrary.getScript());
            preStat.setString(4, sqlLibrary.getDescription());
            preStat.setString(5, sqlLibrary.getDatabase());
            preStat.executeUpdate();
            throwExcep = false;
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwExcep) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 15 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class TestCaseExecutionDAO method findExecutionbyCriteria1.

@Override
public List<TestCaseExecution> findExecutionbyCriteria1(String dateLimit, String test, String testCase, String application, String country, String environment, String controlStatus, String status) throws CerberusException {
    List<TestCaseExecution> myTestCaseExecutions = null;
    TestCaseExecution Execution;
    boolean throwException = false;
    final String query = new StringBuffer("SELECT exe.*, tec.*, app.* FROM testcaseexecution exe ").append("LEFT JOIN testcase tec ON exe.test = tec.test AND exe.testcase = tec.testcase ").append("LEFT JOIN application app ON exe.application = app.application ").append("WHERE exe.start > ? AND exe.test LIKE ? AND exe.testcase LIKE ? AND exe.environment LIKE ? ").append("AND exe.country LIKE ? AND exe.application LIKE ? AND exe.controlstatus LIKE ? ").append("AND exe.status LIKE ?").toString();
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        preStat.setString(1, dateLimit);
        preStat.setString(2, test);
        preStat.setString(3, testCase);
        preStat.setString(4, environment);
        preStat.setString(5, country);
        preStat.setString(6, application);
        preStat.setString(7, controlStatus);
        preStat.setString(8, status);
        try (ResultSet resultSet = preStat.executeQuery()) {
            if (!(resultSet.first())) {
                throwException = true;
            } else {
                myTestCaseExecutions = new ArrayList<TestCaseExecution>();
                do {
                    Execution = this.loadWithDependenciesFromResultSet(resultSet);
                    myTestCaseExecutions.add(Execution);
                } while (resultSet.next());
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        }
    } catch (Exception exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    }
    if (throwException) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA));
    }
    return myTestCaseExecutions;
}
Also used : IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) CerberusException(org.cerberus.exception.CerberusException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) ResultSet(java.sql.ResultSet)

Aggregations

CerberusException (org.cerberus.exception.CerberusException)159 MessageEvent (org.cerberus.engine.entity.MessageEvent)64 MessageGeneral (org.cerberus.engine.entity.MessageGeneral)58 ApplicationContext (org.springframework.context.ApplicationContext)58 JSONObject (org.json.JSONObject)54 JSONException (org.json.JSONException)53 Connection (java.sql.Connection)48 SQLException (java.sql.SQLException)48 PreparedStatement (java.sql.PreparedStatement)47 AnswerItem (org.cerberus.util.answer.AnswerItem)41 ArrayList (java.util.ArrayList)37 IOException (java.io.IOException)35 PolicyFactory (org.owasp.html.PolicyFactory)35 ILogEventService (org.cerberus.crud.service.ILogEventService)34 Answer (org.cerberus.util.answer.Answer)34 ServletException (javax.servlet.ServletException)26 ResultSet (java.sql.ResultSet)18 TestCase (org.cerberus.crud.entity.TestCase)16 JSONArray (org.json.JSONArray)16 HashMap (java.util.HashMap)12