DescriptiveDictionaryController { @RequestMapping(value = {"/descriptive_dictionary/save_descriptive"}, method = {RequestMethod.POST}) public ModelAndView saveDescriptiveDictionary(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()); DescriptiveScope descriptiveScope; GridData data; String userId = null; if (fromAPI) { descriptiveScope = mapper.readValue(root.get("dictionaryFields").toString(), DescriptiveScope.class); data = mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); userId = "API"; } else { descriptiveScope = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), DescriptiveScope.class); data = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), GridData.class); userId = root.get("userid").textValue(); } descriptiveScope.setSearch(utils.appendKeyValue(data.getAttributes(), "AND", ":")); UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(descriptiveScope.getScopeName(), dScopeName, DescriptiveScope.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { DescriptiveScope data1 = (DescriptiveScope) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { descriptiveScope.setId(data1.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data1.getId() != descriptiveScope.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { descriptiveScope.setUserModifiedBy(userInfo); if (descriptiveScope.getId() == 0) { descriptiveScope.setUserCreatedBy(userInfo); commonClassDao.save(descriptiveScope); } else { descriptiveScope.setModifiedDate(new Date()); commonClassDao.update(descriptiveScope); } responseString = mapper.writeValueAsString(commonClassDao.getData(DescriptiveScope.class)); } else { responseString = "Duplicate"; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, descriptiveDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  DescriptiveDictionaryController(CommonClassDao commonClassDao);  DescriptiveDictionaryController(); void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping( value = {"/get_DescriptiveScopeByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getDescriptiveDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_DescriptiveScope"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getDescriptiveDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/descriptive_dictionary/save_descriptive"}, method = {RequestMethod.POST}) ModelAndView saveDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/descriptive_dictionary/remove_descriptiveScope"}, method = {RequestMethod.POST}) void removeDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response);  }
@Test public void testSaveDescriptiveDictionary() { jsonString = "{\"descriptiveScopeDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":" + "\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\"," + "\"descriptiveScopeName\":\"Test\",\"search\":\"Test\"},\"userid\":\"demo\"}"; try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveDescriptiveDictionary(request, response); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); } catch (Exception e) { logger.error("Exception" + e); } }
@Test public void testUpdateDescriptiveDictionary() { jsonString = "{\"descriptiveScopeDictionaryData\":{\"attributes\":[{\"$$hashKey\":\"object:257\",\"id\":" + "\"choice1\",\"number\":\"12\",\"option\":\"test\"}],\"description\":\"test\"," + "\"descriptiveScopeName\":\"Test\",\"id\":1,\"search\":\"Test\"},\"userid\":\"demo\"}"; try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveDescriptiveDictionary(request, response); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("descriptiveScopeDictionaryDatas")); } catch (Exception e) { logger.error("Exception" + e); } }