Search in sources :

Example 11 with TestCase

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

the class FactoryTestCase method create.

@Override
public TestCase create(String test, String testCase, String description) {
    TestCase newTestCase = new TestCase();
    newTestCase.setTest(test);
    newTestCase.setTestCase(testCase);
    newTestCase.setDescription(description);
    return newTestCase;
}
Also used : TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase)

Example 12 with TestCase

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

the class CountryEnvironmentService method getEnvironmentAvailable.

@Override
public List<String[]> getEnvironmentAvailable(String test, String testCase, String country) {
    try {
        List<String[]> list = null;
        TestCase tc = this.testCaseService.findTestCaseByKey(test, testCase);
        if (tc != null) {
            list = this.countryEnvironmentParametersDAO.getEnvironmentAvailable(country, tc.getApplication());
        }
        return list;
    } catch (CerberusException ex) {
        LOG.warn(ex);
    }
    return null;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) TestCase(org.cerberus.crud.entity.TestCase)

Example 13 with TestCase

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

the class ExecutionCheckService method checkRangeBuildRevision.

private boolean checkRangeBuildRevision(TestCaseExecution tCExecution) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Checking if test can be executed in this build and revision");
    }
    TestCase tc = tCExecution.getTestCaseObj();
    CountryEnvParam env = tCExecution.getCountryEnvParam();
    String tcFromSprint = ParameterParserUtil.parseStringParam(tc.getFromBuild(), "");
    String tcToSprint = ParameterParserUtil.parseStringParam(tc.getToBuild(), "");
    String tcFromRevision = ParameterParserUtil.parseStringParam(tc.getFromRev(), "");
    String tcToRevision = ParameterParserUtil.parseStringParam(tc.getToRev(), "");
    String sprint = ParameterParserUtil.parseStringParam(env.getBuild(), "");
    String revision = ParameterParserUtil.parseStringParam(env.getRevision(), "");
    int dif = -1;
    if (!tcFromSprint.isEmpty() && sprint != null) {
        try {
            if (sprint.isEmpty()) {
                message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_NOTDEFINED);
                return false;
            } else {
                dif = this.compareBuild(sprint, tcFromSprint, env.getSystem());
            }
            if (dif == 0) {
                if (!tcFromRevision.isEmpty() && revision != null) {
                    if (revision.isEmpty()) {
                        message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_NOTDEFINED);
                        return false;
                    } else if (this.compareRevision(revision, tcFromRevision, env.getSystem()) < 0) {
                        message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_DIFFERENT);
                        return false;
                    }
                }
            } else if (dif < 0) {
                message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_DIFFERENT);
                return false;
            }
        } catch (NumberFormatException exception) {
            message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_WRONGFORMAT);
            return false;
        } catch (CerberusException ex) {
            message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_BADLYDEFINED);
            return false;
        }
    }
    if (!tcToSprint.isEmpty() && sprint != null) {
        try {
            if (sprint.isEmpty()) {
                message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_NOTDEFINED);
                return false;
            } else {
                dif = this.compareBuild(tcToSprint, sprint, env.getSystem());
            }
            if (dif == 0) {
                if (!tcToRevision.isEmpty() && revision != null) {
                    if (revision.isEmpty()) {
                        message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_NOTDEFINED);
                        return false;
                    } else if (this.compareRevision(tcToRevision, revision, env.getSystem()) < 0) {
                        message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_DIFFERENT);
                        return false;
                    }
                }
            } else if (dif < 0) {
                message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_DIFFERENT);
                return false;
            }
        } catch (NumberFormatException exception) {
            message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_WRONGFORMAT);
            return false;
        } catch (CerberusException ex) {
            message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_BADLYDEFINED);
            return false;
        }
    }
    return true;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) TestCase(org.cerberus.crud.entity.TestCase) CountryEnvParam(org.cerberus.crud.entity.CountryEnvParam)

Example 14 with TestCase

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

the class ExecutionCheckService method checkActiveEnvironmentGroup.

private boolean checkActiveEnvironmentGroup(TestCaseExecution tCExecution) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Checking environment " + tCExecution.getCountryEnvParam().getEnvironment());
    }
    TestCase tc = tCExecution.getTestCaseObj();
    if (tCExecution.getEnvironmentDataObj().getGp1().equalsIgnoreCase("QA")) {
        return this.checkRunQA(tc, tCExecution.getEnvironmentData());
    } else if (tCExecution.getEnvironmentDataObj().getGp1().equalsIgnoreCase("UAT")) {
        return this.checkRunUAT(tc, tCExecution.getEnvironmentData());
    } else if (tCExecution.getEnvironmentDataObj().getGp1().equalsIgnoreCase("PROD")) {
        return this.checkRunPROD(tc, tCExecution.getEnvironmentData());
    } else if (tCExecution.getEnvironmentDataObj().getGp1().equalsIgnoreCase("DEV")) {
        return true;
    }
    message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_ENVIRONMENT_NOTDEFINED);
    message.setDescription(message.getDescription().replace("%ENV%", tCExecution.getEnvironmentData()));
    message.setDescription(message.getDescription().replace("%ENVGP%", tCExecution.getEnvironmentDataObj().getGp1()));
    return false;
}
Also used : MessageGeneral(org.cerberus.engine.entity.MessageGeneral) TestCase(org.cerberus.crud.entity.TestCase)

Example 15 with TestCase

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

TestCase (org.cerberus.crud.entity.TestCase)68 ITestCaseService (org.cerberus.crud.service.ITestCaseService)30 ArrayList (java.util.ArrayList)29 IFactoryTestCase (org.cerberus.crud.factory.IFactoryTestCase)29 JSONObject (org.json.JSONObject)26 AnswerItem (org.cerberus.util.answer.AnswerItem)24 ApplicationContext (org.springframework.context.ApplicationContext)24 MessageEvent (org.cerberus.engine.entity.MessageEvent)23 SQLException (java.sql.SQLException)17 TestCaseCountry (org.cerberus.crud.entity.TestCaseCountry)17 JSONArray (org.json.JSONArray)17 PolicyFactory (org.owasp.html.PolicyFactory)17 Connection (java.sql.Connection)16 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)16 CerberusException (org.cerberus.exception.CerberusException)16 TestCaseStep (org.cerberus.crud.entity.TestCaseStep)15 ILogEventService (org.cerberus.crud.service.ILogEventService)15 AnswerList (org.cerberus.util.answer.AnswerList)15 List (java.util.List)13