Search in sources :

Example 6 with TestDataLib

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

the class FactoryTestDataLib method create.

@Override
public TestDataLib create(Integer testDataLibID, String name, String system, String environment, String country, String group, String type, String database, String script, String databaseUrl, String service, String servicePath, String method, String envelope, String databaseCsv, String csvUrl, String separator, String description, String creator, Timestamp created, String LastModifier, Timestamp lastModified, String subDataValue, String subDataColumn, String subDataParsingAnswer, String subDataColumnPosition) {
    TestDataLib newData = new TestDataLib();
    newData.setTestDataLibID(testDataLibID);
    newData.setType(type);
    newData.setName(name);
    newData.setSystem(system);
    newData.setCountry(country);
    newData.setEnvironment(environment);
    newData.setGroup(group);
    newData.setDescription(description);
    newData.setDatabase(database);
    newData.setScript(script);
    newData.setDatabaseUrl(databaseUrl);
    newData.setServicePath(servicePath);
    newData.setService(service);
    newData.setMethod(method);
    newData.setEnvelope(envelope);
    newData.setDatabaseCsv(databaseCsv);
    newData.setCsvUrl(csvUrl);
    newData.setSeparator(separator);
    newData.setDescription(description);
    newData.setCreator(creator);
    newData.setCreated(created);
    newData.setLastModifier(LastModifier);
    newData.setLastModified(lastModified);
    newData.setSubDataValue(subDataValue);
    newData.setSubDataColumn(subDataColumn);
    newData.setSubDataParsingAnswer(subDataParsingAnswer);
    newData.setSubDataColumnPosition(subDataColumnPosition);
    return newData;
}
Also used : IFactoryTestDataLib(org.cerberus.crud.factory.IFactoryTestDataLib) TestDataLib(org.cerberus.crud.entity.TestDataLib)

Example 7 with TestDataLib

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

the class DeleteTestDataLib method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    JSONObject jsonResponse = new JSONObject();
    Answer ans = new Answer();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    ans.setResultMessage(msg);
    response.setContentType("application/json");
    /**
     * Parsing and securing all required parameters.
     */
    Integer key = 0;
    boolean testdatalibid_error = true;
    try {
        if (request.getParameter("testdatalibid") != null && !request.getParameter("testdatalibid").isEmpty()) {
            key = Integer.valueOf(request.getParameter("testdatalibid"));
            testdatalibid_error = false;
        }
    } catch (NumberFormatException ex) {
        testdatalibid_error = true;
        LOG.warn(ex);
    }
    /**
     * Checking all constrains before calling the services.
     */
    if (testdatalibid_error) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Data Library").replace("%OPERATION%", "Delete").replace("%REASON%", "Test data library (testdatalibid) is missing."));
        ans.setResultMessage(msg);
    } else {
        /**
         * All data seems cleans so we can call the services.
         */
        ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        ITestDataLibService libService = appContext.getBean(ITestDataLibService.class);
        AnswerItem resp = libService.readByKey(key);
        if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
            /**
             * Object could not be found. We stop here and report the error.
             */
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
            msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Data Library").replace("%OPERATION%", "Delete").replace("%REASON%", "Test Data Library does not exist."));
            ans.setResultMessage(msg);
        } else {
            /**
             * The service was able to perform the query and confirm the
             * object exist, then we can delete it.
             */
            TestDataLib lib = (TestDataLib) resp.getItem();
            ans = libService.delete(lib);
            /**
             * Delete was perform with success. Adding Log entry.
             */
            if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                ILogEventService logEventService = appContext.getBean(LogEventService.class);
                logEventService.createForPrivateCalls("/DeleteTestDataLib", "DELETE", "Delete TestDataLib : " + key, request);
            }
        }
    }
    try {
        /**
         * Formating and returning the json result.
         */
        jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
        jsonResponse.put("message", ans.getResultMessage().getDescription());
        response.getWriter().print(jsonResponse.toString());
        response.getWriter().flush();
    } catch (JSONException ex) {
        LOG.warn(ex);
        response.setContentType("application/json");
        response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
        response.getWriter().flush();
    }
}
Also used : Answer(org.cerberus.util.answer.Answer) TestDataLib(org.cerberus.crud.entity.TestDataLib) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) MessageEvent(org.cerberus.engine.entity.MessageEvent) ILogEventService(org.cerberus.crud.service.ILogEventService) JSONException(org.json.JSONException) ITestDataLibService(org.cerberus.crud.service.ITestDataLibService) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 8 with TestDataLib

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

