Search in sources :

Example 46 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class TestCaseStepActionDAO method update.

@Override
public void update(TestCaseStepAction testCaseStepAction) throws CerberusException {
    boolean throwExcep = false;
    final String query = new StringBuilder("UPDATE `testcasestepaction` ").append("SET ").append("`Test` = ?, ").append("`TestCase` = ?, ").append("`Step` = ?, ").append("`Sequence` = ?, ").append("`Sort` = ?, ").append("`ConditionOper` = ?, ").append("`ConditionVal1` = ?, ").append("`ConditionVal2` = ?, ").append("`Action` = ?, ").append("`Value1` = ?, ").append("`Value2` = ?, ").append("`ForceExeStatus` = ?, ").append("`Description` = ?, ").append("`ScreenshotFilename` = ? ").append("WHERE `Test` = ? AND `TestCase` = ? AND `Step` = ? AND `Sequence` = ? ").toString();
    LOG.debug("SQL " + query);
    LOG.debug("SQL.param.conditionOper " + testCaseStepAction.getConditionOper());
    LOG.debug("SQL.param.conditionVal1 " + testCaseStepAction.getConditionVal1());
    LOG.debug("SQL.param.conditionVal2 " + testCaseStepAction.getConditionVal2());
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            int i = 1;
            preStat.setString(i++, testCaseStepAction.getTest());
            preStat.setString(i++, testCaseStepAction.getTestCase());
            preStat.setInt(i++, testCaseStepAction.getStep());
            preStat.setInt(i++, testCaseStepAction.getSequence());
            preStat.setInt(i++, testCaseStepAction.getSort());
            preStat.setString(i++, testCaseStepAction.getConditionOper());
            preStat.setString(i++, testCaseStepAction.getConditionVal1());
            preStat.setString(i++, testCaseStepAction.getConditionVal2());
            preStat.setString(i++, testCaseStepAction.getAction());
            preStat.setString(i++, testCaseStepAction.getValue1());
            preStat.setString(i++, testCaseStepAction.getValue2());
            preStat.setString(i++, testCaseStepAction.getForceExeStatus());
            preStat.setString(i++, testCaseStepAction.getDescription());
            preStat.setString(i++, testCaseStepAction.getScreenshotFilename());
            preStat.setString(i++, testCaseStepAction.getTest());
            preStat.setString(i++, testCaseStepAction.getTestCase());
            preStat.setInt(i++, testCaseStepAction.getStep());
            preStat.setInt(i++, testCaseStepAction.getSequence());
            preStat.executeUpdate();
            throwExcep = false;
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            if (preStat != null) {
                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 47 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class TestCaseStepDAO method updateTestCaseStep.

@Override
public void updateTestCaseStep(TestCaseStep tcs) throws CerberusException {
    boolean throwExcep = false;
    StringBuilder query = new StringBuilder();
    query.append("UPDATE testcasestep SET ");
    query.append(" `Description` = ?, `useStep`=? ");
    if (!StringUtil.isNullOrEmpty(tcs.getUseStepTest())) {
        query.append(",`useStepTest`=? ");
    }
    if (!StringUtil.isNullOrEmpty(tcs.getUseStepTestCase())) {
        query.append(",`useStepTestCase`=? ");
    }
    if (tcs.getUseStepStep() >= 0) {
        query.append(",`useStepStep`=? ");
    }
    query.append(",`inlibrary` = ?, `Sort` = ?, `loop` = ?, `conditionOper` = ?, `conditionVal1` = ?, `conditionVal2` = ? WHERE Test = ? AND TestCase = ? AND step = ?");
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query.toString());
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            int i = 1;
            preStat.setString(i++, tcs.getDescription());
            preStat.setString(i++, tcs.getUseStep() == null ? "N" : tcs.getUseStep());
            if (!StringUtil.isNullOrEmpty(tcs.getUseStepTest())) {
                preStat.setString(i++, tcs.getUseStepTest());
            }
            if (!StringUtil.isNullOrEmpty(tcs.getUseStepTestCase())) {
                preStat.setString(i++, tcs.getUseStepTestCase());
            }
            if (tcs.getUseStepStep() >= 0) {
                preStat.setInt(i++, tcs.getUseStepStep());
            }
            preStat.setString(i++, tcs.getInLibrary() == null ? "N" : tcs.getInLibrary());
            preStat.setInt(i++, tcs.getSort());
            preStat.setString(i++, tcs.getLoop() == null ? "" : tcs.getLoop());
            preStat.setString(i++, tcs.getConditionOper() == null ? "" : tcs.getConditionOper());
            preStat.setString(i++, tcs.getConditionVal1() == null ? "" : tcs.getConditionVal1());
            preStat.setString(i++, tcs.getConditionVal2() == null ? "" : tcs.getConditionVal2());
            preStat.setString(i++, tcs.getTest());
            preStat.setString(i++, tcs.getTestCase());
            preStat.setInt(i++, tcs.getStep());
            preStat.executeUpdate();
            throwExcep = false;
        } 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 48 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class TestDAO method createTest.

@Override
public boolean createTest(Test test) throws CerberusException {
    boolean res = false;
    final String sql = "INSERT INTO test (Test, Description, Active, Automated, TDateCrea) VALUES (?, ?, ?, ?, ?)";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(sql);
        try {
            preStat.setString(1, test.getTest());
            preStat.setString(2, test.getDescription());
            preStat.setString(3, test.getActive());
            preStat.setString(4, test.getAutomated());
            preStat.setString(5, DateUtil.getMySQLTimestampTodayDeltaMinutes(0));
            res = preStat.executeUpdate() > 0;
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.GUI_ERROR_INSERTING_DATA);
            mes.setDescription(mes.getDescription().replace("%DETAILS%", exception.toString()));
            throw new CerberusException(mes);
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.GUI_ERROR_INSERTING_DATA);
        mes.setDescription(mes.getDescription().replace("%DETAILS%", exception.toString()));
        throw new CerberusException(mes);
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    return res;
}
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 49 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class CampaignParameterDAO method findAll.

