Search in sources :

Example 11 with CountryEnvironmentParameters

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

the class FactoryCountryEnvironmentParameters method create.

@Override
public CountryEnvironmentParameters create(String system, String country, String environment, String application, String ip, String domain, String url, String urlLogin, String var1, String var2, String var3, String var4, int poolSize) {
    CountryEnvironmentParameters object = new CountryEnvironmentParameters();
    object.setSystem(system);
    object.setCountry(country);
    object.setEnvironment(environment);
    object.setApplication(application);
    object.setIp(ip);
    object.setDomain(domain);
    object.setUrl(url);
    object.setUrlLogin(urlLogin);
    object.setVar1(var1);
    object.setVar2(var2);
    object.setVar3(var3);
    object.setVar4(var4);
    object.setPoolSize(poolSize);
    return object;
}
Also used : CountryEnvironmentParameters(org.cerberus.crud.entity.CountryEnvironmentParameters) IFactoryCountryEnvironmentParameters(org.cerberus.crud.factory.IFactoryCountryEnvironmentParameters)

Example 12 with CountryEnvironmentParameters

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

the class ExecutionStartService method startExecution.

@Override
public TestCaseExecution startExecution(TestCaseExecution tCExecution) throws CerberusException {
    /**
     * Start timestamp.
     */
    long executionStart = new Date().getTime();
    LOG.debug("Initializing Start Timestamp : " + executionStart);
    tCExecution.setStart(executionStart);
    /**
     * Checking the parameters.
     */
    LOG.debug("Checking the parameters.");
    Invariant myInvariant;
    try {
        myInvariant = invariantService.convert(invariantService.readByKey("OUTPUTFORMAT", tCExecution.getOutputFormat()));
    } catch (CerberusException ex) {
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_OUTPUTFORMAT_INVALID);
        mes.setDescription(mes.getDescription().replace("%PARAM%", tCExecution.getOutputFormat()));
        LOG.debug(mes.getDescription());
        throw new CerberusException(mes);
    }
    try {
        myInvariant = invariantService.convert(invariantService.readByKey("VERBOSE", String.valueOf(tCExecution.getVerbose())));
    } catch (CerberusException ex) {
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_VERBOSE_INVALID);
        mes.setDescription(mes.getDescription().replace("%PARAM%", String.valueOf(tCExecution.getVerbose())));
        LOG.debug(mes.getDescription());
        throw new CerberusException(mes);
    }
    try {
        myInvariant = invariantService.convert(invariantService.readByKey("SCREENSHOT", String.valueOf(tCExecution.getScreenshot())));
    } catch (CerberusException ex) {
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SCREENSHOT_INVALID);
        mes.setDescription(mes.getDescription().replace("%PARAM%", String.valueOf(tCExecution.getScreenshot())));
        LOG.debug(mes.getDescription());
        throw new CerberusException(mes);
    }
    LOG.debug("Parameters checked.");
    /**
     * Load TestCase information and set TCase to the TestCaseExecution
     * object.
     */
    tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_LOADINGDATA));
    LOG.debug("Loading Test Case Information. " + tCExecution.getTest() + "-" + tCExecution.getTestCase());
    // Integrate this.loadTestCaseService.loadTestCase(tCExecution); inside with Dependency.
    try {
        // TestCase tCase = testCaseService.findTestCaseByKey(tCExecution.getTest(), tCExecution.getTestCase());
        TestCase tCase = testCaseService.convert(testCaseService.readByKey(tCExecution.getTest(), tCExecution.getTestCase()));
        if (tCase != null) {
            tCExecution.setTestCaseObj(tCase);
            tCExecution.setDescription(tCase.getDescription());
            tCExecution.setConditionOper(tCase.getConditionOper());
            tCExecution.setConditionVal1(tCase.getConditionVal1());
            tCExecution.setConditionVal1Init(tCase.getConditionVal1());
            tCExecution.setConditionVal2(tCase.getConditionVal2());
            tCExecution.setConditionVal2Init(tCase.getConditionVal2());
            tCExecution.setTestCaseVersion(tCase.getTestCaseVersion());
        } else {
            throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
        }
        /**
         * Copy the status of the testcase to the status column of the
         * Execution. This is done to know how stable was the testcase at
         * the time of the execution.
         */
        tCExecution.setStatus(tCase.getStatus());
    } catch (CerberusException ex) {
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_TESTCASE_NOT_FOUND);
        mes.setDescription(mes.getDescription().replace("%TEST%", tCExecution.getTest()));
        mes.setDescription(mes.getDescription().replace("%TESTCASE%", tCExecution.getTestCase()));
        LOG.debug(mes.getDescription());
        throw new CerberusException(mes);
    }
    LOG.debug("Test Case Information Loaded - " + tCExecution.getTest() + "-" + tCExecution.getTestCase());
    /**
     * Load Test information and Set TestObject to the TestCaseExecution
     * object.
     */
    LOG.debug("Loading Test Information");
    try {
        tCExecution.setTestObj(this.testService.convert(this.testService.readByKey(tCExecution.getTest())));
    } catch (CerberusException ex) {
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_TEST_NOT_FOUND);
        mes.setDescription(mes.getDescription().replace("%TEST%", tCExecution.getTest()));
        LOG.debug(mes.getDescription());
        throw new CerberusException(mes);
    }
    LOG.debug("Test Information Loaded - " + tCExecution.getTest());
    /**
     * Load Application information and Set Application to the
     * TestCaseExecution object.
     */
    LOG.debug("Loading Application Information");
    try {
        tCExecution.setApplication(tCExecution.getTestCaseObj().getApplication());
        tCExecution.setApplicationObj(applicationService.convert(this.applicationService.readByKey(tCExecution.getTestCaseObj().getApplication())));
    } catch (CerberusException ex) {
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_APPLICATION_NOT_FOUND);
        mes.setDescription(mes.getDescription().replace("%APPLI%", tCExecution.getTestCaseObj().getApplication()));
        LOG.debug(mes.getDescription());
        throw new CerberusException(mes);
    }
    LOG.debug("Application Information Loaded - " + tCExecution.getApplicationObj().getApplication() + " - " + tCExecution.getApplicationObj().getDescription());
    /**
     * Init System from Application.
     */
    tCExecution.setSystem(tCExecution.getApplicationObj().getSystem());
    /**
     * Load Country information and Set it to the TestCaseExecution object.
     */
    LOG.debug("Loading Country Information");
    try {
        tCExecution.setCountryObj(invariantService.convert(invariantService.readByKey("COUNTRY", tCExecution.getCountry())));
    } catch (CerberusException ex) {
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_COUNTRY_NOT_FOUND);
        mes.setDescription(mes.getDescription().replace("%COUNTRY%", tCExecution.getCountry()));
        LOG.debug(mes.getDescription());
        throw new CerberusException(mes);
    }
    LOG.debug("Country Information Loaded - " + tCExecution.getCountryObj().getValue() + " - " + tCExecution.getCountryObj().getDescription());
    /**
     * Checking if execution is manual or automaticaly configured. If
     * Manual, CountryEnvironmentParameters object is manually created with
     * the servlet parameters. If automatic, parameters are build from the
     * CountryEnvironmentParameters. table in the database. Environmentdata
     * will always be filled with the environment. Environment will be
     * forced to MANUAL if execution is manual.
     */
    LOG.debug("Checking if connectivity parameters are manual or automatic from the database. '" + tCExecution.isManualURL() + "'");
    if (tCExecution.isManualURL()) {
        LOG.debug("Execution will be done with manual application connectivity setting.");
        if (StringUtil.isNullOrEmpty(tCExecution.getMyHost())) {
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_MANUALURL_INVALID);
            LOG.debug(mes.getDescription());
            throw new CerberusException(mes);
        } else {
            CountryEnvironmentParameters cea;
            cea = this.factorycountryEnvironmentParameters.create(tCExecution.getApplicationObj().getSystem(), tCExecution.getCountry(), tCExecution.getEnvironment(), tCExecution.getApplicationObj().getApplication(), tCExecution.getMyHost(), "", tCExecution.getMyContextRoot(), tCExecution.getMyLoginRelativeURL(), "", "", "", "", CountryEnvironmentParameters.DEFAULT_POOLSIZE);
            cea.setIp(tCExecution.getMyHost());
            cea.setUrl(tCExecution.getMyContextRoot());
            tCExecution.setUrl(StringUtil.getURLFromString(cea.getIp(), cea.getUrl(), "", ""));
            cea.setUrlLogin(tCExecution.getMyLoginRelativeURL());
            tCExecution.setCountryEnvironmentParameters(cea);
            LOG.debug(" -> Execution will be done with manual application connectivity setting. IP/URL/LOGIN : " + cea.getIp() + "-" + cea.getUrl() + "-" + cea.getUrlLogin());
        }
        /**
         * If execution is manual, we force the env at 'MANUAL-ENVDATA'
         * string. We keep envData information in order to trace the env
         * data that has been used.
         */
        tCExecution.setEnvironment("MANUAL-" + tCExecution.getEnvironmentData());
    } else {
        /**
         * Automatic application configuration execution.
         */
        LOG.debug("Execution will be done with automatic application connectivity setting.");
        /**
         * Load Country/Environment/Application information and set them to
         * the TestCaseExecution object
         */
        LOG.debug("Loading Country/Environment/Application Information. " + tCExecution.getCountry() + "-" + tCExecution.getEnvironment() + "-" + tCExecution.getApplicationObj().getApplication());
        CountryEnvironmentParameters cea;
        try {
            cea = this.countryEnvironmentParametersService.convert(this.countryEnvironmentParametersService.readByKey(tCExecution.getApplicationObj().getSystem(), tCExecution.getCountry(), tCExecution.getEnvironment(), tCExecution.getApplicationObj().getApplication()));
            if (cea != null) {
                tCExecution.setCountryEnvironmentParameters(cea);
                // tCExecution.setUrl(cea.getIp()+ cea.getUrl());
                tCExecution.setUrl(StringUtil.getURLFromString(cea.getIp(), cea.getUrl(), "", ""));
            } else {
                MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_COUNTRYENVAPP_NOT_FOUND);
                mes.setDescription(mes.getDescription().replace("%COUNTRY%", tCExecution.getCountry()));
                mes.setDescription(mes.getDescription().replace("%ENV%", tCExecution.getEnvironment()));
                mes.setDescription(mes.getDescription().replace("%APPLI%", tCExecution.getTestCaseObj().getApplication()));
                LOG.error(mes.getDescription());
                throw new CerberusException(mes);
            }
        /**
         * Forcing the IP URL and Login config from DevIP, DevURL and
         * DevLogin parameter only if DevURL is defined.
         */
        } catch (CerberusException ex) {
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_COUNTRYENVAPP_NOT_FOUND);
            mes.setDescription(mes.getDescription().replace("%COUNTRY%", tCExecution.getCountry()));
            mes.setDescription(mes.getDescription().replace("%ENV%", tCExecution.getEnvironment()));
            mes.setDescription(mes.getDescription().replace("%APPLI%", tCExecution.getTestCaseObj().getApplication()));
            LOG.error(mes.getDescription());
            throw new CerberusException(mes);
        }
        LOG.debug("Country/Environment/Application Information Loaded. " + tCExecution.getCountry() + " - " + tCExecution.getEnvironment() + " - " + tCExecution.getApplicationObj().getApplication());
        LOG.debug(" -> Execution will be done with automatic application connectivity setting. IP/URL/LOGIN : " + cea.getIp() + "-" + cea.getUrl() + "-" + cea.getUrlLogin());
        tCExecution.setEnvironmentData(tCExecution.getEnvironment());
    }
    /**
     * Load Environment object from invariant table.
     */
    LOG.debug("Loading Environment Information. " + tCExecution.getEnvironmentData());
    try {
        tCExecution.setEnvironmentDataObj(invariantService.convert(invariantService.readByKey("ENVIRONMENT", tCExecution.getEnvironmentData())));
    } catch (CerberusException ex) {
        if (tCExecution.isManualURL()) {
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_ENVIRONMENT_DOESNOTEXIST_MAN);
            mes.setDescription(mes.getDescription().replace("%ENV%", tCExecution.getEnvironmentData()));
            LOG.debug(mes.getDescription());
            throw new CerberusException(mes);
        } else {
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_ENVIRONMENT_DOESNOTEXIST);
            mes.setDescription(mes.getDescription().replace("%ENV%", tCExecution.getEnvironmentData()));
            LOG.debug(mes.getDescription());
            throw new CerberusException(mes);
        }
    }
    LOG.debug("Environment Information Loaded");
    /**
     * Load Country/Environment information and set them to the
     * TestCaseExecution object. Environment considered here is the data
     * environment.
     */
    LOG.debug("Loading Country/Environment Information. " + tCExecution.getCountry() + " - " + tCExecution.getEnvironmentData());
    CountryEnvParam countEnvParam;
    try {
        countEnvParam = this.countryEnvParamService.convert(this.countryEnvParamService.readByKey(tCExecution.getApplicationObj().getSystem(), tCExecution.getCountry(), tCExecution.getEnvironmentData()));
        tCExecution.setCountryEnvParam(countEnvParam);
        /**
         * Copy the Build/Revision of the environment to the Execution. This
         * is done to keep track of all execution done on a specific version
         * of system
         */
        tCExecution.setBuild(countEnvParam.getBuild());
        tCExecution.setRevision(countEnvParam.getRevision());
    } catch (CerberusException ex) {
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_COUNTRYENV_NOT_FOUND);
        mes.setDescription(mes.getDescription().replace("%SYSTEM%", tCExecution.getApplicationObj().getSystem()));
        mes.setDescription(mes.getDescription().replace("%COUNTRY%", tCExecution.getCountry()));
        mes.setDescription(mes.getDescription().replace("%ENV%", tCExecution.getEnvironmentData()));
        LOG.debug(mes.getDescription());
        throw new CerberusException(mes);
    }
    LOG.debug("Country/Environment Information Loaded. " + tCExecution.getCountry() + " - " + tCExecution.getEnvironmentData());
    /**
     * If Timeout is defined at the execution level, set action wait default
     * to this value, else Get the cerberus_action_wait_default parameter.
     * This parameter will be used by tha wait action if no timeout/event is
     * defined.
     */
    try {
        if (!tCExecution.getTimeout().isEmpty()) {
            tCExecution.setCerberus_action_wait_default(Integer.valueOf(tCExecution.getTimeout()));
        } else {
            tCExecution.setCerberus_action_wait_default(parameterService.getParameterIntegerByKey("cerberus_action_wait_default", tCExecution.getApplicationObj().getSystem(), 90000));
        }
    } catch (NumberFormatException ex) {
        LOG.warn("Parameter cerberus_action_wait_default must be an integer, default value set to 90000 milliseconds. " + ex.toString());
        tCExecution.setCerberus_action_wait_default(90000);
    }
    /**
     * Check if test can be executed TODO : Replace Message with try/catch
     * cerberus exception
     */
    tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_VALIDATIONSTARTING));
    LOG.debug("Performing the Checks before starting the execution");
    MessageGeneral canExecuteTestCase = this.executionCheckService.checkTestCaseExecution(tCExecution);
    tCExecution.setResultMessage(canExecuteTestCase);
    /**
     * We stop if the result is not OK
     */
    if (!(tCExecution.getResultMessage().equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_CHECKINGPARAMETERS)))) {
        return tCExecution;
    }
    LOG.debug("Checks performed -- > OK to continue.");
    /**
     * For GUI application, check if Browser is supported.
     */
    if (!tCExecution.getManualExecution().equals("Y") && tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI)) {
        try {
            myInvariant = invariantService.convert(invariantService.readByKey("BROWSER", tCExecution.getBrowser()));
        } catch (CerberusException ex) {
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_BROWSER_NOT_SUPPORTED);
            mes.setDescription(mes.getDescription().replace("%BROWSER%", tCExecution.getBrowser()));
            LOG.debug(mes.getDescription());
            throw new CerberusException(mes);
        }
    }
    /**
     * Start server if execution is not manual
     */
    if (!tCExecution.getManualExecution().equals("Y")) {
        tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_STARTINGROBOTSERVER));
        if (tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_APK) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_IPA) || tCExecution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_FAT)) {
            if (tCExecution.getIp().equalsIgnoreCase("")) {
                MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_SELENIUM_EMPTYORBADIP);
                mes.setDescription(mes.getDescription().replace("%IP%", tCExecution.getIp()));
                LOG.debug(mes.getDescription());
                throw new CerberusException(mes);
            }
            /**
             * Start Selenium server
             */
            LOG.debug("Starting Server.");
            tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_CREATINGRUNID));
            try {
                this.serverService.startServer(tCExecution);
            } catch (CerberusException ex) {
                LOG.debug(ex.getMessageError().getDescription());
                throw new CerberusException(ex.getMessageError());
            }
            LOG.debug("Server Started.");
        }
    }
    /**
     * Register RunID inside database.
     */
    tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_CREATINGRUNID));
    LOG.debug("Registering Execution ID on database");
    long runID = 0;
    try {
        runID = this.testCaseExecutionService.registerRunID(tCExecution);
        if (runID != 0) {
            tCExecution.setId(runID);
            executionUUIDObject.setExecutionUUID(tCExecution.getExecutionUUID(), tCExecution);
            // Update Queue Execution here if QueueID =! 0.
            if (tCExecution.getQueueID() != 0) {
                inQueueService.updateToExecuting(tCExecution.getQueueID(), "", runID);
            }
        } else {
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_COULDNOTCREATE_RUNID);
            tCExecution.setResultMessage(mes);
            LOG.fatal("Could not create RunID, or cannot retreive the generated Key");
            throw new CerberusException(mes);
        }
    } catch (CerberusException ex) {
        tCExecution.setResultMessage(new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_COULDNOTCREATE_RUNID));
        LOG.warn(ex.getMessageError().getDescription());
        throw new CerberusException(ex.getMessageError());
    }
    LOG.debug("Execution ID registered on database : " + tCExecution.getId());
    /**
     * Stop the browser if executionID is equal to zero (to prevent database
     * instabilities)
     */
    if (!tCExecution.getManualExecution().equals("Y")) {
        try {
            if (tCExecution.getId() == 0) {
                LOG.debug("Starting to Stop the Selenium Server.");
                this.serverService.stopServer(tCExecution.getSession());
                LOG.debug("Selenium Server stopped.");
            }
        } catch (Exception ex) {
            LOG.warn(ex.toString());
        }
    }
    /**
     * Feature Flipping. Should be removed when websocket push is fully
     * working
     */
    tCExecution.setCerberus_featureflipping_activatewebsocketpush(parameterService.getParameterBooleanByKey("cerberus_featureflipping_activatewebsocketpush", "", false));
    tCExecution.setCerberus_featureflipping_websocketpushperiod(parameterService.getParameterLongByKey("cerberus_featureflipping_websocketpushperiod", "", 5000));
    return tCExecution;
}
Also used : Invariant(org.cerberus.crud.entity.Invariant) CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) TestCase(org.cerberus.crud.entity.TestCase) IFactoryCountryEnvironmentParameters(org.cerberus.crud.factory.IFactoryCountryEnvironmentParameters) CountryEnvironmentParameters(org.cerberus.crud.entity.CountryEnvironmentParameters) CountryEnvParam(org.cerberus.crud.entity.CountryEnvParam) Date(java.util.Date) CerberusException(org.cerberus.exception.CerberusException)

Aggregations

CountryEnvironmentParameters (org.cerberus.crud.entity.CountryEnvironmentParameters)12 IFactoryCountryEnvironmentParameters (org.cerberus.crud.factory.IFactoryCountryEnvironmentParameters)10 ArrayList (java.util.ArrayList)7 JSONObject (org.json.JSONObject)6 ICountryEnvironmentParametersService (org.cerberus.crud.service.ICountryEnvironmentParametersService)5 MessageEvent (org.cerberus.engine.entity.MessageEvent)5 CerberusException (org.cerberus.exception.CerberusException)4 AnswerItem (org.cerberus.util.answer.AnswerItem)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 CountryEnvParam (org.cerberus.crud.entity.CountryEnvParam)3 Answer (org.cerberus.util.answer.Answer)3 JSONArray (org.json.JSONArray)3 PolicyFactory (org.owasp.html.PolicyFactory)3 ILogEventService (org.cerberus.crud.service.ILogEventService)2 MessageGeneral (org.cerberus.engine.entity.MessageGeneral)2 AnswerList (org.cerberus.util.answer.AnswerList)2 JSONException (org.json.JSONException)2