Search in sources :

Example 1 with TestCaseExecutionData

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

the class TestCaseExecutionDataDAO method readLastCacheEntry.

@Override
public AnswerItem<TestCaseExecutionData> readLastCacheEntry(String system, String environment, String country, String property, int cacheExpire) {
    AnswerItem ans = new AnswerItem();
    TestCaseExecutionData result = null;
    final String query = "select * from testcaseexecutiondata exd WHERE System=? and Environment=? and Country=? and FromCache='N' and Property=? and Start >= NOW()- INTERVAL ? SECOND and `index`=1 and jsonResult is not null and RC = 'OK' order by id desc;";
    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);
        LOG.debug("SQL.param.system : " + system);
        LOG.debug("SQL.param.property : " + property);
        LOG.debug("SQL.param.cacheExpire : " + String.valueOf(cacheExpire));
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            int i = 1;
            preStat.setString(i++, system);
            preStat.setString(i++, environment);
            preStat.setString(i++, country);
            preStat.setString(i++, property);
            preStat.setInt(i++, cacheExpire);
            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 : SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) TestCaseExecutionData(org.cerberus.crud.entity.TestCaseExecutionData) FactoryTestCaseExecutionData(org.cerberus.crud.factory.impl.FactoryTestCaseExecutionData) IFactoryTestCaseExecutionData(org.cerberus.crud.factory.IFactoryTestCaseExecutionData) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 2 with TestCaseExecutionData

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

the class TestCaseExecutionDataDAO method readByKey.

@Override
public AnswerItem<TestCaseExecutionData> readByKey(long id, String property, int index) {
    AnswerItem ans = new AnswerItem();
    TestCaseExecutionData result = null;
    final String query = "SELECT * FROM testcaseexecutiondata exd WHERE id = ? AND property = ? AND `index` = ?";
    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);
        LOG.debug("SQL.param.id : " + String.valueOf(id));
        LOG.debug("SQL.param.property : " + property);
        LOG.debug("SQL.param.index : " + String.valueOf(index));
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setLong(1, id);
            preStat.setString(2, property);
            preStat.setInt(3, index);
            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 : SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) TestCaseExecutionData(org.cerberus.crud.entity.TestCaseExecutionData) FactoryTestCaseExecutionData(org.cerberus.crud.factory.impl.FactoryTestCaseExecutionData) IFactoryTestCaseExecutionData(org.cerberus.crud.factory.IFactoryTestCaseExecutionData) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 3 with TestCaseExecutionData

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

the class FactoryTestCaseExecutionData method create.

@Override
public TestCaseExecutionData create(long id, String property, int index, String description, String value, String type, String value1, String value2, String rC, String rMessage, long start, long end, long startLong, long endLong, MessageEvent message, int retrynb, int retryperiod, String database, String value1Init, String value2Init, String lengthInit, String length, int rowLimit, String nature, String system, String environment, String country, String dataLib, String jsonResult, String fromCache) {
    TestCaseExecutionData testCaseExecutionData = new TestCaseExecutionData();
    testCaseExecutionData.setId(id);
    testCaseExecutionData.setProperty(property);
    testCaseExecutionData.setIndex(index);
    testCaseExecutionData.setType(type);
    testCaseExecutionData.setValue(value);
    testCaseExecutionData.setDatabase(database);
    testCaseExecutionData.setValue1Init(value1Init);
    testCaseExecutionData.setValue2Init(value2Init);
    testCaseExecutionData.setValue1(value1);
    testCaseExecutionData.setValue2(value2);
    testCaseExecutionData.setLength(length);
    testCaseExecutionData.setLengthInit(lengthInit);
    testCaseExecutionData.setRowLimit(rowLimit);
    testCaseExecutionData.setNature(nature);
    testCaseExecutionData.setRetryNb(retrynb);
    testCaseExecutionData.setRetryPeriod(retryperiod);
    testCaseExecutionData.setStart(start);
    testCaseExecutionData.setEnd(end);
    testCaseExecutionData.setStartLong(startLong);
    testCaseExecutionData.setEndLong(endLong);
    testCaseExecutionData.setRC(rC);
    testCaseExecutionData.setrMessage(rMessage);
    testCaseExecutionData.setDescription(description);
    testCaseExecutionData.setPropertyResultMessage(message);
    testCaseExecutionData.setSystem(system);
    testCaseExecutionData.setEnvironment(environment);
    testCaseExecutionData.setCountry(country);
    testCaseExecutionData.setDataLib(dataLib);
    testCaseExecutionData.setJsonResult(jsonResult);
    testCaseExecutionData.setFromCache(fromCache);
    // List objects
    List<TestCaseExecutionFile> objectFileList = new ArrayList<TestCaseExecutionFile>();
    testCaseExecutionData.setFileList(objectFileList);
    return testCaseExecutionData;
}
Also used : TestCaseExecutionData(org.cerberus.crud.entity.TestCaseExecutionData) IFactoryTestCaseExecutionData(org.cerberus.crud.factory.IFactoryTestCaseExecutionData) ArrayList(java.util.ArrayList) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Example 4 with TestCaseExecutionData

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

