Search in sources :

Example 41 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral 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)

Example 42 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class SeleniumServerService method setCapabilityBrowser.

/**
 * Instanciate DesiredCapabilities regarding the browser
 *
 * @param capabilities
 * @param browser
 * @param tCExecution
 * @return
 * @throws CerberusException
 */
private DesiredCapabilities setCapabilityBrowser(DesiredCapabilities capabilities, String browser, TestCaseExecution tCExecution) throws CerberusException {
    try {
        if (browser.equalsIgnoreCase("firefox")) {
            capabilities = DesiredCapabilities.firefox();
            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("app.update.enabled", false);
            try {
                Invariant invariant = invariantService.convert(invariantService.readByKey("COUNTRY", tCExecution.getCountry()));
                if (invariant.getGp2() == null) {
                    LOG.warn("Country selected (" + tCExecution.getCountry() + ") has no value of GP2 in Invariant table, default language set to English (en)");
                    profile.setPreference("intl.accept_languages", "en");
                } else {
                    profile.setPreference("intl.accept_languages", invariant.getGp2());
                }
            } catch (CerberusException ex) {
                LOG.warn("Country selected (" + tCExecution.getCountry() + ") not in Invariant table, default language set to English (en)");
                profile.setPreference("intl.accept_languages", "en");
            }
            // Set UserAgent if testCaseUserAgent or robotUserAgent is defined
            String usedUserAgent = getUserAgentToUse(tCExecution.getTestCaseObj().getUserAgent(), tCExecution.getUserAgent());
            if (!StringUtil.isNullOrEmpty(usedUserAgent)) {
                profile.setPreference("general.useragent.override", usedUserAgent);
            }
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
        } else if (browser.equalsIgnoreCase("IE")) {
            capabilities = DesiredCapabilities.internetExplorer();
        } else if (browser.equalsIgnoreCase("chrome")) {
            capabilities = DesiredCapabilities.chrome();
            /**
             * Add custom capabilities
             */
            ChromeOptions options = new ChromeOptions();
            // Maximize windows for chrome browser
            options.addArguments("--start-fullscreen");
            // Set UserAgent if necessary
            String usedUserAgent = getUserAgentToUse(tCExecution.getTestCaseObj().getUserAgent(), tCExecution.getUserAgent());
            if (!StringUtil.isNullOrEmpty(usedUserAgent)) {
                options.addArguments("--user-agent=" + usedUserAgent);
            }
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        } else if (browser.contains("android")) {
            capabilities = DesiredCapabilities.android();
        } else if (browser.contains("ipad")) {
            capabilities = DesiredCapabilities.ipad();
        } else if (browser.contains("iphone")) {
            capabilities = DesiredCapabilities.iphone();
        } else if (browser.contains("safari")) {
            capabilities = DesiredCapabilities.safari();
        } else {
            LOG.warn("Not supported Browser : " + browser);
            MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
            mes.setDescription(mes.getDescription().replace("%MES%", "Browser '" + browser + "' is not supported"));
            mes.setDescription("Not supported Browser : " + browser);
            throw new CerberusException(mes);
        }
    } catch (CerberusException ex) {
        MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.EXECUTION_FA_SELENIUM);
        mes.setDescription(mes.getDescription().replace("%MES%", "Failed to set capability on the browser '" + browser + "' due to " + ex.getMessageError().getDescription()));
        throw new CerberusException(mes);
    }
    return capabilities;
}
Also used : Invariant(org.cerberus.crud.entity.Invariant) CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 43 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class TestCaseStepActionControlDAO method updateTestCaseStepActionControl.

