Search in sources :

Example 46 with TestCaseExecution

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

the class RecorderService method recordExecutionInformationAfterStepActionandControl.

@Override
public List<TestCaseExecutionFile> recordExecutionInformationAfterStepActionandControl(TestCaseStepActionExecution testCaseStepActionExecution, TestCaseStepActionControlExecution testCaseStepActionControlExecution) {
    List<TestCaseExecutionFile> objectFileList = new ArrayList<TestCaseExecutionFile>();
    TestCaseExecutionFile objectFile = null;
    // Used for logging purposes
    String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
    TestCaseExecution myExecution;
    boolean doScreenshot;
    boolean getPageSource;
    String applicationType;
    String returnCode;
    Integer controlNumber = 0;
    if (testCaseStepActionControlExecution == null) {
        myExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();
        doScreenshot = testCaseStepActionExecution.getActionResultMessage().isDoScreenshot();
        getPageSource = testCaseStepActionExecution.getActionResultMessage().isGetPageSource();
        applicationType = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getApplicationObj().getType();
        returnCode = testCaseStepActionExecution.getReturnCode();
    } else {
        myExecution = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution();
        doScreenshot = testCaseStepActionControlExecution.getControlResultMessage().isDoScreenshot();
        getPageSource = testCaseStepActionControlExecution.getControlResultMessage().isGetPageSource();
        applicationType = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution().getApplicationObj().getType();
        returnCode = testCaseStepActionControlExecution.getReturnCode();
        controlNumber = testCaseStepActionControlExecution.getControlSequence();
    }
    /**
     * SCREENSHOT Management. Screenshot only done when : screenshot
     * parameter is eq to 2 or screenshot parameter is eq to 1 with the
     * correct doScreenshot flag on the last action MessageEvent.
     */
    if ((myExecution.getScreenshot() == 2) || ((myExecution.getScreenshot() == 1) && (doScreenshot))) {
        if (applicationType.equals(Application.TYPE_GUI) || applicationType.equals(Application.TYPE_APK) || applicationType.equals(Application.TYPE_IPA) || applicationType.equals(Application.TYPE_FAT)) {
            /**
             * Only if the return code is not equal to Cancel, meaning lost
             * connectivity with selenium.
             */
            if (!returnCode.equals("CA")) {
                objectFile = this.recordScreenshot(myExecution, testCaseStepActionExecution, controlNumber);
                if (objectFile != null) {
                    objectFileList.add(objectFile);
                }
            } else {
                LOG.debug(logPrefix + "Not Doing screenshot because connectivity with selenium server lost.");
            }
        }
    } else {
        LOG.debug(logPrefix + "Not Doing screenshot because of the screenshot parameter or flag on the last Action result.");
    }
    /**
     * PAGESOURCE management. Get PageSource if requested by the last Action
     * MessageEvent.
     */
    if ((myExecution.getPageSource() == 2) || ((myExecution.getPageSource() == 1) && (getPageSource))) {
        if (applicationType.equals(Application.TYPE_GUI) || applicationType.equals(Application.TYPE_APK) || applicationType.equals(Application.TYPE_IPA)) {
            /**
             * Only if the return code is not equal to Cancel, meaning lost
             * connectivity with selenium.
             */
            if (!returnCode.equals("CA")) {
                objectFile = this.recordPageSource(myExecution, testCaseStepActionExecution, controlNumber);
                if (objectFile != null) {
                    objectFileList.add(objectFile);
                }
            } else {
                LOG.debug(logPrefix + "Not Doing screenshot because connectivity with selenium server lost.");
            }
        }
    } else {
        LOG.debug(logPrefix + "Not getting page source because of the pageSource parameter or flag on the last Action result.");
    }
    /**
     * Last call XML SOURCE management. Get Source of the XML if requested
     * by the last Action or control MessageEvent.
     */
    if (applicationType.equals(Application.TYPE_SRV) && ((myExecution.getPageSource() == 2) || ((myExecution.getPageSource() == 1) && (getPageSource)) || (myExecution.getScreenshot() == 2) || ((myExecution.getScreenshot() == 1) && (doScreenshot)))) {
        // Record the Request and Response.
        AppService se = (AppService) testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getLastServiceCalled();
        if (se != null) {
            // No Calls were performed previously
            List<TestCaseExecutionFile> objectFileSOAPList = new ArrayList<TestCaseExecutionFile>();
            objectFileSOAPList = this.recordServiceCall(myExecution, testCaseStepActionExecution, controlNumber, null, se);
            if (objectFileSOAPList.isEmpty() != true) {
                for (TestCaseExecutionFile testCaseExecutionFile : objectFileSOAPList) {
                    objectFileList.add(testCaseExecutionFile);
                }
            }
        }
    }
    return objectFileList;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) AppService(org.cerberus.crud.entity.AppService) ArrayList(java.util.ArrayList) IFactoryTestCaseExecutionFile(org.cerberus.crud.factory.IFactoryTestCaseExecutionFile) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Example 47 with TestCaseExecution

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