the class FactoryTestCaseExecution method create.

@Override
public TestCaseExecution create(long id, String test, String testCase, String description, String build, String revision, String environment, String country, String browser, String version, String platform, String browserFullVersion, long start, long end, String controlStatus, String controlMessage, String application, Application applicationObj, String ip, String url, String port, String tag, int verbose, int screenshot, int pageSource, int seleniumLog, boolean synchroneous, String timeout, String outputFormat, String status, String crbVersion, TestCase tCase, CountryEnvParam countryEnvParam, CountryEnvironmentParameters countryEnvironmentParameters, boolean manualURL, String myHost, String myContextRoot, String myLoginRelativeURL, String myEnvData, String seleniumIP, String seleniumPort, List<TestCaseStepExecution> testCaseStepExecution, MessageGeneral resultMessage, String executor, int numberOfRetries, String screenSize, List<RobotCapability> capabilities, String conditionOper, String conditionVal1Init, String conditionVal2Init, String conditionVal1, String conditionVal2, String manualExecution, String userAgent, int testCaseVersion, String system, String robotDecli) {
    TestCaseExecution newTce = new TestCaseExecution();
    newTce.setApplicationObj(applicationObj);
    newTce.setApplication(application);
    newTce.setBrowser(browser);
    newTce.setVersion(version);
    newTce.setPlatform(platform);
    newTce.setBrowserFullVersion(browserFullVersion);
    newTce.setBuild(build);
    newTce.setControlMessage(controlMessage);
    newTce.setControlStatus(controlStatus);
    newTce.setCountry(country);
    newTce.setCrbVersion(crbVersion);
    newTce.setEnd(end);
    newTce.setEnvironment(environment);
    newTce.setEnvironmentData(myEnvData);
    newTce.setId(id);
    newTce.setIp(ip);
    newTce.setPort(port);
    newTce.setRevision(revision);
    newTce.setStart(start);
    newTce.setStatus(status);
    newTce.setTag(tag);
    newTce.setTest(test);
    newTce.setTestCase(testCase);
    newTce.setUrl(url);
    newTce.setVerbose(verbose);
    newTce.setScreenshot(screenshot);
    newTce.setTestCaseObj(tCase);
    newTce.setCountryEnvParam(countryEnvParam);
    newTce.setCountryEnvironmentParameters(countryEnvironmentParameters);
    newTce.setManualURL(manualURL);
    newTce.setMyHost(myHost);
    newTce.setMyContextRoot(myContextRoot);
    newTce.setMyLoginRelativeURL(myLoginRelativeURL);
    newTce.setSeleniumIP(seleniumIP);
    newTce.setSeleniumPort(seleniumPort);
    if (testCaseStepExecution == null) {
        testCaseStepExecution = new ArrayList<>();
    }
    newTce.setTestCaseStepExecutionList(testCaseStepExecution);
    newTce.setResultMessage(resultMessage);
    newTce.setOutputFormat(outputFormat);
    newTce.setTimeout(timeout);
    newTce.setSynchroneous(synchroneous);
    newTce.setPageSource(pageSource);
    newTce.setSeleniumLog(seleniumLog);
    newTce.setExecutor(executor);
    newTce.setNumberOfRetries(numberOfRetries);
    newTce.setScreenSize(screenSize);
    newTce.setCapabilities(capabilities);
    newTce.setLastWebsocketPush(0);
    newTce.setConditionOper(conditionOper);
    newTce.setConditionVal1(conditionVal1);
    newTce.setConditionVal1Init(conditionVal1Init);
    newTce.setConditionVal2(conditionVal2);
    newTce.setConditionVal2Init(conditionVal2Init);
    newTce.setManualExecution(manualExecution);
    newTce.setUserAgent(userAgent);
    newTce.setDescription(description);
    newTce.setRobotDecli(robotDecli);
    newTce.setSystem(system);
    // List objects
    List<TestCaseExecutionFile> objectFileList = new ArrayList<>();
    newTce.setFileList(objectFileList);
    TreeMap<String, TestCaseExecutionData> hashTemp1 = new TreeMap<>();
    newTce.setTestCaseExecutionDataMap(hashTemp1);
    newTce.setNbExecutions(1);
    newTce.setTestCaseVersion(testCaseVersion);
    return newTce;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecutionData(org.cerberus.crud.entity.TestCaseExecutionData) ArrayList(java.util.ArrayList) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile) TreeMap(java.util.TreeMap)

