Search in sources :

Example 6 with AppService

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

the class ActionService method doActionCallService.

private MessageEvent doActionCallService(TestCaseStepActionExecution testCaseStepActionExecution, String value1) {
    MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);
    TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();
    AnswerItem lastServiceCalledAnswer;
    lastServiceCalledAnswer = serviceService.callService(value1, null, null, null, null, tCExecution);
    message = lastServiceCalledAnswer.getResultMessage();
    if (lastServiceCalledAnswer.getItem() != null) {
        AppService lastServiceCalled = (AppService) lastServiceCalledAnswer.getItem();
        tCExecution.setLastServiceCalled(lastServiceCalled);
        /**
         * Record the Request and Response in filesystem.
         */
        testCaseStepActionExecution.addFileList(recorderService.recordServiceCall(tCExecution, testCaseStepActionExecution, 0, null, lastServiceCalled));
    }
    return message;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) AppService(org.cerberus.crud.entity.AppService) MessageEvent(org.cerberus.engine.entity.MessageEvent) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 7 with AppService

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

the class CalculatePropertyForTestCase method doGet.

@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.BLOCKS);
    String type = policy.sanitize(httpServletRequest.getParameter("type"));
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    String result = null;
    String description = null;
    String system = "";
    String property = httpServletRequest.getParameter("property");
    String testName = policy.sanitize(httpServletRequest.getParameter("test"));
    String testCaseName = policy.sanitize(httpServletRequest.getParameter("testCase"));
    String country = policy.sanitize(httpServletRequest.getParameter("country"));
    String environment = policy.sanitize(httpServletRequest.getParameter("environment"));
    try {
        if (type.equals("executeSoapFromLib")) {
            IAppServiceService appServiceService = appContext.getBean(AppServiceService.class);
            ISoapService soapService = appContext.getBean(ISoapService.class);
            IXmlUnitService xmlUnitService = appContext.getBean(IXmlUnitService.class);
            AppService appService = appServiceService.findAppServiceByKey(property);
            if (appService != null) {
                ExecutionUUID executionUUIDObject = appContext.getBean(ExecutionUUID.class);
                UUID executionUUID = UUID.randomUUID();
                executionUUIDObject.setExecutionUUID(executionUUID.toString(), null);
                soapService.callSOAP(appService.getServiceRequest(), appService.getServicePath(), appService.getOperation(), appService.getAttachementURL(), null, null, 60000, system);
                result = xmlUnitService.getFromXml(executionUUID.toString(), appService.getAttachementURL());
                description = appService.getDescription();
                executionUUIDObject.removeExecutionUUID(executionUUID.toString());
                LOG.debug("Clean ExecutionUUID");
            }
        } else {
            try {
                ITestCaseService testCaseService = appContext.getBean(TestCaseService.class);
                IApplicationService applicationService = appContext.getBean(ApplicationService.class);
                TestCase testCase = testCaseService.findTestCaseByKey(testName, testCaseName);
                if (testCase != null) {
                    system = applicationService.convert(applicationService.readByKey(testCase.getApplication())).getSystem();
                } else {
                    throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));
                }
            } catch (CerberusException ex) {
                LOG.warn(ex);
            }
            if (system != null) {
                String database = policy.sanitize(httpServletRequest.getParameter("database"));
                ICountryEnvironmentDatabaseService countryEnvironmentDatabaseService = appContext.getBean(CountryEnvironmentDatabaseService.class);
                CountryEnvironmentDatabase countryEnvironmentDatabase;
                countryEnvironmentDatabase = countryEnvironmentDatabaseService.convert(countryEnvironmentDatabaseService.readByKey(system, country, environment, database));
                String connectionName = countryEnvironmentDatabase.getConnectionPoolName();
                if (type.equals("executeSqlFromLib")) {
                    ISqlLibraryService sqlLibraryService = appContext.getBean(SqlLibraryService.class);
                    SqlLibrary sl = sqlLibraryService.findSqlLibraryByKey(policy.sanitize(property));
                    property = sl.getScript();
                    if (!(StringUtil.isNullOrEmpty(connectionName)) && !(StringUtil.isNullOrEmpty(policy.sanitize(property)))) {
                        ISQLService sqlService = appContext.getBean(ISQLService.class);
                        IParameterService parameterService = appContext.getBean(IParameterService.class);
                        Integer sqlTimeout = parameterService.getParameterIntegerByKey("cerberus_propertyexternalsql_timeout", system, 60);
                        result = sqlService.queryDatabase(connectionName, policy.sanitize(property), 1, sqlTimeout).get(0);
                        description = sl.getDescription();
                    }
                }
            }
        }
    } catch (CerberusException ex) {
        LOG.warn(ex);
        result = ex.getMessageError().getDescription();
        description = ex.getMessageError().getDescription();
    } catch (CerberusEventException ex) {
        LOG.warn(ex);
        result = ex.getMessageError().getDescription();
        description = ex.getMessageError().getDescription();
    }
    if (result != null) {
        try {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("resultList", result);
            jsonObject.put("description", description);
            httpServletResponse.setContentType("application/json");
            httpServletResponse.getWriter().print(jsonObject.toString());
        } catch (JSONException exception) {
            LOG.warn(exception.toString());
        }
    }
}
Also used : AppService(org.cerberus.crud.entity.AppService) CerberusException(org.cerberus.exception.CerberusException) PolicyFactory(org.owasp.html.PolicyFactory) ExecutionUUID(org.cerberus.engine.entity.ExecutionUUID) SqlLibrary(org.cerberus.crud.entity.SqlLibrary) JSONException(org.json.JSONException) IAppServiceService(org.cerberus.crud.service.IAppServiceService) IParameterService(org.cerberus.crud.service.IParameterService) CerberusEventException(org.cerberus.exception.CerberusEventException) ApplicationContext(org.springframework.context.ApplicationContext) ISQLService(org.cerberus.service.sql.ISQLService) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) JSONObject(org.json.JSONObject) ISoapService(org.cerberus.service.soap.ISoapService) TestCase(org.cerberus.crud.entity.TestCase) ITestCaseService(org.cerberus.crud.service.ITestCaseService) ISqlLibraryService(org.cerberus.crud.service.ISqlLibraryService) ICountryEnvironmentDatabaseService(org.cerberus.crud.service.ICountryEnvironmentDatabaseService) UUID(java.util.UUID) ExecutionUUID(org.cerberus.engine.entity.ExecutionUUID) IXmlUnitService(org.cerberus.service.xmlunit.IXmlUnitService) IApplicationService(org.cerberus.crud.service.IApplicationService) CountryEnvironmentDatabase(org.cerberus.crud.entity.CountryEnvironmentDatabase)