the class TestCaseExecutionDAO method readByKey.

@Override
public AnswerItem readByKey(long executionId) {
    AnswerItem ans = new AnswerItem();
    TestCaseExecution result = null;
    final String query = "SELECT * FROM `testcaseexecution` exe WHERE exe.`id` = ?";
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setLong(1, executionId);
            ResultSet resultSet = preStat.executeQuery();
            try {
                if (resultSet.first()) {
                    result = loadFromResultSet(resultSet);
                    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()));
            } 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 ans;
}
Also used : IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 48 with TestCaseExecution

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

the class TestCaseExecutionDAO method loadTestCaseExecutionAndApplicationFromResultSet.

private TestCaseExecution loadTestCaseExecutionAndApplicationFromResultSet(ResultSet resultSet) throws SQLException {
    TestCaseExecution testCaseExecution = new TestCaseExecution();
    testCaseExecution = this.loadFromResultSet(resultSet);
    testCaseExecution.setApplicationObj(applicationDAO.loadFromResultSet(resultSet));
    return testCaseExecution;
}
Also used : IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution)

Example 49 with TestCaseExecution

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

the class TestCaseExecutionDAO method findLastTestCaseExecutionNotPE.

@Override
public TestCaseExecution findLastTestCaseExecutionNotPE(String test, String testCase) throws CerberusException {
    TestCaseExecution result = null;
    StringBuilder query = new StringBuilder();
    query.append("SELECT exe.*  FROM `testcaseexecution` exe ");
    query.append(" WHERE Test = ? and TestCase= ? and ID = ");
    query.append(" (SELECT MAX(ID) from `testcaseexecution` ");
    query.append("WHERE Test= ? and TestCase= ? and ControlStatus!='PE')");
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query.toString())) {
        preStat.setString(1, test);
        preStat.setString(2, testCase);
        preStat.setString(3, test);
        preStat.setString(4, testCase);
        try (ResultSet resultSet = preStat.executeQuery()) {
            if (resultSet.first()) {
                result = loadFromResultSet(resultSet);
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
    }
    return result;
}
Also used : IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 50 with TestCaseExecution

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

the class TestCaseExecutionDAO method readByTagByCriteria.

@Override
public AnswerList readByTagByCriteria(String tag, int start, int amount, String sort, String searchTerm, Map<String, List<String>> individualSearch) throws CerberusException {
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    AnswerList answer = new AnswerList();
    List<String> individalColumnSearchValues = new ArrayList<String>();
    final StringBuffer query = new StringBuffer();
    query.append("SELECT * FROM testcaseexecution exe ");
    query.append("left join testcase tec on exe.Test = tec.Test and exe.TestCase = tec.TestCase ");
    query.append("left join application app on tec.application = app.application ");
    query.append("where exe.ID IN ");
    query.append("(select MAX(exe.ID) from testcaseexecution exe ");
    query.append("where 1=1 ");
    if (!StringUtil.isNullOrEmpty(tag)) {
        query.append("and exe.tag = ? ");
    }
    query.append("group by exe.test, exe.testcase, exe.Environment, exe.Browser, exe.Country) ");
    if (!StringUtil.isNullOrEmpty(searchTerm)) {
        query.append("and (exe.`test` like ? ");
        query.append(" or exe.`testCase` like ? ");
        query.append(" or exe.`application` like ? ");
        query.append(" or tec.`bugid` like ? ");
        query.append(" or tec.`priority` like ? ");
        query.append(" or tec.`description` like ? )");
    }
    if (individualSearch != null && !individualSearch.isEmpty()) {
        query.append(" and ( 1=1 ");
        for (Map.Entry<String, List<String>> entry : individualSearch.entrySet()) {
            query.append(" and ");
            query.append(SqlUtil.getInSQLClauseForPreparedStatement(entry.getKey(), entry.getValue()));
            individalColumnSearchValues.addAll(entry.getValue());
        }
        query.append(" ) ");
    }
    if (!StringUtil.isNullOrEmpty(sort)) {
        query.append(" order by ").append(sort);
    }
    if ((amount <= 0) || (amount >= MAX_ROW_SELECTED)) {
        query.append(" limit ").append(start).append(" , ").append(MAX_ROW_SELECTED);
    } else {
        query.append(" limit ").append(start).append(" , ").append(amount);
    }
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query.toString());
        LOG.debug("SQL.param.tag : " + tag);
    }
    List<TestCaseExecution> testCaseExecutionList = new ArrayList<TestCaseExecution>();
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        int i = 1;
        if (!StringUtil.isNullOrEmpty(tag)) {
            preStat.setString(i++, tag);
        }
        if (!Strings.isNullOrEmpty(searchTerm)) {
            preStat.setString(i++, "%" + searchTerm + "%");
            preStat.setString(i++, "%" + searchTerm + "%");
            preStat.setString(i++, "%" + searchTerm + "%");
            preStat.setString(i++, "%" + searchTerm + "%");
            preStat.setString(i++, "%" + searchTerm + "%");
            preStat.setString(i++, "%" + searchTerm + "%");
        }
        for (String individualColumnSearchValue : individalColumnSearchValues) {
            preStat.setString(i++, individualColumnSearchValue);
        }
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    testCaseExecutionList.add(this.loadWithDependenciesFromResultSet(resultSet));
                }
                msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecution").replace("%OPERATION%", "SELECT"));
                // answer = new AnswerList(testCaseExecutionList, testCaseExecutionList.size());
                answer.setTotalRows(testCaseExecutionList.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!"));
                testCaseExecutionList = null;
            } finally {
                resultSet.close();
            }
        } 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!"));
            testCaseExecutionList = null;
        } finally {
            preStat.close();
        }
    } 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!"));
        testCaseExecutionList = 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);
    answer.setDataList(testCaseExecutionList);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) ResultSet(java.sql.ResultSet) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Map(java.util.Map)

Aggregations

TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)55 ArrayList (java.util.ArrayList)24 IFactoryTestCaseExecution (org.cerberus.crud.factory.IFactoryTestCaseExecution)20 MessageEvent (org.cerberus.engine.entity.MessageEvent)19 JSONObject (org.json.JSONObject)17 AnswerItem (org.cerberus.util.answer.AnswerItem)15 AnswerList (org.cerberus.util.answer.AnswerList)14 Connection (java.sql.Connection)13 PreparedStatement (java.sql.PreparedStatement)13 ResultSet (java.sql.ResultSet)13 SQLException (java.sql.SQLException)13 LinkedHashMap (java.util.LinkedHashMap)13 ITestCaseExecutionService (org.cerberus.crud.service.ITestCaseExecutionService)12 CerberusException (org.cerberus.exception.CerberusException)11 List (java.util.List)10 HashMap (java.util.HashMap)9 TestCaseExecutionQueue (org.cerberus.crud.entity.TestCaseExecutionQueue)9 JSONArray (org.json.JSONArray)9 JSONException (org.json.JSONException)9 ApplicationContext (org.springframework.context.ApplicationContext)9