BRMSDictionaryController { @RequestMapping(value = {"/brms_dictionary/save_BRMSParam"}, method = {RequestMethod.POST}) public ModelAndView saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); BrmsParamTemplate bRMSParamTemplateData; String userId = null; if (fromAPI) { bRMSParamTemplateData = mapper.readValue(root.get(dictionaryFields).toString(), BrmsParamTemplate.class); userId = "API"; } else { bRMSParamTemplateData = mapper.readValue(root.get("brmsParamDictionaryData").toString(), BrmsParamTemplate.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(bRMSParamTemplateData.getRuleName(), ruleName, BrmsParamTemplate.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { BrmsParamTemplate data = (BrmsParamTemplate) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { bRMSParamTemplateData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != bRMSParamTemplateData.getId()))) { duplicateflag = true; } } String responseString = null; boolean validation = false; if (rule != null && CreateBRMSRuleTemplate.validateRuleParams(rule)) { bRMSParamTemplateData.setRule(rule); validation = true; if (!duplicateflag) { if (bRMSParamTemplateData.getId() == 0) { bRMSParamTemplateData.setUserCreatedBy(userInfo); commonClassDao.save(bRMSParamTemplateData); } else { commonClassDao.update(bRMSParamTemplateData); } responseString = mapper.writeValueAsString(commonClassDao.getData(BrmsParamTemplate.class)); } else { responseString = duplicateResponseString; } } if (!validation) { responseString = VALIDATIONRESPONSE; } if (fromAPI) { if (responseString != null && !(duplicateResponseString).equals(responseString) && !VALIDATIONRESPONSE.equals(responseString)) { responseString = successMsg; } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { utils.setResponseData(response, brmsParamDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  BRMSDictionaryController(CommonClassDao commonClassDao);  BRMSDictionaryController(); static void setCommonClassDao(CommonClassDao commonClassDao2); @RequestMapping( value = {"/get_BRMSParamDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSParamDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_BRMSParamData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSParamDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/set_BRMSParamData"}, method = {RequestMethod.POST}) static void setRuleData(HttpServletRequest request); @RequestMapping(value = {"/brms_dictionary/save_BRMSParam"}, method = {RequestMethod.POST}) ModelAndView saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/remove_brmsParam"}, method = {RequestMethod.POST}) void removeBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_BRMSDependencyDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSDependencyDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_BRMSDependencyData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSDependencyDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/save_BRMSDependencyData"}, method = {RequestMethod.POST}) ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/remove_brmsDependency"}, method = {RequestMethod.POST}) void removeBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_BRMSControllerDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSControllerDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_BRMSControllerData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSControllerDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/save_BRMSControllerData"}, method = {RequestMethod.POST}) ModelAndView saveBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/remove_brmsController"}, method = {RequestMethod.POST}) void removeBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response); BrmsDependency getDependencyDataByID(String dependencyName); BrmsController getControllerDataByID(String controllerName);  }
@Test public void testSaveBRMSParamDictionary() { logger.info("testSaveBRMSParamDictionary: Entering"); jsonString = "{\"brmsParamDictionaryData\": {\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}"; try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveBRMSParamDictionary(request, response); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("brmsParamDictionaryData")); logger.info("response.getContentAsString(): " + response.getContentAsString()); } catch (Exception e) { logger.error("Exception" + e); } logger.info("testSaveBRMSParamDictionary: exit"); }