the class CreateTestDataLib method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IFactoryTestDataLibData tdldFactory = appContext.getBean(IFactoryTestDataLibData.class);
    ITestDataLibDataService tdldService = appContext.getBean(ITestDataLibDataService.class);
    IParameterService parameterService = appContext.getBean(IParameterService.class);
    JSONObject jsonResponse = new JSONObject();
    Answer ans = new Answer();
    AnswerItem ansItem = new AnswerItem();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    ans.setResultMessage(msg);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    String charset = request.getCharacterEncoding();
    response.setContentType("application/json");
    Map<String, String> fileData = new HashMap<String, String>();
    FileItem file = null;
    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    try {
        List<FileItem> fields = upload.parseRequest(request);
        Iterator<FileItem> it = fields.iterator();
        if (!it.hasNext()) {
            return;
        }
        while (it.hasNext()) {
            FileItem fileItem = it.next();
            boolean isFormField = fileItem.isFormField();
            if (isFormField) {
                fileData.put(fileItem.getFieldName(), ParameterParserUtil.parseStringParamAndDecode(fileItem.getString("UTF-8"), "", charset));
            } else {
                file = fileItem;
            }
        }
    } catch (FileUploadException e) {
        e.printStackTrace();
    }
    try {
        /**
         * Parsing and securing all required parameters.
         */
        // Parameter that are already controled by GUI (no need to decode) --> We SECURE them
        String type = policy.sanitize(fileData.get("type"));
        String system = policy.sanitize(fileData.get("system"));
        String environment = policy.sanitize(fileData.get("environment"));
        String country = policy.sanitize(fileData.get("country"));
        String database = policy.sanitize(fileData.get("database"));
        String databaseUrl = policy.sanitize(fileData.get("databaseUrl"));
        String databaseCsv = policy.sanitize(fileData.get("databaseCsv"));
        // Parameter that needs to be secured --> We SECURE+DECODE them
        // this is mandatory
        String name = fileData.get("name");
        String group = fileData.get("group");
        String description = fileData.get("libdescription");
        String service = fileData.get("service");
        // Parameter that we cannot secure as we need the html --> We DECODE them
        String script = fileData.get("script");
        String servicePath = fileData.get("servicepath");
        String method = fileData.get("method");
        String envelope = fileData.get("envelope");
        String csvUrl = fileData.get("csvUrl");
        String separator = fileData.get("separator");
        String test = fileData.get("subdataCheck");
        /**
         * Checking all constrains before calling the services.
         */
        // Prepare the final answer.
        MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
        Answer finalAnswer = new Answer(msg1);
        if (StringUtil.isNullOrEmpty(name)) {
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
            msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Data Library").replace("%OPERATION%", "Create").replace("%REASON%", "Test data library name is missing! "));
            finalAnswer.setResultMessage(msg);
        } else {
            /**
             * All data seems cleans so we can call the services.
             */
            ITestDataLibService libService = appContext.getBean(ITestDataLibService.class);
            IFactoryTestDataLib factoryLibService = appContext.getBean(IFactoryTestDataLib.class);
            TestDataLib lib = factoryLibService.create(0, name, system, environment, country, group, type, database, script, databaseUrl, service, servicePath, method, envelope, databaseCsv, csvUrl, separator, description, request.getRemoteUser(), null, "", null, null, null, null, null);
            // Creates the entries and the subdata list
            ansItem = libService.create(lib);
            finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ansItem);
            /**
             * Object created. Adding Log entry.
             */
            if (ansItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                ILogEventService logEventService = appContext.getBean(LogEventService.class);
                logEventService.createForPrivateCalls("/CreateTestDataLib", "CREATE", "Create TestDataLib  : " + request.getParameter("name"), request);
            }
            List<TestDataLibData> tdldList = new ArrayList();
            TestDataLib dataLibWithUploadedFile = (TestDataLib) ansItem.getItem();
            if (file != null) {
                ans = libService.uploadFile(dataLibWithUploadedFile.getTestDataLibID(), file);
                if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                    dataLibWithUploadedFile.setCsvUrl(File.separator + dataLibWithUploadedFile.getTestDataLibID() + File.separator + file.getName());
                    libService.update(dataLibWithUploadedFile);
                }
            }
            // Getting list of SubData from JSON Call
            if (fileData.get("subDataList") != null) {
                JSONArray objSubDataArray = new JSONArray(fileData.get("subDataList"));
                tdldList = getSubDataFromParameter(request, appContext, dataLibWithUploadedFile.getTestDataLibID(), objSubDataArray);
            }
            if (file != null && test.equals("1")) {
                String firstLine = "";
                String secondLine = "";
                try (BufferedReader reader = new BufferedReader(new FileReader(parameterService.getParameterStringByKey("cerberus_testdatalibCSV_path", "", null) + lib.getCsvUrl()))) {
                    firstLine = reader.readLine();
                    secondLine = reader.readLine();
                    String[] firstLineSubData = (!dataLibWithUploadedFile.getSeparator().isEmpty()) ? firstLine.split(dataLibWithUploadedFile.getSeparator()) : firstLine.split(",");
                    String[] secondLineSubData = (!dataLibWithUploadedFile.getSeparator().isEmpty()) ? secondLine.split(dataLibWithUploadedFile.getSeparator()) : secondLine.split(",");
                    int i = 0;
                    int y = 1;
                    TestDataLibData firstLineLibData = tdldList.get(0);
                    tdldList = new ArrayList();
                    if (StringUtil.isNullOrEmpty(firstLineLibData.getColumnPosition())) {
                        firstLineLibData.setColumnPosition("1");
                    }
                    if (StringUtil.isNullOrEmpty(firstLineLibData.getValue())) {
                        firstLineLibData.setValue(secondLineSubData[0]);
                    }
                    if (StringUtil.isNullOrEmpty(firstLineLibData.getColumn())) {
                        firstLineLibData.setColumn(firstLineSubData[0]);
                    }
                    tdldList.add(firstLineLibData);
                    for (String item : firstLineSubData) {
                        TestDataLibData tdld = tdldFactory.create(null, dataLibWithUploadedFile.getTestDataLibID(), item + "_" + y, secondLineSubData[i], item, null, Integer.toString(y), null);
                        tdldList.add(tdld);
                        i++;
                        y++;
                    }
                // Update the Database with the new list.
                } finally {
                    try {
                        file.getInputStream().close();
                    } catch (Throwable ignore) {
                    }
                }
            }
            ans = tdldService.compareListAndUpdateInsertDeleteElements(dataLibWithUploadedFile.getTestDataLibID(), tdldList);
            finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
        }
        /**
         * Formating and returning the json result.
         */
        // sets the message returned by the operations
        jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());
        jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());
        response.getWriter().print(jsonResponse);
        response.getWriter().flush();
    } catch (JSONException ex) {
        LOG.warn(ex);
        response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
        response.getWriter().flush();
    }
}
Also used : PolicyFactory(org.owasp.html.PolicyFactory) HashMap(java.util.HashMap) MessageEvent(org.cerberus.engine.entity.MessageEvent) IFactoryTestDataLibData(org.cerberus.crud.factory.IFactoryTestDataLibData) ArrayList(java.util.ArrayList) IParameterService(org.cerberus.crud.service.IParameterService) ITestDataLibDataService(org.cerberus.crud.service.ITestDataLibDataService) ApplicationContext(org.springframework.context.ApplicationContext) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) ILogEventService(org.cerberus.crud.service.ILogEventService) FileReader(java.io.FileReader) TestDataLib(org.cerberus.crud.entity.TestDataLib) IFactoryTestDataLib(org.cerberus.crud.factory.IFactoryTestDataLib) IFactoryTestDataLib(org.cerberus.crud.factory.IFactoryTestDataLib) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) AnswerItem(org.cerberus.util.answer.AnswerItem) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) FileItemFactory(org.apache.commons.fileupload.FileItemFactory) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) Answer(org.cerberus.util.answer.Answer) FileItem(org.apache.commons.fileupload.FileItem) JSONObject(org.json.JSONObject) BufferedReader(java.io.BufferedReader) ITestDataLibService(org.cerberus.crud.service.ITestDataLibService) FileUploadException(org.apache.commons.fileupload.FileUploadException) IFactoryTestDataLibData(org.cerberus.crud.factory.IFactoryTestDataLibData) TestDataLibData(org.cerberus.crud.entity.TestDataLibData)

