Search in sources :

Example 21 with MessageGeneral

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

the class ControlService method doControl.

@Override
public TestCaseStepActionControlExecution doControl(TestCaseStepActionControlExecution testCaseStepActionControlExecution) {
    MessageEvent res;
    TestCaseExecution tCExecution = testCaseStepActionControlExecution.getTestCaseStepActionExecution().getTestCaseStepExecution().gettCExecution();
    AnswerItem<String> answerDecode = new AnswerItem();
    /**
     * Decode the 2 fields property and values before doing the control.
     */
    try {
        // then the execution of this control should not performed
        if (testCaseStepActionControlExecution.getValue1().contains("%")) {
            // When starting a new control, we reset the property list that was already calculated.
            tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
            answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getValue1(), tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), false);
            testCaseStepActionControlExecution.setValue1((String) answerDecode.getItem());
            if (!(answerDecode.isCodeStringEquals("OK"))) {
                // If anything wrong with the decode --> we stop here with decode message in the control result.
                testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Value1"));
                testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
                testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
                testCaseStepActionControlExecution.setEnd(new Date().getTime());
                LOG.debug("Control interupted due to decode 'Control Value1' Error.");
                return testCaseStepActionControlExecution;
            }
        }
        if (testCaseStepActionControlExecution.getValue2().contains("%")) {
            // When starting a new control, we reset the property list that was already calculated.
            tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
            answerDecode = variableService.decodeStringCompletly(testCaseStepActionControlExecution.getValue2(), tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), false);
            testCaseStepActionControlExecution.setValue2((String) answerDecode.getItem());
            if (!(answerDecode.isCodeStringEquals("OK"))) {
                // If anything wrong with the decode --> we stop here with decode message in the control result.
                testCaseStepActionControlExecution.setControlResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Control Value2"));
                testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
                testCaseStepActionControlExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
                testCaseStepActionControlExecution.setEnd(new Date().getTime());
                LOG.debug("Control interupted due to decode 'Control Value2' Error.");
                return testCaseStepActionControlExecution;
            }
        }
    } catch (CerberusEventException cex) {
        testCaseStepActionControlExecution.setControlResultMessage(cex.getMessageError());
        testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));
        return testCaseStepActionControlExecution;
    }
    /**
     * Timestamp starts after the decode. TODO protect when property is
     * null.
     */
    testCaseStepActionControlExecution.setStart(new Date().getTime());
    // When starting a new control, we reset the property list that was already calculated.
    tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
    try {
        switch(testCaseStepActionControlExecution.getControl()) {
            case TestCaseStepActionControl.CONTROL_VERIFYSTRINGEQUAL:
                res = this.verifyStringEqual(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYSTRINGDIFFERENT:
                res = this.verifyStringDifferent(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYSTRINGGREATER:
                res = this.verifyStringGreater(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYSTRINGMINOR:
                res = this.verifyStringMinor(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYSTRINGCONTAINS:
                res = this.verifyStringContains(testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYNUMERICEQUALS:
            case TestCaseStepActionControl.CONTROL_VERIFYNUMERICDIFFERENT:
            case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATER:
            case TestCaseStepActionControl.CONTROL_VERIFYNUMERICGREATEROREQUAL:
            case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOR:
            case TestCaseStepActionControl.CONTROL_VERIFYNUMERICMINOROREQUAL:
                res = this.evaluateControl_ifNumericXXX(testCaseStepActionControlExecution.getControl(), testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTPRESENT:
                // TODO validate properties
                res = this.verifyElementPresent(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTPRESENT:
                // TODO validate properties
                res = this.verifyElementNotPresent(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTVISIBLE:
                // TODO validate properties
                res = this.verifyElementVisible(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTVISIBLE:
                // TODO validate properties
                res = this.verifyElementNotVisible(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTEQUALS:
                res = this.verifyElementEquals(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTDIFFERENT:
                res = this.verifyElementDifferent(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTINELEMENT:
                // TODO validate properties
                res = this.verifyElementInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTCLICKABLE:
                res = this.verifyElementClickable(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYELEMENTNOTCLICKABLE:
                res = this.verifyElementNotClickable(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYTEXTINELEMENT:
                res = this.verifyTextInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINELEMENT:
                res = this.verifyTextNotInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYREGEXINELEMENT:
                res = this.VerifyRegexInElement(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYTEXTINPAGE:
                res = this.VerifyTextInPage(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYTEXTNOTINPAGE:
                res = this.VerifyTextNotInPage(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYTITLE:
                res = this.verifyTitle(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYURL:
                res = this.verifyUrl(tCExecution, testCaseStepActionControlExecution.getValue1());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYTEXTINDIALOG:
                res = this.verifyTextInDialog(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_VERIFYXMLTREESTRUCTURE:
                res = this.verifyXmlTreeStructure(tCExecution, testCaseStepActionControlExecution.getValue1(), testCaseStepActionControlExecution.getValue2());
                break;
            case TestCaseStepActionControl.CONTROL_TAKESCREENSHOT:
                res = this.takeScreenshot(tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), testCaseStepActionControlExecution);
                break;
            case TestCaseStepActionControl.CONTROL_GETPAGESOURCE:
                res = this.getPageSource(tCExecution, testCaseStepActionControlExecution.getTestCaseStepActionExecution(), testCaseStepActionControlExecution);
                break;
            default:
                res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_UNKNOWNCONTROL);
                res.setDescription(res.getDescription().replace("%CONTROL%", testCaseStepActionControlExecution.getControl()));
        }
    } catch (final CerberusEventException exception) {
        res = exception.getMessageError();
    } catch (final Exception unexpected) {
        LOG.error("Unexpected exception: " + unexpected.getMessage(), unexpected);
        res = new MessageEvent(MessageEventEnum.CONTROL_FAILED_GENERIC).resolveDescription("ERROR", unexpected.getMessage());
    }
    testCaseStepActionControlExecution.setControlResultMessage(res);
    /**
     * Updating Control result message only if control is not successful.
     * This is to keep the last KO information and preventing KO to be
     * transformed to OK.
     */
    if (!(res.equals(new MessageEvent(MessageEventEnum.CONTROL_SUCCESS)))) {
        testCaseStepActionControlExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));
    }
    /**
     * We only stop the test if Control Event message is in stop status AND
     * the control is FATAL. If control is not fatal, we continue the test
     * but refresh the Execution status.
     */
    if (res.isStopTest()) {
        if (testCaseStepActionControlExecution.getFatal().equals("Y")) {
            testCaseStepActionControlExecution.setStopExecution(true);
        }
    }
    testCaseStepActionControlExecution.setEnd(new Date().getTime());
    return testCaseStepActionControlExecution;
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) AnswerItem(org.cerberus.util.answer.AnswerItem) Date(java.util.Date) WebDriverException(org.openqa.selenium.WebDriverException) PatternSyntaxException(java.util.regex.PatternSyntaxException) CerberusEventException(org.cerberus.exception.CerberusEventException) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 22 with MessageGeneral

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

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

the class ExecutionCheckService method checkRunPROD.

private boolean checkRunPROD(TestCase tc, String env) {
    if (tc.getActivePROD().equals("Y")) {
        return true;
    }
    message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RUNPROD_NOTDEFINED);
    message.setDescription(message.getDescription().replace("%ENV%", env));
    return false;
}
Also used : MessageGeneral(org.cerberus.engine.entity.MessageGeneral)

Example 24 with MessageGeneral

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

the class ExecutionCheckService method checkRunQA.

private boolean checkRunQA(TestCase tc, String env) {
    if (tc.getActiveQA().equals("Y")) {
        return true;
    }
    message = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RUNQA_NOTDEFINED);
    message.setDescription(message.getDescription().replace("%ENV%", env));
    return false;
}
Also used : MessageGeneral(org.cerberus.engine.entity.MessageGeneral)

Example 25 with MessageGeneral

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

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