DecisionPolicyDictionaryController { @RequestMapping(value = {"/decision_dictionary/save_RainyDay"}, method = {RequestMethod.POST}) public ModelAndView saveRainyDayDictionary(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()); RainyDayTreatments decisionRainyDay; TreatmentValues treatmentsData = null; if (fromAPI) { decisionRainyDay = mapper.readValue(root.get(dictionaryFields).toString(), RainyDayTreatments.class); treatmentsData = mapper.readValue(root.get(dictionaryFields).toString(), TreatmentValues.class); } else { decisionRainyDay = mapper.readValue(root.get("rainyDayDictionaryData").toString(), RainyDayTreatments.class); treatmentsData = mapper.readValue(root.get("rainyDayDictionaryData").toString(), TreatmentValues.class); } decisionRainyDay.setTreatments(utils.appendKey(treatmentsData.getUserDataTypeValues(), "treatment", ",")); List<Object> duplicateData = commonClassDao.checkDuplicateEntry( decisionRainyDay.getBbid() + ":" + decisionRainyDay.getWorkstep(), "bbid:workstep", RainyDayTreatments.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { RainyDayTreatments data = (RainyDayTreatments) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { decisionRainyDay.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != decisionRainyDay.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { if (decisionRainyDay.getId() == 0) { commonClassDao.save(decisionRainyDay); } else { commonClassDao.update(decisionRainyDay); } responseString = mapper.writeValueAsString(commonClassDao.getData(RainyDayTreatments.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, rainDayDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  DecisionPolicyDictionaryController(CommonClassDao commonClassDao);  DecisionPolicyDictionaryController(); @RequestMapping( value = {"/get_SettingsDictionaryDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getSettingsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_SettingsDictionaryData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getSettingsDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/decision_dictionary/save_Settings"}, method = {RequestMethod.POST}) ModelAndView saveSettingsDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/settings_dictionary/remove_settings"}, method = {RequestMethod.POST}) void removeSettingsDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_RainyDayDictionaryDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getRainyDayDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_RainyDayDictionaryData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getRainyDayDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/decision_dictionary/save_RainyDay"}, method = {RequestMethod.POST}) ModelAndView saveRainyDayDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/decision_dictionary/remove_rainyDay"}, method = {RequestMethod.POST}) void removeRainyDayDictionary(HttpServletRequest request, HttpServletResponse response);  }
@Test public void testSaveRainyDayDictionary() { logger.info("testSaveRainyDayDictionary: Entering"); MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); try { jsonString = "{\"rainyDayDictionaryData\":{\"bbid\":\"BB2\",\"workstep\":\"1\",\"userDataTypeValues\"" + ":[{\"$$hashKey\":\"object:233\",\"treatment\":\"test1\"},{\"$$hashKey\":\"object:239\"," + "\"treatment\":\"test2\"}]},\"userid\":\"mm117s\"}"; BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.saveRainyDayDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); } catch (Exception e) { logger.error("Exception Occured" + e); fail("Exception: " + e); } logger.info("testSaveRainyDayDictionary: exit"); }