Example 9 with TestDataLib

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

the class ReadTestDataLib method findTestDataLibList.

/**
 * Auxiliary method that retrieves a list of test data library entries with
 * basis on the GUI information (datatable)
 *
 * @param appContext - context object used to get the required beans
 * @param request - object that contains the search and sort filters used to
 * retrieve the information to be displayed in the GUI.
 * @return object containing the info to be displayed in the GUI
 * @throws IOException
 * @throws BeansException
 * @throws NumberFormatException
 * @throws JSONException
 */
private AnswerItem findTestDataLibList(ApplicationContext appContext, HttpServletRequest request) throws IOException, BeansException, NumberFormatException, JSONException {
    AnswerItem item = new AnswerItem();
    JSONObject jsonResponse = new JSONObject();
    testDataLibService = appContext.getBean(ITestDataLibService.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"), "tdl.TestDataLibID,tdl.Name,tdl.System,tdl.Environment,tdl.Country,tdl.Group,tdl.Type,tdl.Database,tdl.Script,tdl.ServicePath,tdl.Method,tdl.Envelope,tdl.databaseCsv,tdl.Description");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    Map<String, List<String>> individualSearch = new HashMap<String, List<String>>();
    List<String> individualLike = new ArrayList(Arrays.asList(request.getParameter("sLike").split(",")));
    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 = testDataLibService.readByVariousByCriteria(null, null, null, null, null, startPosition, length, columnName, sort, searchParameter, individualSearch);
    JSONArray jsonArray = new JSONArray();
    boolean userHasPermissions = request.isUserInRole("TestDataManager");
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (TestDataLib testDataLib : (List<TestDataLib>) resp.getDataList()) {
            jsonArray.put(convertTestDataLibToJSONObject(testDataLib, false));
        }
    }
    // recordsFiltered do lado do servidor
    jsonResponse.put("hasPermissions", userHasPermissions);
    jsonResponse.put("contentTable", jsonArray);
    jsonResponse.put("iTotalRecords", resp.getTotalRows());
    jsonResponse.put("iTotalDisplayRecords", resp.getTotalRows());
    // recordsFiltered
    item.setItem(jsonResponse);
    item.setResultMessage(resp.getResultMessage());
    return item;
}
Also used : TestDataLib(org.cerberus.crud.entity.TestDataLib) AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) JSONObject(org.json.JSONObject) ITestDataLibService(org.cerberus.crud.service.ITestDataLibService) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with TestDataLib

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

