Search in sources :

Example 1 with TestCaseExecutionQueue

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

the class TestCaseExecutionQueueDAO method readByVarious1.

@Override
public AnswerList readByVarious1(String tag, List<String> stateList, boolean withDependencies) throws CerberusException {
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    AnswerList answer = new AnswerList();
    final StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM testcaseexecutionqueue exq ");
    if (withDependencies) {
        query.append("left join testcase tec on exq.Test = tec.Test and exq.TestCase = tec.TestCase ");
        query.append("left join application app on tec.application = app.application ");
    }
    query.append("where exq.tag = ? ");
    query.append(SqlUtil.createWhereInClause(" AND exq.state", stateList, true));
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query.toString());
        LOG.debug("SQL.param.tag : " + tag);
    }
    List<TestCaseExecutionQueue> testCaseExecutionInQueueList = new ArrayList<TestCaseExecutionQueue>();
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        preStat.setString(1, tag);
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    if (withDependencies) {
                        testCaseExecutionInQueueList.add(this.loadWithDependenciesFromResultSet(resultSet));
                    } else {
                        testCaseExecutionInQueueList.add(this.loadFromResultSet(resultSet));
                    }
                }
                msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecutionInQueue").replace("%OPERATION%", "SELECT"));
                answer = new AnswerList(testCaseExecutionInQueueList, testCaseExecutionInQueueList.size());
            } 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%", "Unable to retrieve the list of entries!"));
                testCaseExecutionInQueueList = null;
            } catch (FactoryCreationException ex) {
                LOG.error("Unable to execute query : " + ex.toString());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
            } finally {
                resultSet.close();
            }
        } 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%", "Unable to retrieve the list of entries!"));
            testCaseExecutionInQueueList = null;
        } finally {
            preStat.close();
        }
    } 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%", "Unable to retrieve the list of entries!"));
        testCaseExecutionInQueueList = null;
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
        }
    }
    answer.setResultMessage(msg);
    return answer;
}
Also used : FactoryCreationException(org.cerberus.exception.FactoryCreationException) AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) IFactoryTestCaseExecutionQueue(org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue) PreparedStatement(java.sql.PreparedStatement)

Example 2 with TestCaseExecutionQueue

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

the class TestCaseExecutionQueueDAO method findTestCaseExecutionInQueuebyTag.

@Override
public List<TestCaseExecutionQueue> findTestCaseExecutionInQueuebyTag(String tag) throws CerberusException {
    boolean throwEx = false;
    final StringBuilder query = new StringBuilder("select exq.*, tec.*, app.* from ( select exq.* ").append("from testcaseexecutionqueue exq ").append("where exq.tag = ? ").append(" order by exq.test, exq.testcase, exq.ID desc) as exq ").append("LEFT JOIN testcase tec on exq.Test = tec.Test and exq.TestCase = tec.TestCase ").append("LEFT JOIN application app ON tec.application = app.application ").append("GROUP BY exq.test, exq.testcase, exq.Environment, exq.Browser, exq.Country ");
    List<TestCaseExecutionQueue> testCaseExecutionInQueueList = new ArrayList<TestCaseExecutionQueue>();
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        preStat.setString(1, tag);
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    testCaseExecutionInQueueList.add(this.loadWithDependenciesFromResultSet(resultSet));
                }
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
                testCaseExecutionInQueueList = null;
            } catch (FactoryCreationException ex) {
                LOG.error("Unable to execute query : " + ex.toString());
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            testCaseExecutionInQueueList = null;
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        testCaseExecutionInQueueList = null;
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwEx) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
    }
    return testCaseExecutionInQueueList;
}
Also used : FactoryCreationException(org.cerberus.exception.FactoryCreationException) 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) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) IFactoryTestCaseExecutionQueue(org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue) PreparedStatement(java.sql.PreparedStatement)

Example 3 with TestCaseExecutionQueue

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

the class TestCaseExecutionQueueDAO method getNbEntryToGo.

@Override
public int getNbEntryToGo(long id, int prio) {
    AnswerItem<TestCaseExecutionQueue> ans = new AnswerItem<>();
    TestCaseExecutionQueue result = null;
    final String query = "SELECT count(*)  FROM testcaseexecutionqueue WHERE State = 'QUEUED' and (ID < ? and Priority <= ?);";
    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);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            int i = 1;
            preStat.setLong(i++, id);
            preStat.setInt(i++, prio);
            ResultSet resultSet = preStat.executeQuery();
            try {
                if (resultSet.first()) {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                    msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
                    return resultSet.getInt(1);
                } else {
                    LOG.error("No record found : " + query);
                    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()));
            } finally {
                resultSet.close();
            }
        } 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()));
        } finally {
            preStat.close();
        }
    } 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()));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to close connection : " + exception.toString());
        }
    }
    // sets the message
    ans.setResultMessage(msg);
    return 999999;
}
Also used : SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) IFactoryTestCaseExecutionQueue(org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue) PreparedStatement(java.sql.PreparedStatement) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 4 with TestCaseExecutionQueue

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

the class TestCaseExecutionQueueDAO method readDistinctEnvCountryBrowserByTag.

