Search in sources :

Example 96 with CerberusException

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

the class GetParameter method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String echo = request.getParameter("sEcho");
    String mySystem = request.getParameter("system");
    LOG.debug("System : '" + mySystem + "'.");
    // data that will be shown in the table
    JSONArray data = new JSONArray();
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IParameterService parameterService = appContext.getBean(ParameterService.class);
    try {
        JSONObject jsonResponse = new JSONObject();
        try {
            for (Parameter myParameter : parameterService.findAllParameter()) {
                JSONArray row = new JSONArray();
                row.put(myParameter.getParam()).put(myParameter.getValue()).put(myParameter.getValue()).put(myParameter.getDescription());
                data.put(row);
            }
        } catch (CerberusException ex) {
            response.setContentType("text/html");
            response.getWriter().print(ex.getMessageError().getDescription());
        }
        jsonResponse.put("aaData", data);
        jsonResponse.put("sEcho", echo);
        jsonResponse.put("iTotalRecords", data.length());
        jsonResponse.put("iTotalDisplayRecords", data.length());
        response.setContentType("application/json");
        response.getWriter().print(jsonResponse.toString());
    } catch (JSONException e) {
        LOG.warn(e);
        response.setContentType("text/html");
        response.getWriter().print(e.getMessage());
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) CerberusException(org.cerberus.exception.CerberusException) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Parameter(org.cerberus.crud.entity.Parameter) JSONException(org.json.JSONException) IParameterService(org.cerberus.crud.service.IParameterService)

Example 97 with CerberusException

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

the class PropertyService method decodeStringWithExistingProperties.

@Override
public AnswerItem<String> decodeStringWithExistingProperties(String stringToDecode, TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, boolean forceCalculation) throws CerberusEventException {
    MessageEvent msg = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS);
    AnswerItem<String> answer = new AnswerItem();
    answer.setResultMessage(msg);
    answer.setItem(stringToDecode);
    String country = tCExecution.getCountry();
    long now = new Date().getTime();
    String stringToDecodeInit = stringToDecode;
    if (LOG.isDebugEnabled()) {
        LOG.debug("Starting to decode string (Property) : " + stringToDecode);
    }
    /**
     * Look at all the potencial properties still contained in
     * StringToDecode (considering that properties are between %).
     */
    List<String> internalPropertiesFromStringToDecode = this.getPropertiesListFromString(stringToDecode);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Internal potencial properties still found inside property '" + stringToDecode + "' : " + internalPropertiesFromStringToDecode);
    }
    if (internalPropertiesFromStringToDecode.isEmpty()) {
        // We escape if no property found on the string to decode
        if (LOG.isDebugEnabled()) {
            LOG.debug("Finished to decode (no properties detected in string) : . result : '" + stringToDecodeInit + "' to :'" + stringToDecode + "'");
        }
        answer.setItem(stringToDecode);
        answer.setResultMessage(msg);
        return answer;
    }
    /**
     * Get the list of properties needed to calculate the required property
     */
    List<TestCaseCountryProperties> tcProperties = tCExecution.getTestCaseCountryPropertyList();
    List<TestCaseCountryProperties> linkedProperties = new ArrayList();
    for (String internalProperty : internalPropertiesFromStringToDecode) {
        // Looping on potential properties in string to decode.
        List<TestCaseCountryProperties> newLinkedProperties = new ArrayList();
        newLinkedProperties = this.getListOfPropertiesLinkedToProperty(country, internalProperty, new ArrayList(), tcProperties);
        linkedProperties.addAll(newLinkedProperties);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Property " + internalProperty + " need calculation of these (" + newLinkedProperties.size() + ") property(ies) " + newLinkedProperties);
        }
    }
    /**
     * For all linked properties, calculate it if needed.
     */
    for (TestCaseCountryProperties eachTccp : linkedProperties) {
        TestCaseExecutionData tcExeData;
        /**
         * First create testCaseExecutionData object
         */
        now = new Date().getTime();
        tcExeData = factoryTestCaseExecutionData.create(tCExecution.getId(), eachTccp.getProperty(), 1, eachTccp.getDescription(), null, eachTccp.getType(), eachTccp.getValue1(), eachTccp.getValue2(), null, null, now, now, now, now, new MessageEvent(MessageEventEnum.PROPERTY_PENDING), eachTccp.getRetryNb(), eachTccp.getRetryPeriod(), eachTccp.getDatabase(), eachTccp.getValue1(), eachTccp.getValue2(), eachTccp.getLength(), eachTccp.getLength(), eachTccp.getRowLimit(), eachTccp.getNature(), tCExecution.getApplicationObj().getSystem(), tCExecution.getEnvironment(), tCExecution.getCountry(), "", null, "N");
        tcExeData.setTestCaseCountryProperties(eachTccp);
        tcExeData.settCExecution(tCExecution);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Trying to calculate Property : '" + tcExeData.getProperty() + "' " + tcExeData);
        }
        /*  First check if property has already been calculated 
             *  if action is calculateProperty, then set isKnownData to false. 
             */
        tcExeData = getExecutionDataFromList(tCExecution.getTestCaseExecutionDataMap(), eachTccp, forceCalculation, tcExeData);
        /**
         * If testcasecountryproperty not defined, set ExecutionData with
         * the same resultMessage
         */
        if (eachTccp.getResult() != null) {
            tcExeData.setPropertyResultMessage(eachTccp.getResult());
        }
        /*
             * If not already calculated, or calculateProperty, then calculate it and insert or update it.
             */
        if (MessageEventEnum.PROPERTY_PENDING.equals(tcExeData.getPropertyResultMessage().getSource())) {
            calculateProperty(tcExeData, tCExecution, testCaseStepActionExecution, eachTccp, forceCalculation);
            msg = tcExeData.getPropertyResultMessage();
            // saves the result
            try {
                testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcExeData));
                /**
                 * Add TestCaseExecutionData in TestCaseExecutionData List
                 * of the TestCaseExecution
                 */
                LOG.debug("Adding into Execution data list. Property : '" + tcExeData.getProperty() + "' Index : '" + String.valueOf(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, "", tcExeData.getSystem(), tcExeData.getEnvironment(), tcExeData.getCountry(), tcExeData.getDataLib(), null, "N");
                        testCaseExecutionDataService.convert(testCaseExecutionDataService.save(tcedS));
                    }
                }
            } catch (CerberusException cex) {
                LOG.error(cex.getMessage(), cex);
            }
        }
        /**
         * After calculation, replace properties by value calculated
         */
        stringToDecode = decodeStringWithAlreadyCalculatedProperties(stringToDecode, tCExecution);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Property " + eachTccp.getProperty() + " calculated with Value = " + tcExeData.getValue() + ", Value1 = " + tcExeData.getValue1() + ", Value2 = " + tcExeData.getValue2());
        }
        /**
         * Log TestCaseExecutionData
         */
        if (tCExecution.getVerbose() > 0) {
            LOG.info(tcExeData.toJson(false, true));
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Finished to decode String (property) : '" + stringToDecodeInit + "' to :'" + stringToDecode + "'");
    }
    answer.setResultMessage(msg);
    answer.setItem(stringToDecode);
    return answer;
}
Also used : 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) ArrayList(java.util.ArrayList) AnswerItem(org.cerberus.util.answer.AnswerItem) Date(java.util.Date)