the class PropertyService method property_getFromDataLib.

private TestCaseExecutionData property_getFromDataLib(TestCaseExecutionData testCaseExecutionData, TestCaseExecution tCExecution, TestCaseStepActionExecution testCaseStepActionExecution, TestCaseCountryProperties testCaseCountryProperty, boolean forceRecalculation) {
    MessageEvent res = new MessageEvent(MessageEventEnum.PROPERTY_SUCCESS_GETFROMDATALIB);
    TestDataLib testDataLib;
    List<HashMap<String, String>> result = null;
    AnswerItem<String> answerDecode = new AnswerItem();
    // We get here the correct TestDataLib entry from the Value1 (name) that better match the context on system, environment and country.
    AnswerItem<TestDataLib> answer = testDataLibService.readByNameBySystemByEnvironmentByCountry(testCaseExecutionData.getValue1(), tCExecution.getApplicationObj().getSystem(), tCExecution.getEnvironmentData(), tCExecution.getCountry());
    if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answer.getItem() != null) {
        testDataLib = (TestDataLib) answer.getItem();
        AnswerList serviceAnswer;
        // check if there are properties defined in the data specification
        try {
            if (testDataLib.getType().equals(TestDataLib.TYPE_SQL)) {
                // check if the script contains properties that neeed to be calculated
                answerDecode = variableService.decodeStringCompletly(testDataLib.getScript(), tCExecution, testCaseStepActionExecution, false);
                String decodedScript = (String) answerDecode.getItem();
                testDataLib.setScript(decodedScript);
                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", "SQL Script"));
                    testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());
                    LOG.debug("Property interupted due to decode 'SQL Script'.");
                    return testCaseExecutionData;
                }
            }
        } catch (CerberusEventException cex) {
            LOG.error(cex.toString());
        }
        String decodedLength = null;
        // Here, we try to decode testCaseCountryProperty field `length` to get the value of property if needed
        try {
            answerDecode = variableService.decodeStringCompletly(testCaseCountryProperty.getLength(), tCExecution, testCaseStepActionExecution, false);
            decodedLength = (String) answerDecode.getItem();
            if (!(answerDecode.isCodeStringEquals("OK"))) {
                testCaseExecutionData.setPropertyResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "length"));
                testCaseExecutionData.setStopExecution(answerDecode.getResultMessage().isStopTest());
                LOG.debug("Property interupted due to decode 'Length field'.");
                return testCaseExecutionData;
            }
        } catch (CerberusEventException cex) {
            LOG.error(cex.toString());
        }
        // if we can, we set the value of testCaseExecutionData field `length` to the casted value
        if (decodedLength != null) {
            try {
                Integer.parseInt(decodedLength);
                testCaseExecutionData.setLength(decodedLength);
            } catch (NumberFormatException e) {
                LOG.error(e.toString());
                MessageEvent msg = new MessageEvent(MessageEventEnum.CASTING_OPERATION_FAILED);
                msg.setDescription(msg.getDescription().replace("%ERROR%", e.toString()));
                msg.setDescription(msg.getDescription().replace("%FIELD%", "field length"));
                testCaseExecutionData.setPropertyResultMessage(msg);
                testCaseExecutionData.setStopExecution(msg.isStopTest());
                return testCaseExecutionData;
            }
        }
        // we need to recalculate the result for the lib
        serviceAnswer = dataLibService.getFromDataLib(testDataLib, testCaseCountryProperty, tCExecution, testCaseExecutionData);
        testCaseExecutionData.setDataLib(testDataLib.getName());
        res = serviceAnswer.getResultMessage();
        // test data library returned by the service
        result = (List<HashMap<String, String>>) serviceAnswer.getDataList();
        if (result != null) {
            // Keeping raw data to testCaseExecutionData object.
            testCaseExecutionData.setDataLibRawData(result);
            // Value of testCaseExecutionData object takes the master subdata entry "".
            String value = (String) result.get(0).get("");
            if (value == null) {
                testCaseExecutionData.setValue(VALUE_NULL);
            } else {
                testCaseExecutionData.setValue(value);
                // Converting HashMap to json.
                String jsonText = "";
                JSONArray jsonResult = null;
                try {
                    jsonResult = dataLibService.convertToJSONObject(result);
                    jsonText = jsonResult.toString();
                } catch (JSONException ex) {
                    java.util.logging.Logger.getLogger(PropertyService.class.getName()).log(Level.SEVERE, null, ex);
                }
                testCaseExecutionData.setJsonResult(jsonText);
            }
            // Record result in filessytem.
            recorderService.recordTestDataLibProperty(tCExecution.getId(), testCaseCountryProperty.getProperty(), 1, result);
        }
        res.setDescription(res.getDescription().replace("%ENTRY%", testDataLib.getName()).replace("%ENTRYID%", String.valueOf(testDataLib.getTestDataLibID())));
    } else {
        // no TestDataLib found was returned
        // the library does not exist at all
        AnswerList nameExistsAnswer = testDataLibService.readNameListByName(testCaseExecutionData.getValue1(), 1, false);
        if (nameExistsAnswer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && nameExistsAnswer.getTotalRows() > 0) {
            // if the library name exists but was not available or does not exist for the current specification but exists for other countries/environments/systems
            res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOT_FOUND_ERROR);
            res.setDescription(res.getDescription().replace("%ITEM%", testCaseExecutionData.getValue1()).replace("%COUNTRY%", tCExecution.getCountryEnvironmentParameters().getCountry()).replace("%ENVIRONMENT%", tCExecution.getCountryEnvironmentParameters().getEnvironment()).replace("%SYSTEM%", tCExecution.getCountryEnvironmentParameters().getSystem()));
        } else {
            res = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_NOT_EXIST_ERROR);
            res.setDescription(res.getDescription().replace("%ITEM%", testCaseExecutionData.getValue1()));
        }
    }
    res.setDescription(res.getDescription().replace("%VALUE1%", testCaseExecutionData.getValue1()));
    testCaseExecutionData.setPropertyResultMessage(res);
    return testCaseExecutionData;
}
Also used : TestDataLib(org.cerberus.crud.entity.TestDataLib) AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) MessageEvent(org.cerberus.engine.entity.MessageEvent) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) AnswerItem(org.cerberus.util.answer.AnswerItem) CerberusEventException(org.cerberus.exception.CerberusEventException) IPropertyService(org.cerberus.engine.gwt.IPropertyService)

Aggregations

TestDataLib (org.cerberus.crud.entity.TestDataLib)16 MessageEvent (org.cerberus.engine.entity.MessageEvent)11 AnswerItem (org.cerberus.util.answer.AnswerItem)10 ArrayList (java.util.ArrayList)9 IFactoryTestDataLib (org.cerberus.crud.factory.IFactoryTestDataLib)8 AnswerList (org.cerberus.util.answer.AnswerList)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 ITestDataLibService (org.cerberus.crud.service.ITestDataLibService)6 JSONObject (org.json.JSONObject)6 HashMap (java.util.HashMap)5 JSONArray (org.json.JSONArray)5 List (java.util.List)4 TestDataLibData (org.cerberus.crud.entity.TestDataLibData)4 JSONException (org.json.JSONException)4 IFactoryTestDataLibData (org.cerberus.crud.factory.IFactoryTestDataLibData)3 ILogEventService (org.cerberus.crud.service.ILogEventService)3 Answer (org.cerberus.util.answer.Answer)3