@Override
public AnswerList readDistinctEnvCountryBrowserByTag(String tag) {
    AnswerList answer = new AnswerList();
    StringBuilder query = new StringBuilder();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    query.append("SELECT exq.* FROM testcaseexecutionqueue exq WHERE tag = ? GROUP BY Environment, Country, Browser");
    Connection connection = this.databaseSpring.connect();
    List<TestCaseExecutionQueue> EnvCountryBrowserList = new ArrayList<TestCaseExecutionQueue>();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        preStat.setString(1, tag);
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    EnvCountryBrowserList.add(this.loadFromResultSet(resultSet));
                }
                msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecutionInQueue").replace("%OPERATION%", "SELECT"));
                answer = new AnswerList(EnvCountryBrowserList, EnvCountryBrowserList.size());
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
                EnvCountryBrowserList = null;
            } catch (FactoryCreationException ex) {
                LOG.warn("Unable to execute query : " + ex.toString());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
                EnvCountryBrowserList = null;
            } finally {
                if (resultSet != null) {
                    resultSet.close();
                }
            }
        } catch (SQLException ex) {
            LOG.warn("Unable to execute query : " + ex.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
            EnvCountryBrowserList = null;
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException ex) {
        LOG.warn(ex.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException ex) {
            LOG.warn("Unable to execute query : " + ex.toString());
        }
    }
    answer.setResultMessage(msg);
    return answer;
}
Also used : FactoryCreationException(org.cerberus.exception.FactoryCreationException) AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) IFactoryTestCaseExecutionQueue(org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue) PreparedStatement(java.sql.PreparedStatement)

Example 5 with TestCaseExecutionQueue

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

the class TestCaseExecutionQueueDAO method readDistinctColumnByTag.

@Override
public AnswerList readDistinctColumnByTag(String tag, boolean env, boolean country, boolean browser, boolean app) {
    AnswerList answer = new AnswerList();
    StringBuilder query = new StringBuilder();
    StringBuilder distinct = new StringBuilder();
    int prev = 0;
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    if (!(!env && !country && !app && !browser)) {
        if (env) {
            distinct.append("exq.Environment");
            prev++;
        }
        if (country) {
            if (prev != 0) {
                prev = 0;
                distinct.append(",");
            }
            distinct.append("exq.Country");
            prev++;
        }
        if (browser) {
            if (prev != 0) {
                prev = 0;
                distinct.append(",");
            }
            distinct.append("exq.Browser");
            prev++;
        }
        if (app) {
            if (prev != 0) {
                prev = 0;
                distinct.append(",");
            }
            distinct.append("tec.Application");
        }
        query.append("SELECT tec.test, tec.testcase, exq.tag,  ");
        query.append(distinct.toString());
        query.append(" FROM testcase tec LEFT JOIN testcaseexecutionqueue exq ON exq.Test = tec.Test AND exq.TestCase = tec.TestCase WHERE tag = ? GROUP BY ");
        query.append(distinct.toString());
    } else {
        // If there is no distinct, select nothing
        query.append("SELECT * FROM testcaseexecutionqueue exq WHERE 1=0 AND tag = ?");
    }
    Connection connection = this.databaseSpring.connect();
    List<TestCaseExecutionQueue> column = new ArrayList<TestCaseExecutionQueue>();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        preStat.setString(1, tag);
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    TestCaseExecutionQueue tmp = new TestCaseExecutionQueue();
                    tmp.setTest(resultSet.getString("tec.test"));
                    tmp.setTestCase(resultSet.getString("tec.testcase"));
                    tmp.setTag(resultSet.getString("exq.tag"));
                    if (env) {
                        tmp.setEnvironment(resultSet.getString("Environment"));
                    } else {
                        tmp.setEnvironment("");
                    }
                    if (country) {
                        tmp.setCountry(resultSet.getString("Country"));
                    } else {
                        tmp.setCountry("");
                    }
                    if (browser) {
                        tmp.setBrowser(resultSet.getString("Browser"));
                    } else {
                        tmp.setBrowser("");
                    }
                    if (app) {
                        Application application = factoryApplication.create(resultSet.getString("Application"));
                        tmp.setApplicationObj(application);
                    }
                    column.add(tmp);
                }
                msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));
                answer = new AnswerList(column, column.size());
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
                column = null;
            } finally {
                if (resultSet != null) {
                    resultSet.close();
                }
            }
        } catch (SQLException ex) {
            LOG.warn("Unable to execute query : " + ex.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
            column = null;
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException ex) {
        LOG.warn(ex.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException ex) {
            LOG.warn("Unable to execute query : " + ex.toString());
        }
    }
    answer.setResultMessage(msg);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) IFactoryTestCaseExecutionQueue(org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue) PreparedStatement(java.sql.PreparedStatement) IFactoryApplication(org.cerberus.crud.factory.IFactoryApplication) Application(org.cerberus.crud.entity.Application)

Aggregations

TestCaseExecutionQueue (org.cerberus.crud.entity.TestCaseExecutionQueue)33 IFactoryTestCaseExecutionQueue (org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue)22 ArrayList (java.util.ArrayList)21 MessageEvent (org.cerberus.engine.entity.MessageEvent)18 FactoryCreationException (org.cerberus.exception.FactoryCreationException)15 AnswerItem (org.cerberus.util.answer.AnswerItem)14 ITestCaseExecutionQueueService (org.cerberus.crud.service.ITestCaseExecutionQueueService)12 AnswerList (org.cerberus.util.answer.AnswerList)11 JSONObject (org.json.JSONObject)11 Connection (java.sql.Connection)10 PreparedStatement (java.sql.PreparedStatement)10 ResultSet (java.sql.ResultSet)10 SQLException (java.sql.SQLException)10 CerberusException (org.cerberus.exception.CerberusException)10 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)9 ApplicationContext (org.springframework.context.ApplicationContext)9 Date (java.util.Date)8 List (java.util.List)8 ITagService (org.cerberus.crud.service.ITagService)8 Map (java.util.Map)7