Example 8 with AppService

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

the class ReadAppService method findAppServiceByLikeName.

private AnswerItem findAppServiceByLikeName(String key, ApplicationContext appContext, int limit) throws JSONException {
    AnswerItem answerItem = new AnswerItem();
    JSONObject response = new JSONObject();
    appServiceService = appContext.getBean(AppServiceService.class);
    AnswerList resp = appServiceService.readByLikeName(key, limit);
    AppService p = null;
    JSONArray jsonArray = new JSONArray();
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (AppService appService : (List<AppService>) resp.getDataList()) {
            jsonArray.put(convertSoapLibraryToJSONObject(appService));
        }
    }
    response.put("contentTable", jsonArray);
    response.put("iTotalRecords", resp.getTotalRows());
    response.put("iTotalDisplayRecords", resp.getTotalRows());
    answerItem.setItem(response);
    answerItem.setResultMessage(resp.getResultMessage());
    return answerItem;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) AppService(org.cerberus.crud.entity.AppService) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) AnswerList(org.cerberus.util.answer.AnswerList) AppServiceService(org.cerberus.crud.service.impl.AppServiceService) IAppServiceService(org.cerberus.crud.service.IAppServiceService) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 9 with AppService

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

the class ReadAppService method findAppServiceList.

private AnswerItem findAppServiceList(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject object = new JSONObject();
    appServiceService = appContext.getBean(AppServiceService.class);
    int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
    int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
    /*int sEcho  = Integer.valueOf(request.getParameter("sEcho"));*/
    String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
    int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "0"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "service,type,method,description");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));
    Map<String, List<String>> individualSearch = new HashMap<>();
    for (int a = 0; a < columnToSort.length; a++) {
        if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {
            List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));
            if (individualLike.contains(columnToSort[a])) {
                individualSearch.put(columnToSort[a] + ":like", search);
            } else {
                individualSearch.put(columnToSort[a], search);
            }
        }
    }
    AnswerList resp = appServiceService.readByCriteria(startPosition, length, columnName, sort, searchParameter, individualSearch);
    JSONArray jsonArray = new JSONArray();
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (AppService param : (List<AppService>) resp.getDataList()) {
            jsonArray.put(convertSoapLibraryToJSONObject(param));
        }
    }
    object.put("hasPermissions", userHasPermissions);
    object.put("contentTable", jsonArray);
    object.put("iTotalRecords", resp.getTotalRows());
    object.put("iTotalDisplayRecords", resp.getTotalRows());
    item.setItem(object);
    item.setResultMessage(resp.getResultMessage());
    return item;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) AppService(org.cerberus.crud.entity.AppService) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) JSONObject(org.json.JSONObject) AnswerList(org.cerberus.util.answer.AnswerList) AppServiceService(org.cerberus.crud.service.impl.AppServiceService) IAppServiceService(org.cerberus.crud.service.IAppServiceService)