@Override
public void updateTestCaseStepActionControl(TestCaseStepActionControl testCaseStepActionControl) throws CerberusException {
    boolean throwExcep = false;
    final String query = new StringBuilder("UPDATE `testcasestepactioncontrol` SET ").append("`Test` = ?, ").append("`TestCase` = ?, ").append("`Step` = ?, ").append("`Sequence` = ?, ").append("`ControlSequence` = ?, ").append("`Sort` = ?, ").append("`ConditionOper` = ?, ").append("`ConditionVal1` = ?, ").append("`ConditionVal2` = ?, ").append("`Control` = ?, ").append("`Value1` = ?, ").append("`Value2` = ?, ").append("`Description` = ?, ").append("`Fatal` = ?, ").append("`screenshotFilename` = ? ").append("WHERE `Test` = ? AND `TestCase` = ? AND `Step` = ? AND `Sequence` = ? AND `ControlSequence` = ? ").toString();
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        int i = 1;
        preStat.setString(i++, testCaseStepActionControl.getTest());
        preStat.setString(i++, testCaseStepActionControl.getTestCase());
        preStat.setInt(i++, testCaseStepActionControl.getStep());
        preStat.setInt(i++, testCaseStepActionControl.getSequence());
        preStat.setInt(i++, testCaseStepActionControl.getControlSequence());
        preStat.setInt(i++, testCaseStepActionControl.getSort());
        preStat.setString(i++, testCaseStepActionControl.getConditionOper());
        preStat.setString(i++, testCaseStepActionControl.getConditionVal1());
        preStat.setString(i++, testCaseStepActionControl.getConditionVal2());
        preStat.setString(i++, testCaseStepActionControl.getControl());
        preStat.setString(i++, testCaseStepActionControl.getValue1());
        preStat.setString(i++, testCaseStepActionControl.getValue2());
        preStat.setString(i++, testCaseStepActionControl.getDescription());
        preStat.setString(i++, testCaseStepActionControl.getFatal());
        preStat.setString(i++, testCaseStepActionControl.getScreenshotFilename());
        preStat.setString(i++, testCaseStepActionControl.getTest());
        preStat.setString(i++, testCaseStepActionControl.getTestCase());
        preStat.setInt(i++, testCaseStepActionControl.getStep());
        preStat.setInt(i++, testCaseStepActionControl.getSequence());
        preStat.setInt(i++, testCaseStepActionControl.getControlSequence());
        throwExcep = preStat.executeUpdate() == 0;
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    }
    if (throwExcep) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 44 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class TestCaseStepActionDAO method delete.

@Override
public void delete(TestCaseStepAction tcsa) throws CerberusException {
    boolean throwExcep = false;
    final String query = "DELETE FROM testcasestepaction WHERE test = ? and testcase = ? and step = ? and `sequence` = ?";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, tcsa.getTest());
            preStat.setString(2, tcsa.getTestCase());
            preStat.setInt(3, tcsa.getStep());
            preStat.setInt(4, tcsa.getSequence());
            throwExcep = preStat.executeUpdate() == 0;
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwExcep) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 45 with MessageGeneral

use of org.cerberus.engine.entity.MessageGeneral in project cerberus-source by cerberustesting.

the class TestCaseStepActionDAO method createTestCaseStepAction.

@Override
public void createTestCaseStepAction(TestCaseStepAction testCaseStepAction) throws CerberusException {
    boolean throwExcep = false;
    StringBuilder query = new StringBuilder();
    query.append("INSERT INTO testcasestepaction (`test`, `testCase`, `step`, `sequence`, `sort`, `conditionOper`, `conditionVal1`, `conditionVal2`, `action`, `value1`, `value2`, `ForceExeStatus`, `description`, `screenshotfilename`) ");
    query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, testCaseStepAction.getTest());
            preStat.setString(2, testCaseStepAction.getTestCase());
            preStat.setInt(3, testCaseStepAction.getStep());
            preStat.setInt(4, testCaseStepAction.getSequence());
            preStat.setInt(5, testCaseStepAction.getSort());
            preStat.setString(6, testCaseStepAction.getConditionOper());
            preStat.setString(7, testCaseStepAction.getConditionVal1());
            preStat.setString(8, testCaseStepAction.getConditionVal2());
            preStat.setString(9, testCaseStepAction.getAction());
            preStat.setString(10, testCaseStepAction.getValue1());
            preStat.setString(11, testCaseStepAction.getValue2());
            preStat.setString(12, testCaseStepAction.getForceExeStatus());
            preStat.setString(13, testCaseStepAction.getDescription());
            preStat.setString(14, testCaseStepAction.getScreenshotFilename());
            preStat.executeUpdate();
            throwExcep = false;
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    if (throwExcep) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

MessageGeneral (org.cerberus.engine.entity.MessageGeneral)71 CerberusException (org.cerberus.exception.CerberusException)61 Connection (java.sql.Connection)46 PreparedStatement (java.sql.PreparedStatement)46 SQLException (java.sql.SQLException)46 ResultSet (java.sql.ResultSet)18 ArrayList (java.util.ArrayList)12 Date (java.util.Date)10 TestCase (org.cerberus.crud.entity.TestCase)10 MessageEvent (org.cerberus.engine.entity.MessageEvent)8 AnswerItem (org.cerberus.util.answer.AnswerItem)7 Timestamp (java.sql.Timestamp)5 CerberusEventException (org.cerberus.exception.CerberusEventException)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 CountryEnvParam (org.cerberus.crud.entity.CountryEnvParam)4 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)4 TestCaseExecutionQueue (org.cerberus.crud.entity.TestCaseExecutionQueue)4 IOException (java.io.IOException)3 CampaignParameter (org.cerberus.crud.entity.CampaignParameter)3 IFactoryCampaignParameter (org.cerberus.crud.factory.IFactoryCampaignParameter)3