Search in sources :

Example 1 with TestCaseCountryProperties

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

the class TestCaseCountryPropertiesDAO method createTestCaseCountryPropertiesBatch.

@Override
public Answer createTestCaseCountryPropertiesBatch(List<TestCaseCountryProperties> listOfPropertiesToInsert) {
    Answer answer = new Answer();
    MessageEvent rs = null;
    StringBuilder query = new StringBuilder();
    query.append("INSERT INTO testcasecountryproperties (`Test`,`TestCase`,`Country`,`Property` , `Description`, `Type`");
    query.append(",`Database`,`Value1`,`Value2`,`Length`,`RowLimit`,`Nature`,`RetryNb`,`RetryPeriod`) ");
    query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            for (TestCaseCountryProperties prop : listOfPropertiesToInsert) {
                preStat.setString(1, prop.getTest());
                preStat.setString(2, prop.getTestCase());
                preStat.setString(3, prop.getCountry());
                preStat.setString(4, prop.getProperty());
                preStat.setString(5, prop.getDescription());
                preStat.setString(6, prop.getType());
                preStat.setString(7, prop.getDatabase());
                preStat.setString(8, prop.getValue1());
                preStat.setString(9, prop.getValue2());
                preStat.setString(10, prop.getLength());
                preStat.setInt(11, prop.getRowLimit());
                preStat.setString(12, prop.getNature());
                preStat.setInt(13, prop.getRetryNb());
                preStat.setInt(14, prop.getRetryPeriod());
                preStat.addBatch();
            }
            // executes the batch
            preStat.executeBatch();
            int[] affectedRows = preStat.executeBatch();
            // verify if some of the statements failed
            boolean someFailed = ArrayUtils.contains(affectedRows, 0) || ArrayUtils.contains(affectedRows, Statement.EXECUTE_FAILED);
            if (someFailed == false) {
                rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                rs.setDescription(rs.getDescription().replace("%ITEM%", "Property").replace("%OPERATION%", "CREATE"));
            } else {
                rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
                rs.setDescription(rs.getDescription().replace("%ITEM%", "Property").replace("%OPERATION%", "CREATE").replace("%REASON%", "Some problem occurred while creating the new property! "));
            }
        } catch (SQLException exception) {
            rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            rs.setDescription(rs.getDescription().replace("%DESCRIPTION%", "It was not possible to update table."));
            LOG.error("Unable to execute query : " + exception.toString());
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException exception) {
        rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        rs.setDescription(rs.getDescription().replace("%DESCRIPTION%", "It was not possible to update table."));
        LOG.error("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (!this.databaseSpring.isOnTransaction()) {
                if (connection != null) {
                    connection.close();
                }
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    answer.setResultMessage(rs);
    return answer;
}
Also used : Answer(org.cerberus.util.answer.Answer) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 2 with TestCaseCountryProperties

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

the class TestCaseCountryPropertiesDAO method findListOfPropertyPerTestTestCase.

@Override
public List<TestCaseCountryProperties> findListOfPropertyPerTestTestCase(String test, String testcase) {
    List<TestCaseCountryProperties> list = null;
    final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ?";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, test);
            preStat.setString(2, testcase);
            ResultSet resultSet = preStat.executeQuery();
            try {
                list = new ArrayList<TestCaseCountryProperties>();
                while (resultSet.next()) {
                    String country = resultSet.getString("country");
                    String property = resultSet.getString("property");
                    String description = resultSet.getString("description");
                    String type = resultSet.getString("type");
                    String database = resultSet.getString("database");
                    String value1 = resultSet.getString("value1");
                    String value2 = resultSet.getString("value2");
                    String length = resultSet.getString("length");
                    int rowLimit = resultSet.getInt("rowLimit");
                    String nature = resultSet.getString("nature");
                    int retryNb = resultSet.getInt("RetryNb");
                    int retryPeriod = resultSet.getInt("RetryPeriod");
                    int cacheExpire = resultSet.getInt("CacheExpire");
                    list.add(factoryTestCaseCountryProperties.create(test, testcase, country, property, description, type, database, value1, value2, length, rowLimit, nature, retryNb, retryPeriod, cacheExpire));
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } 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 exception) {
            LOG.warn(exception.toString());
        }
    }
    return list;
}
Also used : TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 3 with TestCaseCountryProperties

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

the class TestCaseCountryPropertiesDAO method findListOfPropertyPerTestTestCaseCountry.