Example 10 with AppService

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

the class ReadAppService method findAppServiceBySystemByKey.

private AnswerItem findAppServiceBySystemByKey(String key, ApplicationContext appContext, boolean userHasPermissions) throws JSONException {
    JSONObject response = new JSONObject();
    appServiceService = appContext.getBean(AppServiceService.class);
    AnswerItem resp = appServiceService.readByKeyWithDependency(key, null);
    AppService p = null;
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        p = (AppService) resp.getItem();
    }
    JSONObject item = convertSoapLibraryToJSONObject(p);
    response.put("contentTable", item);
    item.put("hasPermissions", userHasPermissions);
    resp.setItem(response);
    return resp;
}
Also used : AppService(org.cerberus.crud.entity.AppService) JSONObject(org.json.JSONObject) AppServiceService(org.cerberus.crud.service.impl.AppServiceService) IAppServiceService(org.cerberus.crud.service.IAppServiceService) AnswerItem(org.cerberus.util.answer.AnswerItem)

Aggregations

AppService (org.cerberus.crud.entity.AppService)21 AnswerItem (org.cerberus.util.answer.AnswerItem)13 MessageEvent (org.cerberus.engine.entity.MessageEvent)12 IFactoryAppService (org.cerberus.crud.factory.IFactoryAppService)11 ArrayList (java.util.ArrayList)9 AppServiceHeader (org.cerberus.crud.entity.AppServiceHeader)7 IAppServiceService (org.cerberus.crud.service.IAppServiceService)7 CerberusException (org.cerberus.exception.CerberusException)7 JSONObject (org.json.JSONObject)7 AppServiceContent (org.cerberus.crud.entity.AppServiceContent)6 AnswerList (org.cerberus.util.answer.AnswerList)6 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 IFactoryAppServiceHeader (org.cerberus.crud.factory.IFactoryAppServiceHeader)4 JSONArray (org.json.JSONArray)4 ApplicationContext (org.springframework.context.ApplicationContext)4 IOException (java.io.IOException)3 List (java.util.List)3