Example 5 with TestCaseExecutionData

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

the class ActionService method doActionCalculateProperty.

private MessageEvent doActionCalculateProperty(TestCaseStepActionExecution testCaseStepActionExecution, String value1, String value2) {
    MessageEvent message;
    AnswerItem<String> answerDecode = new AnswerItem();
    if (StringUtil.isNullOrEmpty(value1)) {
        // Value1 is a mandatory parameter.
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_MISSINGPROPERTY);
        message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY));
    } else {
        try {
            TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();
            // Getting the Country property definition.
            TestCaseCountryProperties tccp = null;
            boolean propertyExistOnAnyCountry = false;
            for (TestCaseCountryProperties object : tCExecution.getTestCaseCountryPropertyList()) {
                if ((object.getProperty().equalsIgnoreCase(value1)) && (object.getCountry().equalsIgnoreCase(tCExecution.getCountry()))) {
                    tccp = object;
                }
                if ((object.getProperty().equalsIgnoreCase(value1))) {
                    propertyExistOnAnyCountry = true;
                }
            }
            if (tccp == null) {
                // Could not find a country property inside the existing execution.
                if (propertyExistOnAnyCountry) {
                    message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NO_PROPERTY_DEFINITION);
                    message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY).replace("%PROP%", value1).replace("%COUNTRY%", tCExecution.getCountry()));
                    return message;
                } else {
                    message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_PROPERTYNOTFOUND);
                    message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY).replace("%PROP%", value1).replace("%COUNTRY%", tCExecution.getCountry()));
                    return message;
                }
            } else {
                if (!(StringUtil.isNullOrEmpty(value2))) {
                    // If value2 is fed with something, we control here that value is a valid property name and gets its defintion.
                    tccp = null;
                    propertyExistOnAnyCountry = false;
                    for (TestCaseCountryProperties object : tCExecution.getTestCaseCountryPropertyList()) {
                        if ((object.getProperty().equalsIgnoreCase(value2)) && (object.getCountry().equalsIgnoreCase(tCExecution.getCountry()))) {
                            tccp = object;
                        }
                        if ((object.getProperty().equalsIgnoreCase(value2))) {
                            propertyExistOnAnyCountry = true;
                        }
                    }
                    if (tccp == null) {
                        // Could not find a country property inside the existing execution.
                        if (propertyExistOnAnyCountry) {
                            message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NO_PROPERTY_DEFINITION);
                            message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY).replace("%PROP%", value2).replace("%COUNTRY%", tCExecution.getCountry()));
                            return message;
                        } else {
                            message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_PROPERTYNOTFOUND);
                            message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY).replace("%PROP%", value2).replace("%COUNTRY%", tCExecution.getCountry()));
                            return message;
                        }
                    }
                }
                // We calculate the property here.
                long now = new Date().getTime();
                TestCaseExecutionData tcExeData;
                tcExeData = factoryTestCaseExecutionData.create(tCExecution.getId(), tccp.getProperty(), 1, tccp.getDescription(), null, tccp.getType(), tccp.getValue1(), tccp.getValue2(), null, null, now, now, now, now, new MessageEvent(MessageEventEnum.PROPERTY_PENDING), tccp.getRetryNb(), tccp.getRetryPeriod(), tccp.getDatabase(), tccp.getValue1(), tccp.getValue2(), tccp.getLength(), tccp.getLength(), tccp.getRowLimit(), tccp.getNature(), "", "", "", "", "", "N");
                tcExeData.setTestCaseCountryProperties(tccp);
                propertyService.calculateProperty(tcExeData, tCExecution, testCaseStepActionExecution, tccp, true);
                // Property message goes to Action message.
                message = tcExeData.getPropertyResultMessage();
                if (message.getCodeString().equals("OK")) {
                    // If Property calculated successfully we summarize the message to a shorter version.
                    message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALCULATEPROPERTY);
                    message.setDescription(message.getDescription().replace("%PROP%", value1).replace("%VALUE%", tcExeData.getValue()));
                    if (tcExeData.getDataLibRawData() != null) {
                        message.setDescription(message.getDescription() + " %NBROWS% row(s) with %NBSUBDATA% Subdata(s) calculated.".replace("%NBROWS%", String.valueOf(tcExeData.getDataLibRawData().size())).replace("%NBSUBDATA%", String.valueOf(tcExeData.getDataLibRawData().get(0).size())));
                    }
                }
                if (!(StringUtil.isNullOrEmpty(value2))) {
                    // If value2 is fed we force the result to value1.
                    tcExeData.setProperty(value1);
                }
                // saves the result
                try {
                    testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcExeData));
                    LOG.debug("Adding into Execution data list. Property : '" + tcExeData.getProperty() + "' Index : '" + tcExeData.getIndex() + "' Value : '" + tcExeData.getValue() + "'");
                    tCExecution.getTestCaseExecutionDataMap().put(tcExeData.getProperty(), tcExeData);
                    if (tcExeData.getDataLibRawData() != null) {
                        // If the property is a TestDataLib, we same all rows retreived in order to support nature such as NOTINUSe or RANDOMNEW.
                        for (int i = 1; i < (tcExeData.getDataLibRawData().size()); i++) {
                            now = new Date().getTime();
                            TestCaseExecutionData tcedS = factoryTestCaseExecutionData.create(tcExeData.getId(), tcExeData.getProperty(), (i + 1), tcExeData.getDescription(), tcExeData.getDataLibRawData().get(i).get(""), tcExeData.getType(), "", "", tcExeData.getRC(), "", now, now, now, now, null, 0, 0, "", "", "", "", "", 0, "", "", "", "", "", "", "N");
                            testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcedS));
                        }
                    }
                } catch (CerberusException cex) {
                    LOG.error(cex.getMessage(), cex);
                }
            }
        } catch (Exception ex) {
            LOG.error(ex.toString(), ex);
            message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC).resolveDescription("DETAIL", ex.toString());
        }
    }
    return message;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) CerberusException(org.cerberus.exception.CerberusException) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) MessageEvent(org.cerberus.engine.entity.MessageEvent) TestCaseExecutionData(org.cerberus.crud.entity.TestCaseExecutionData) IFactoryTestCaseExecutionData(org.cerberus.crud.factory.IFactoryTestCaseExecutionData) AnswerItem(org.cerberus.util.answer.AnswerItem) Date(java.util.Date) CerberusEventException(org.cerberus.exception.CerberusEventException) CerberusException(org.cerberus.exception.CerberusException)

Aggregations

TestCaseExecutionData (org.cerberus.crud.entity.TestCaseExecutionData)13 IFactoryTestCaseExecutionData (org.cerberus.crud.factory.IFactoryTestCaseExecutionData)9 MessageEvent (org.cerberus.engine.entity.MessageEvent)8 ArrayList (java.util.ArrayList)7 AnswerItem (org.cerberus.util.answer.AnswerItem)7 Date (java.util.Date)4 TestCaseExecutionFile (org.cerberus.crud.entity.TestCaseExecutionFile)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)3 FactoryTestCaseExecutionData (org.cerberus.crud.factory.impl.FactoryTestCaseExecutionData)3 CerberusEventException (org.cerberus.exception.CerberusEventException)3 AnswerList (org.cerberus.util.answer.AnswerList)3 TestCaseCountryProperties (org.cerberus.crud.entity.TestCaseCountryProperties)2 CerberusException (org.cerberus.exception.CerberusException)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1