Search in sources :

Example 51 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class BuildRevisionParametersService method check_buildRevisionAlreadyUsed.

@Override
public boolean check_buildRevisionAlreadyUsed(String application, String build, String revision) {
    try {
        // First set is to get the system value
        String system = "";
        system = applicationService.convert(applicationService.readByKey(application)).getSystem();
        // Then we check here inside countryenvparam_log table is the build revision has already been used.
        AnswerList resp = countryEnvParamLogService.readByVariousByCriteria(system, null, null, build, revision, 0, 0, "id", "asc", null, null);
        if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getTotalRows() > 0) {
            return true;
        } else {
            return false;
        }
    } catch (CerberusException ex) {
        LOG.error(ex);
    }
    return true;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) CerberusException(org.cerberus.exception.CerberusException)

Example 52 with CerberusException

use of org.cerberus.exception.CerberusException 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 53 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class RobotService method fillCapabilities.

private AnswerItem<Robot> fillCapabilities(AnswerItem<Robot> robotItem) {
    try {
        Robot robot = convert(robotItem);
        robot.setCapabilities(robotCapabilityService.convert(robotCapabilityService.readByRobot(robot.getRobot())));
    } catch (CerberusException e) {
        LOGGER.warn("Unable to flll robot capabilities due to " + e.getMessage());
    }
    return robotItem;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) Robot(org.cerberus.crud.entity.Robot)

Example 54 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class AppServiceContentService method compareListAndUpdateInsertDeleteElements.

@Override
public Answer compareListAndUpdateInsertDeleteElements(String service, List<AppServiceContent> newList) {
    Answer ans = new Answer(null);
    MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
    Answer finalAnswer = new Answer(msg1);
    List<AppServiceContent> oldList = new ArrayList();
    try {
        oldList = this.convert(this.readByVarious(service, null));
    } catch (CerberusException ex) {
        LOG.error(ex);
    }
    /**
     * Update and Create all objects database Objects from newList
     */
    List<AppServiceContent> listToUpdateOrInsert = new ArrayList(newList);
    listToUpdateOrInsert.removeAll(oldList);
    List<AppServiceContent> listToUpdateOrInsertToIterate = new ArrayList(listToUpdateOrInsert);
    for (AppServiceContent objectDifference : listToUpdateOrInsertToIterate) {
        for (AppServiceContent objectInDatabase : oldList) {
            if (objectDifference.hasSameKey(objectInDatabase)) {
                ans = this.update(objectDifference.getService(), objectDifference.getKey(), objectDifference);
                finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                listToUpdateOrInsert.remove(objectDifference);
            }
        }
    }
    /**
     * Delete all objects database Objects that do not exist from newList
     */
    List<AppServiceContent> listToDelete = new ArrayList(oldList);
    listToDelete.removeAll(newList);
    List<AppServiceContent> listToDeleteToIterate = new ArrayList(listToDelete);
    for (AppServiceContent tcsDifference : listToDeleteToIterate) {
        for (AppServiceContent tcsInPage : newList) {
            if (tcsDifference.hasSameKey(tcsInPage)) {
                listToDelete.remove(tcsDifference);
            }
        }
    }
    if (!listToDelete.isEmpty()) {
        ans = this.deleteList(listToDelete);
        finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
    }
    // We insert only at the end (after deletion of all potencial enreg - linked with #1281)
    if (!listToUpdateOrInsert.isEmpty()) {
        ans = this.createList(listToUpdateOrInsert);
        finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
    }
    return finalAnswer;
}
Also used : Answer(org.cerberus.util.answer.Answer) CerberusException(org.cerberus.exception.CerberusException) MessageEvent(org.cerberus.engine.entity.MessageEvent) AppServiceContent(org.cerberus.crud.entity.AppServiceContent) ArrayList(java.util.ArrayList)

Example 55 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class ActionService method doActionCalculateProperty.

