Search in sources :

Example 6 with TestCaseCountryProperties

use of org.cerberus.crud.entity.TestCaseCountryProperties 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)

Example 7 with TestCaseCountryProperties

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

the class PropertyService method getListOfPropertiesLinkedToProperty.

/**
 * Method that takes the potencial @param property, finds it (or not if it
 * is not a existing property) inside the existing property list @param
 * propertiesOfTestcase and gets the list of all other properties required
 * (contained inside value1 or value2).
 *
 * @param country country used to filter property from propertiesOfTestcase
 * @param property property to be calculated
 * @param crossedProperties List of previously found properties.
 * @param propertiesOfTestcase List of properties defined from the testcase.
 * @return list of TestCaseCountryProperties that are included inside the
 * definition of the @param property
 */
private List<TestCaseCountryProperties> getListOfPropertiesLinkedToProperty(String country, String property, List<String> crossedProperties, List<TestCaseCountryProperties> propertiesOfTestcase) {
    List<TestCaseCountryProperties> result = new ArrayList();
    TestCaseCountryProperties testCaseCountryProperty = null;
    /*
         * Check if property is not already known (recursive case).
         */
    if (crossedProperties.contains(property)) {
        return result;
    }
    crossedProperties.add(property);
    /*
         * Check if property is defined for this testcase
         */
    AnswerItem ansSearch = findMatchingTestCaseCountryProperty(property, country, propertiesOfTestcase);
    testCaseCountryProperty = (TestCaseCountryProperties) ansSearch.getItem();
    if (testCaseCountryProperty == null) {
        return result;
    }
    /* 
         * Check if property value1 and value2 contains internal properties
         */
    List<String> allProperties = new ArrayList();
    // Value1 treatment
    List<String> propertiesValue1 = new ArrayList();
    // check the properties specified in the test
    for (String propNameFromValue1 : this.getPropertiesListFromString(testCaseCountryProperty.getValue1())) {
        for (TestCaseCountryProperties pr : propertiesOfTestcase) {
            if (pr.getProperty().equals(propNameFromValue1)) {
                propertiesValue1.add(propNameFromValue1);
                break;
            }
        }
    }
    allProperties.addAll(propertiesValue1);
    // Value2 treatment :
    List<String> propertiesValue2 = new ArrayList();
    // check the properties specified in the test
    for (String propNameFromValue2 : this.getPropertiesListFromString(testCaseCountryProperty.getValue2())) {
        for (TestCaseCountryProperties pr : propertiesOfTestcase) {
            if (pr.getProperty().equals(propNameFromValue2)) {
                propertiesValue2.add(propNameFromValue2);
                break;
            }
        }
    }
    allProperties.addAll(propertiesValue2);
    for (String internalProperty : allProperties) {
        result.addAll(getListOfPropertiesLinkedToProperty(country, internalProperty, crossedProperties, propertiesOfTestcase));
    }
    result.add(testCaseCountryProperty);
    return result;
}
Also used : TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) ArrayList(java.util.ArrayList) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 8 with TestCaseCountryProperties

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

the class ConditionService method evaluateCondition_ifPropertyExist.

private AnswerItem<Boolean> evaluateCondition_ifPropertyExist(String conditionOper, String conditionValue1, TestCaseExecution tCExecution) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Checking if property Exist");
    }
    AnswerItem ans = new AnswerItem();
    MessageEvent mes;
    if (StringUtil.isNullOrEmpty(conditionValue1)) {
        mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FAILED_IFPROPERTYEXIST_MISSINGPARAMETER);
        mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));
    } else {
        String myCountry = tCExecution.getCountry();
        String myProperty = conditionValue1;
        boolean execute_Action = false;
        for (TestCaseCountryProperties prop : tCExecution.getTestCaseCountryPropertyList()) {
            LOG.debug(prop.getCountry() + " - " + myCountry + " - " + prop.getProperty() + " - " + myProperty);
            if ((prop.getCountry().equals(myCountry)) && (prop.getProperty().equals(myProperty))) {
                execute_Action = true;
            }
        }
        if (execute_Action == false) {
            mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_FALSE_IFPROPERTYEXIST);
            mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));
            mes.setDescription(mes.getDescription().replace("%PROP%", conditionValue1));
            mes.setDescription(mes.getDescription().replace("%COUNTRY%", tCExecution.getCountry()));
        } else {
            mes = new MessageEvent(MessageEventEnum.CONDITIONEVAL_TRUE_IFPROPERTYEXIST);
            mes.setDescription(mes.getDescription().replace("%COND%", conditionOper));
            mes.setDescription(mes.getDescription().replace("%PROP%", conditionValue1));
            mes.setDescription(mes.getDescription().replace("%COUNTRY%", tCExecution.getCountry()));
        }
    }
    ans.setResultMessage(mes);
    return ans;
}
Also used : TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) MessageEvent(org.cerberus.engine.entity.MessageEvent) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 9 with TestCaseCountryProperties

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

the class TestCaseCountryPropertiesService method duplicateList.

@Override
public Answer duplicateList(List<TestCaseCountryProperties> objectList, String targetTest, String targetTestCase) {
    Answer ans = new Answer(null);
    List<TestCaseCountryProperties> listToCreate = new ArrayList();
    for (TestCaseCountryProperties objectToDuplicate : objectList) {
        objectToDuplicate.setTest(targetTest);
        objectToDuplicate.setTestCase(targetTestCase);
        listToCreate.add(objectToDuplicate);
    }
    ans = createList(listToCreate);
    return ans;
}
Also used : Answer(org.cerberus.util.answer.Answer) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) ArrayList(java.util.ArrayList)

