ActionPolicyDictionaryController { @RequestMapping(value = {"/action_dictionary/save_ActionDict"}, method = {RequestMethod.POST}) public ModelAndView saveActionPolicyDictionary(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()); ActionPolicyDict actionPolicyDict = null; ActionAdapter adapter = null; String userId = null; if (fromAPI) { actionPolicyDict = mapper.readValue(root.get("dictionaryFields").toString(), ActionPolicyDict.class); adapter = mapper.readValue(root.get("dictionaryFields").toString(), ActionAdapter.class); userId = "API"; } else { actionPolicyDict = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionPolicyDict.class); adapter = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionAdapter.class); userId = root.get("userid").textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(actionPolicyDict.getAttributeName(), attributeName, ActionPolicyDict.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { ActionPolicyDict data = (ActionPolicyDict) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { actionPolicyDict.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != actionPolicyDict.getId()))) { duplicateflag = true; } } actionPolicyDict.setHeader(utils.appendKeyValue(adapter.getHeaders(), ":", "=")); String responseString = null; if (!duplicateflag) { actionPolicyDict.setUserModifiedBy(userInfo); if (actionPolicyDict.getId() == 0) { actionPolicyDict.setUserCreatedBy(userInfo); commonClassDao.save(actionPolicyDict); } else { actionPolicyDict.setModifiedDate(new Date()); commonClassDao.update(actionPolicyDict); } responseString = mapper.writeValueAsString(commonClassDao.getData(ActionPolicyDict.class)); } else { responseString = "Duplicate"; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, actionDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  ActionPolicyDictionaryController(CommonClassDao commonClassDao);  ActionPolicyDictionaryController(); void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping( value = {"/get_ActionPolicyDictDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getActionEntitybyName(HttpServletResponse response); @RequestMapping( value = {"/get_ActionPolicyDictData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getActionPolicyDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/action_dictionary/save_ActionDict"}, method = {RequestMethod.POST}) ModelAndView saveActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/action_dictionary/remove_actionPolicyDict"}, method = {RequestMethod.POST}) void removeActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response);  }
@Test public void testSaveActionPolicyDictionary() { jsonString = "{\"actionPolicyDictionaryData\":{\"attributeName\":\"Test\",\"body\":\"{}\",\"description\":" + "\"test\",\"headers\":[{\"$$hashKey\":\"object:548\",\"id\":\"choice1\",\"number\":\"12\"," + "\"option\":\"test\"}],\"method\":\"GET\",\"type\":\"REST\",\"url\":\"http: + "\"userid\":\"demo\"}"; try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveActionPolicyDictionary(request, response); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryData")); } catch (Exception e) { logger.error("Exception" + e); } }
@Test public void testUpdateActionPolicyDictionary() { jsonString = "{\"actionPolicyDictionaryData\":{\"id\":1,\"attributeName\":\"Test\",\"body\":\"{}\",\"description\":" + "\"test\",\"headers\":[{\"$$hashKey\":\"object:548\",\"id\":\"choice1\",\"number\":" + "\"12\",\"option\":\"test\"}],\"method\":\"GET\",\"type\":\"REST\",\"url\":\"http: + "\"userid\":\"demo\"}"; try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveActionPolicyDictionary(request, response); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("actionPolicyDictionaryData")); } catch (Exception e) { logger.error("Exception" + e); } }