@Override
public List<CampaignParameter> findAll() throws CerberusException {
    boolean throwEx = false;
    final String query = "SELECT * FROM campaignparameter c";
    List<CampaignParameter> campaignParameterList = new ArrayList<CampaignParameter>();
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        try (ResultSet resultSet = preStat.executeQuery()) {
            while (resultSet.next()) {
                campaignParameterList.add(this.loadFromResultSet(resultSet));
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
            campaignParameterList = null;
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
        campaignParameterList = null;
    }
    if (throwEx) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
    }
    return campaignParameterList;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IFactoryCampaignParameter(org.cerberus.crud.factory.IFactoryCampaignParameter) CampaignParameter(org.cerberus.crud.entity.CampaignParameter)

Example 50 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class CampaignParameterDAO method findCampaignParametersByCampaign.

@Override
public List<CampaignParameter> findCampaignParametersByCampaign(String campaign) throws CerberusException {
    boolean throwEx = false;
    final String query = "SELECT * FROM campaignparameter c WHERE c.campaign = ?";
    List<CampaignParameter> campaignParameterList = new ArrayList<CampaignParameter>();
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        preStat.setString(1, campaign);
        try (ResultSet resultSet = preStat.executeQuery()) {
            while (resultSet.next()) {
                campaignParameterList.add(this.loadFromResultSet(resultSet));
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
            campaignParameterList = null;
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
        campaignParameterList = null;
    }
    if (throwEx) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
    }
    return campaignParameterList;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IFactoryCampaignParameter(org.cerberus.crud.factory.IFactoryCampaignParameter) CampaignParameter(org.cerberus.crud.entity.CampaignParameter)

Aggregations

MessageGeneral (org.cerberus.engine.entity.MessageGeneral)71 CerberusException (org.cerberus.exception.CerberusException)61 Connection (java.sql.Connection)46 PreparedStatement (java.sql.PreparedStatement)46 SQLException (java.sql.SQLException)46 ResultSet (java.sql.ResultSet)18 ArrayList (java.util.ArrayList)12 Date (java.util.Date)10 TestCase (org.cerberus.crud.entity.TestCase)10 MessageEvent (org.cerberus.engine.entity.MessageEvent)8 AnswerItem (org.cerberus.util.answer.AnswerItem)7 Timestamp (java.sql.Timestamp)5 CerberusEventException (org.cerberus.exception.CerberusEventException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 CountryEnvParam (org.cerberus.crud.entity.CountryEnvParam)4 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)4 TestCaseExecutionQueue (org.cerberus.crud.entity.TestCaseExecutionQueue)4 IOException (java.io.IOException)3 CampaignParameter (org.cerberus.crud.entity.CampaignParameter)3 IFactoryCampaignParameter (org.cerberus.crud.factory.IFactoryCampaignParameter)3