private MessageEvent doActionCalculateProperty(TestCaseStepActionExecution testCaseStepActionExecution, String value1, String value2) {
    MessageEvent message;
    AnswerItem<String> answerDecode = new AnswerItem();
    if (StringUtil.isNullOrEmpty(value1)) {
        // Value1 is a mandatory parameter.
        message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_MISSINGPROPERTY);
        message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY));
    } else {
        try {
            TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();
            // Getting the Country property definition.
            TestCaseCountryProperties tccp = null;
            boolean propertyExistOnAnyCountry = false;
            for (TestCaseCountryProperties object : tCExecution.getTestCaseCountryPropertyList()) {
                if ((object.getProperty().equalsIgnoreCase(value1)) && (object.getCountry().equalsIgnoreCase(tCExecution.getCountry()))) {
                    tccp = object;
                }
                if ((object.getProperty().equalsIgnoreCase(value1))) {
                    propertyExistOnAnyCountry = true;
                }
            }
            if (tccp == null) {
                // Could not find a country property inside the existing execution.
                if (propertyExistOnAnyCountry) {
                    message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NO_PROPERTY_DEFINITION);
                    message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY).replace("%PROP%", value1).replace("%COUNTRY%", tCExecution.getCountry()));
                    return message;
                } else {
                    message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_PROPERTYNOTFOUND);
                    message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY).replace("%PROP%", value1).replace("%COUNTRY%", tCExecution.getCountry()));
                    return message;
                }
            } else {
                if (!(StringUtil.isNullOrEmpty(value2))) {
                    // If value2 is fed with something, we control here that value is a valid property name and gets its defintion.
                    tccp = null;
                    propertyExistOnAnyCountry = false;
                    for (TestCaseCountryProperties object : tCExecution.getTestCaseCountryPropertyList()) {
                        if ((object.getProperty().equalsIgnoreCase(value2)) && (object.getCountry().equalsIgnoreCase(tCExecution.getCountry()))) {
                            tccp = object;
                        }
                        if ((object.getProperty().equalsIgnoreCase(value2))) {
                            propertyExistOnAnyCountry = true;
                        }
                    }
                    if (tccp == null) {
                        // Could not find a country property inside the existing execution.
                        if (propertyExistOnAnyCountry) {
                            message = new MessageEvent(MessageEventEnum.ACTION_NOTEXECUTED_NO_PROPERTY_DEFINITION);
                            message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY).replace("%PROP%", value2).replace("%COUNTRY%", tCExecution.getCountry()));
                            return message;
                        } else {
                            message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALCULATEPROPERTY_PROPERTYNOTFOUND);
                            message.setDescription(message.getDescription().replace("%ACTION%", TestCaseStepAction.ACTION_CALCULATEPROPERTY).replace("%PROP%", value2).replace("%COUNTRY%", tCExecution.getCountry()));
                            return message;
                        }
                    }
                }
                // We calculate the property here.
                long now = new Date().getTime();
                TestCaseExecutionData tcExeData;
                tcExeData = factoryTestCaseExecutionData.create(tCExecution.getId(), tccp.getProperty(), 1, tccp.getDescription(), null, tccp.getType(), tccp.getValue1(), tccp.getValue2(), null, null, now, now, now, now, new MessageEvent(MessageEventEnum.PROPERTY_PENDING), tccp.getRetryNb(), tccp.getRetryPeriod(), tccp.getDatabase(), tccp.getValue1(), tccp.getValue2(), tccp.getLength(), tccp.getLength(), tccp.getRowLimit(), tccp.getNature(), "", "", "", "", "", "N");
                tcExeData.setTestCaseCountryProperties(tccp);
                propertyService.calculateProperty(tcExeData, tCExecution, testCaseStepActionExecution, tccp, true);
                // Property message goes to Action message.
                message = tcExeData.getPropertyResultMessage();
                if (message.getCodeString().equals("OK")) {
                    // If Property calculated successfully we summarize the message to a shorter version.
                    message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALCULATEPROPERTY);
                    message.setDescription(message.getDescription().replace("%PROP%", value1).replace("%VALUE%", tcExeData.getValue()));
                    if (tcExeData.getDataLibRawData() != null) {
                        message.setDescription(message.getDescription() + " %NBROWS% row(s) with %NBSUBDATA% Subdata(s) calculated.".replace("%NBROWS%", String.valueOf(tcExeData.getDataLibRawData().size())).replace("%NBSUBDATA%", String.valueOf(tcExeData.getDataLibRawData().get(0).size())));
                    }
                }
                if (!(StringUtil.isNullOrEmpty(value2))) {
                    // If value2 is fed we force the result to value1.
                    tcExeData.setProperty(value1);
                }
                // saves the result
                try {
                    testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcExeData));
                    LOG.debug("Adding into Execution data list. Property : '" + tcExeData.getProperty() + "' Index : '" + tcExeData.getIndex() + "' Value : '" + tcExeData.getValue() + "'");
                    tCExecution.getTestCaseExecutionDataMap().put(tcExeData.getProperty(), tcExeData);
                    if (tcExeData.getDataLibRawData() != null) {
                        // If the property is a TestDataLib, we same all rows retreived in order to support nature such as NOTINUSe or RANDOMNEW.
                        for (int i = 1; i < (tcExeData.getDataLibRawData().size()); i++) {
                            now = new Date().getTime();
                            TestCaseExecutionData tcedS = factoryTestCaseExecutionData.create(tcExeData.getId(), tcExeData.getProperty(), (i + 1), tcExeData.getDescription(), tcExeData.getDataLibRawData().get(i).get(""), tcExeData.getType(), "", "", tcExeData.getRC(), "", now, now, now, now, null, 0, 0, "", "", "", "", "", 0, "", "", "", "", "", "", "N");
                            testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcedS));
                        }
                    }
                } catch (CerberusException cex) {
                    LOG.error(cex.getMessage(), cex);
                }
            }
        } catch (Exception ex) {
            LOG.error(ex.toString(), ex);
            message = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC).resolveDescription("DETAIL", ex.toString());
        }
    }
    return message;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) CerberusException(org.cerberus.exception.CerberusException) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) MessageEvent(org.cerberus.engine.entity.MessageEvent) TestCaseExecutionData(org.cerberus.crud.entity.TestCaseExecutionData) IFactoryTestCaseExecutionData(org.cerberus.crud.factory.IFactoryTestCaseExecutionData) AnswerItem(org.cerberus.util.answer.AnswerItem) Date(java.util.Date) CerberusEventException(org.cerberus.exception.CerberusEventException) CerberusException(org.cerberus.exception.CerberusException)

Aggregations

CerberusException (org.cerberus.exception.CerberusException)159 MessageEvent (org.cerberus.engine.entity.MessageEvent)64 MessageGeneral (org.cerberus.engine.entity.MessageGeneral)58 ApplicationContext (org.springframework.context.ApplicationContext)58 JSONObject (org.json.JSONObject)54 JSONException (org.json.JSONException)53 Connection (java.sql.Connection)48 SQLException (java.sql.SQLException)48 PreparedStatement (java.sql.PreparedStatement)47 AnswerItem (org.cerberus.util.answer.AnswerItem)41 ArrayList (java.util.ArrayList)37 IOException (java.io.IOException)35 PolicyFactory (org.owasp.html.PolicyFactory)35 ILogEventService (org.cerberus.crud.service.ILogEventService)34 Answer (org.cerberus.util.answer.Answer)34 ServletException (javax.servlet.ServletException)26 ResultSet (java.sql.ResultSet)18 TestCase (org.cerberus.crud.entity.TestCase)16 JSONArray (org.json.JSONArray)16 HashMap (java.util.HashMap)12