@Override
public List<TestCaseCountryProperties> findListOfPropertyPerTestTestCaseCountry(String test, String testcase, String country) {
    List<TestCaseCountryProperties> list = null;
    final String query = "SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ? AND country = ?";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
        LOG.debug("SQL.param.test : " + test);
        LOG.debug("SQL.param.testcase : " + testcase);
        LOG.debug("SQL.param.country : " + country);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, test);
            preStat.setString(2, testcase);
            preStat.setString(3, country);
            ResultSet resultSet = preStat.executeQuery();
            try {
                list = new ArrayList<TestCaseCountryProperties>();
                while (resultSet.next()) {
                    String property = resultSet.getString("property");
                    String description = resultSet.getString("description");
                    String type = resultSet.getString("type");
                    String database = resultSet.getString("database");
                    String value1 = resultSet.getString("value1");
                    String value2 = resultSet.getString("value2");
                    String length = resultSet.getString("length");
                    int rowLimit = resultSet.getInt("rowLimit");
                    String nature = resultSet.getString("nature");
                    int retryNb = resultSet.getInt("RetryNb");
                    int retryPeriod = resultSet.getInt("RetryPeriod");
                    int cacheExpire = resultSet.getInt("CacheExpire");
                    list.add(factoryTestCaseCountryProperties.create(test, testcase, country, property, description, type, database, value1, value2, length, rowLimit, nature, retryNb, retryPeriod, cacheExpire));
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } 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(e.toString());
        }
    }
    return list;
}
Also used : TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 4 with TestCaseCountryProperties

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

the class TestCaseCountryPropertiesDAO method findDistinctPropertiesOfTestCase.

@Override
public List<TestCaseCountryProperties> findDistinctPropertiesOfTestCase(String test, String testcase) {
    List<TestCaseCountryProperties> listProperties = null;
    final StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM testcasecountryproperties WHERE test = ? AND testcase = ?");
    query.append(" group by HEX(`property`), `type`, `database`, HEX(`value1`) ,  HEX(`value2`) , `length`, `rowlimit`, `nature`");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, test);
            preStat.setString(2, testcase);
            ResultSet resultSet = preStat.executeQuery();
            try {
                listProperties = new ArrayList<TestCaseCountryProperties>();
                while (resultSet.next()) {
                    String country = resultSet.getString("country");
                    String property = resultSet.getString("property");
                    String description = resultSet.getString("description");
                    String type = resultSet.getString("type");
                    String database = resultSet.getString("database");
                    String value1 = resultSet.getString("value1");
                    String value2 = resultSet.getString("value2");
                    String length = resultSet.getString("length");
                    int rowLimit = resultSet.getInt("rowLimit");
                    String nature = resultSet.getString("nature");
                    int retryNb = resultSet.getInt("RetryNb");
                    int retryPeriod = resultSet.getInt("RetryPeriod");
                    int cacheExpire = resultSet.getInt("CacheExpire");
                    listProperties.add(factoryTestCaseCountryProperties.create(test, testcase, country, property, description, type, database, value1, value2, length, rowLimit, nature, retryNb, retryPeriod, cacheExpire));
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
            } finally {
                resultSet.close();
            }
        } 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(e.toString());
        }
    }
    return listProperties;
}
Also used : TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 5 with TestCaseCountryProperties

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

the class FactoryTestCaseCountryProperties method create.

@Override
public TestCaseCountryProperties create(String test, String testCase, String country, String property, String description, String type, String database, String value1, String value2, String length, int rowLimit, String nature, int retryNb, int retryPeriod, int cacheExpire) {
    TestCaseCountryProperties testCaseCountryProperties = new TestCaseCountryProperties();
    testCaseCountryProperties.setTest(test);
    testCaseCountryProperties.setTestCase(testCase);
    testCaseCountryProperties.setCountry(country);
    testCaseCountryProperties.setProperty(property);
    testCaseCountryProperties.setDescription(description == null ? "" : description);
    testCaseCountryProperties.setType(type);
    testCaseCountryProperties.setDatabase(database);
    testCaseCountryProperties.setValue1(value1);
    testCaseCountryProperties.setValue2(value2);
    testCaseCountryProperties.setLength(length);
    testCaseCountryProperties.setRowLimit(rowLimit);
    testCaseCountryProperties.setNature(nature);
    testCaseCountryProperties.setRetryNb(retryNb);
    testCaseCountryProperties.setRetryPeriod(retryPeriod);
    testCaseCountryProperties.setCacheExpire(cacheExpire);
    return testCaseCountryProperties;
}
Also used : IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties)

Aggregations

TestCaseCountryProperties (org.cerberus.crud.entity.TestCaseCountryProperties)33 ArrayList (java.util.ArrayList)19 IFactoryTestCaseCountryProperties (org.cerberus.crud.factory.IFactoryTestCaseCountryProperties)13 MessageEvent (org.cerberus.engine.entity.MessageEvent)12 TestCase (org.cerberus.crud.entity.TestCase)11 TestCaseStep (org.cerberus.crud.entity.TestCaseStep)11 JSONObject (org.json.JSONObject)11 ITestCaseCountryPropertiesService (org.cerberus.crud.service.ITestCaseCountryPropertiesService)10 TestCaseStepAction (org.cerberus.crud.entity.TestCaseStepAction)9 AnswerItem (org.cerberus.util.answer.AnswerItem)9 ApplicationContext (org.springframework.context.ApplicationContext)9 TestCaseCountry (org.cerberus.crud.entity.TestCaseCountry)8 TestCaseStepActionControl (org.cerberus.crud.entity.TestCaseStepActionControl)8 ITestCaseCountryService (org.cerberus.crud.service.ITestCaseCountryService)8 Answer (org.cerberus.util.answer.Answer)8 ITestCaseService (org.cerberus.crud.service.ITestCaseService)7 CerberusException (org.cerberus.exception.CerberusException)7 JSONArray (org.json.JSONArray)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6