DictionaryController { @RequestMapping(value = {"/onap_dictionary/save_onapName"}, method = {RequestMethod.POST}) public ModelAndView saveOnapDictionary(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()); OnapName onapData; String userId = null; if (fromAPI) { onapData = mapper.readValue(root.get(dictionaryFields).toString(), OnapName.class); userId = "API"; } else { onapData = mapper.readValue(root.get("onapNameDictionaryData").toString(), OnapName.class); userId = root.get("userid").textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), onapName, OnapName.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { OnapName data = (OnapName) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { onapData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != onapData.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { onapData.setUserModifiedBy(userInfo); if (onapData.getId() == 0) { onapData.setUserCreatedBy(userInfo); commonClassDao.save(onapData); } else { onapData.setModifiedDate(new Date()); commonClassDao.update(onapData); } responseString = mapper.writeValueAsString(commonClassDao.getData(OnapName.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, onapNameDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  DictionaryController(CommonClassDao commonClassDao);  DictionaryController(); @RequestMapping( value = {"/get_AttributeDatabyAttributeName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getAttributeDictionaryEntityDatabyAttributeName(HttpServletResponse response); @RequestMapping( value = "/get_AttributeData", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) void getAttributeDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/attribute_dictionary/save_attribute"}, method = {RequestMethod.POST}) ModelAndView saveAttributeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/attribute_dictionary/remove_attribute"}, method = {RequestMethod.POST}) void removeAttributeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_OnapNameDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getOnapNameDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_OnapNameData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getOnapNameDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/onap_dictionary/save_onapName"}, method = {RequestMethod.POST}) ModelAndView saveOnapDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/onap_dictionary/remove_onap"}, method = {RequestMethod.POST}) void removeOnapDictionary(HttpServletRequest request, HttpServletResponse response);  }
@Test public void testSaveOnapDictionary() { logger.info("testSaveOnapDictionary: Entering"); MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); try { jsonString = "{\"userid\":\"demo\",\"onapNameDictionaryData\":{\"description\":\"test\",\"onapName\":\"Test\"}}"; BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.saveOnapDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("onapNameDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); } logger.info("testSaveOnapDictionary: exit"); }