Example 98 with CerberusException

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

the class PropertyService method property_executeSqlFromLib.

private TestCaseExecutionData property_executeSqlFromLib(TestCaseExecutionData testCaseExecutionData, TestCaseCountryProperties testCaseCountryProperty, TestCaseExecution tCExecution, boolean forceCalculation) {
    try {
        String script = this.sqlLibraryService.findSqlLibraryByKey(testCaseExecutionData.getValue1()).getScript();
        // TODO use the new library
        testCaseExecutionData.setValue1(script);
    } catch (CerberusException ex) {
        LOG.warn(ex);
        MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL_SQLLIB_NOTEXIT);
        res.setDescription(res.getDescription().replace("%SQLLIB%", testCaseExecutionData.getValue1()));
        testCaseExecutionData.setPropertyResultMessage(res);
        testCaseExecutionData.setEnd(new Date().getTime());
        return testCaseExecutionData;
    }
    testCaseExecutionData = this.property_getFromSql(testCaseExecutionData, tCExecution, testCaseCountryProperty, forceCalculation);
    return testCaseExecutionData;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Date(java.util.Date)

Example 99 with CerberusException

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

the class PropertyService method property_executeSoapFromLib.

private TestCaseExecutionData property_executeSoapFromLib(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceCalculation) {
    String result = null;
    AnswerItem<String> answerDecode = new AnswerItem();
    try {
        AppService appService = this.appServiceService.findAppServiceByKey(testCaseExecutionData.getValue1());
        if (appService != null) {
            String decodedEnveloppe = appService.getServiceRequest();
            String decodedServicePath = appService.getServicePath();
            String decodedMethod = appService.getOperation();
            String decodedAttachement = appService.getAttachementURL();
            if (appService.getServiceRequest().contains("%")) {
                answerDecode = variableService.decodeStringCompletly(appService.getServiceRequest(), tCExecution, testCaseStepActionExecution, false);
                decodedEnveloppe = (String) answerDecode.getItem();
                if (!(answerDecode.isCodeStringEquals("OK"))) {
                    // If anything wrong with the decode --> we stop here with decode message in the action result.
                    testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Service Request"));
                    testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());
                    LOG.debug("Property interupted due to decode 'SOAP Service Request' Error.");
                    return testCaseExecutionData;
                }
            }
            if (appService.getServicePath().contains("%")) {
                answerDecode = variableService.decodeStringCompletly(appService.getServicePath(), tCExecution, testCaseStepActionExecution, false);
                decodedServicePath = (String) answerDecode.getItem();
                if (!(answerDecode.isCodeStringEquals("OK"))) {
                    // If anything wrong with the decode --> we stop here with decode message in the action result.
                    testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Service Path"));
                    testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());
                    LOG.debug("Property interupted due to decode 'SOAP Service Path.");
                    return testCaseExecutionData;
                }
            }
            if (appService.getOperation().contains("%")) {
                answerDecode = variableService.decodeStringCompletly(appService.getOperation(), tCExecution, testCaseStepActionExecution, false);
                decodedMethod = (String) answerDecode.getItem();
                if (!(answerDecode.isCodeStringEquals("OK"))) {
                    // If anything wrong with the decode --> we stop here with decode message in the action result.
                    testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Operation"));
                    testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());
                    LOG.debug("Property interupted due to decode 'SOAP Operation.");
                    return testCaseExecutionData;
                }
            }
            if (appService.getAttachementURL().contains("%")) {
                answerDecode = variableService.decodeStringCompletly(appService.getAttachementURL(), tCExecution, testCaseStepActionExecution, false);
                decodedAttachement = (String) answerDecode.getItem();
                if (!(answerDecode.isCodeStringEquals("OK"))) {
                    // If anything wrong with the decode --> we stop here with decode message in the action result.
                    testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "SOAP Attachement URL"));
                    testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());
                    LOG.debug("Property interupted due to decode 'SOAP Attachement URL.");
                    return testCaseExecutionData;
                }
            }
            // Call Soap and set LastSoapCall of the testCaseExecution.
            AnswerItem soapCall = soapService.callSOAP(decodedEnveloppe, decodedServicePath, decodedMethod, decodedAttachement, null, null, 60000, tCExecution.getApplicationObj().getSystem());
            AppService se1 = (AppService) soapCall.getItem();
            if (soapCall.isCodeEquals(200)) {
                // SOAPExecution lastSoapCalled = (SOAPExecution) tCExecution.getLastSOAPCalled().getItem();
                String xmlResponse = se1.getResponseHTTPBody();
                result = xmlUnitService.getFromXml(xmlResponse, appService.getAttachementURL());
            }
            if (result != null) {
                testCaseExecutionData.setValue(result);
                MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_SOAP);
                testCaseExecutionData.setPropertyResultMessage(res);
            } else {
                MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SOAPFROMLIB_NODATA);
                testCaseExecutionData.setPropertyResultMessage(res);
            }
        }
    } catch (CerberusException exception) {
        LOG.error(exception.toString());
        MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_TESTDATA_PROPERTYDONOTEXIST);
        res.setDescription(res.getDescription().replace("%PROPERTY%", testCaseExecutionData.getValue1()));
        testCaseExecutionData.setPropertyResultMessage(res);
    } catch (CerberusEventException ex) {
        LOG.error(ex.toString());
        MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP);
        message.setDescription(message.getDescription().replace("%SOAPNAME%", testCaseExecutionData.getValue1()));
        message.setDescription(message.getDescription().replace("%DESCRIPTION%", ex.getMessageError().getDescription()));
        testCaseExecutionData.setPropertyResultMessage(message);
    }
    return testCaseExecutionData;
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) AppService(org.cerberus.crud.entity.AppService) CerberusException(org.cerberus.exception.CerberusException) MessageEvent(org.cerberus.engine.entity.MessageEvent) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 100 with CerberusException

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

the class ExecutionCheckService method compareBuild.

private int compareBuild(String build1, String build2, String system) throws CerberusException {
    BuildRevisionInvariant b1;
    BuildRevisionInvariant b2;
    try {
        b1 = buildRevisionInvariantService.convert(buildRevisionInvariantService.readByKey(system, 1, build1));
        b2 = buildRevisionInvariantService.convert(buildRevisionInvariantService.readByKey(system, 1, build2));
    } catch (CerberusException e) {
        throw new NumberFormatException();
    }
    if (null == b1 || null == b2) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_RANGE_ENVIRONMENT_BUILDREVISION_BADLYDEFINED));
    }
    return b1.getSeq().compareTo(b2.getSeq());
}
Also used : CerberusException(org.cerberus.exception.CerberusException) BuildRevisionInvariant(org.cerberus.crud.entity.BuildRevisionInvariant) MessageGeneral(org.cerberus.engine.entity.MessageGeneral)

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