Example 10 with TestCaseCountryProperties

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

the class TestCaseCountryPropertiesService method findAllWithDependencies.

@Override
public List<TestCaseCountryProperties> findAllWithDependencies(String test, String testcase, String country) throws CerberusException {
    if (parameterService.getParameterBooleanByKey("cerberus_property_countrylevelheritage", "", false)) {
        // Heritage is done at property + country level.
        List<TestCaseCountryProperties> tccpList = new ArrayList();
        List<TestCaseCountryProperties> tccpListPerCountry = new ArrayList();
        TestCase mainTC = testCaseService.findTestCaseByKey(test, testcase);
        // find all properties of preTests
        List<TestCase> tcptList = testCaseService.findTestCaseActiveByCriteria("Pre Testing", mainTC.getApplication(), country);
        for (TestCase tcase : tcptList) {
            tccpList.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(tcase.getTest(), tcase.getTestCase()));
            tccpListPerCountry.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCaseCountry(tcase.getTest(), tcase.getTestCase(), country));
        }
        // find all properties of the used step
        List<TestCase> tcList = testCaseService.findUseTestCaseList(test, testcase);
        for (TestCase tcase : tcList) {
            tccpList.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(tcase.getTest(), tcase.getTestCase()));
            tccpListPerCountry.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCaseCountry(tcase.getTest(), tcase.getTestCase(), country));
        }
        // find all properties of the testcase
        tccpList.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(test, testcase));
        tccpListPerCountry.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCaseCountry(test, testcase, country));
        // Keep only one property by name
        // all properties that are defined for the country are included
        HashMap tccpMap = new HashMap();
        for (TestCaseCountryProperties tccp : tccpListPerCountry) {
            tccpMap.put(tccp.getProperty(), tccp);
        }
        // the properties exist for the country.
        for (TestCaseCountryProperties tccp : tccpList) {
            TestCaseCountryProperties p = (TestCaseCountryProperties) tccpMap.get(tccp.getProperty());
            if (p == null) {
                tccpMap.put(tccp.getProperty(), tccp);
            } else if (p.getCountry().compareTo(country) != 0 && tccp.getCountry().compareTo(country) == 0) {
                tccpMap.put(tccp.getProperty(), tccp);
            }
        }
        List<TestCaseCountryProperties> result = new ArrayList<TestCaseCountryProperties>(tccpMap.values());
        return result;
    } else {
        // Heritage is done at property + country level.
        List<TestCaseCountryProperties> tccpList = new ArrayList();
        TestCase mainTC = testCaseService.findTestCaseByKey(test, testcase);
        /**
         * We load here all the properties countries from all related
         * testcases linked with test/testcase The order the load is done is
         * important as it will define the priority of each property.
         * properties coming from Pre Testing is the lower prio then, the
         * property coming from the useStep and then, top priority is the
         * property on the test + testcase.
         */
        // find all properties of preTests
        List<TestCase> tcptList = testCaseService.findTestCaseActiveByCriteria("Pre Testing", mainTC.getApplication(), country);
        for (TestCase tcase : tcptList) {
            tccpList.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(tcase.getTest(), tcase.getTestCase()));
        }
        // find all properties of the used step
        List<TestCase> tcList = testCaseService.findUseTestCaseList(test, testcase);
        for (TestCase tcase : tcList) {
            tccpList.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(tcase.getTest(), tcase.getTestCase()));
        }
        // find all properties of the testcase
        tccpList.addAll(testCaseCountryPropertiesDAO.findListOfPropertyPerTestTestCase(test, testcase));
        /**
         * We loop here the previous list, keeping by property, the last
         * value (top priority). That will define the level to consider
         * property on the test. testcase.
         */
        HashMap<String, TestCaseCountryProperties> tccpMap1 = new HashMap<String, TestCaseCountryProperties>();
        for (TestCaseCountryProperties tccp : tccpList) {
            tccpMap1.put(tccp.getProperty(), tccp);
        }
        /**
         * We then loop again in order to keep the selected properties for
         * the given country and level found on the previous step by
         * property.
         */
        List<TestCaseCountryProperties> result = new ArrayList<TestCaseCountryProperties>();
        for (TestCaseCountryProperties tccp : tccpList) {
            if (tccp.getCountry().equals(country)) {
                TestCaseCountryProperties tccp_level = (TestCaseCountryProperties) tccpMap1.get(tccp.getProperty());
                if ((tccp_level != null) && (((tccp.getTest().equals("Pre Testing")) && (tccp_level.getTest().equals("Pre Testing"))) || ((tccp.getTest().equals(test)) && (tccp.getTestCase().equals(testcase)) && (tccp_level.getTest().equals(test)) && (tccp_level.getTestCase().equals(testcase))) || ((tccp.getTest().equals(tccp_level.getTest())) && (tccp.getTestCase().equals(tccp_level.getTestCase()))))) {
                    result.add(tccp);
                }
            }
        }
        return result;
    }
}
Also used : TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) TestCase(org.cerberus.crud.entity.TestCase) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

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