DictionaryController { @RequestMapping(value = {"/attribute_dictionary/save_attribute"}, method = {RequestMethod.POST}) public ModelAndView saveAttributeDictionary(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()); Attribute attributeData = null; AttributeValues attributeValueData = null; String userId = null; if (fromAPI) { attributeData = mapper.readValue(root.get(dictionaryFields).toString(), Attribute.class); attributeValueData = mapper.readValue(root.get(dictionaryFields).toString(), AttributeValues.class); userId = "API"; } else { attributeData = mapper.readValue(root.get("attributeDictionaryData").toString(), Attribute.class); attributeValueData = mapper.readValue(root.get("attributeDictionaryData").toString(), AttributeValues.class); userId = root.get("userid").textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(attributeData.getXacmlId(), xacmlId, Attribute.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { Attribute data = (Attribute) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { attributeData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != attributeData.getId()))) { duplicateflag = true; } } if (attributeValueData.getUserDataTypeValues() != null && !attributeValueData.getUserDataTypeValues().isEmpty()) { attributeData.setAttributeValue( utils.appendKey(attributeValueData.getUserDataTypeValues(), "attributeValues", ",")); } if (attributeData.getDatatypeBean().getShortName() != null) { String datatype = attributeData.getDatatypeBean().getShortName(); attributeData.setDatatypeBean(utils.getDataType(datatype)); } String responseString = null; if (!duplicateflag) { attributeData.setUserModifiedBy(userInfo); if (attributeData.getId() == 0) { attributeData.setCategoryBean(utils.getCategory()); attributeData.setUserCreatedBy(userInfo); commonClassDao.save(attributeData); } else { attributeData.setModifiedDate(new Date()); commonClassDao.update(attributeData); } responseString = mapper.writeValueAsString(commonClassDao.getData(Attribute.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, attributeDatas, 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 testSaveAttributeDictionary() { logger.info("testSaveAttributeDictionary: Entering"); MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); try { jsonString = "{\"attributeDictionaryData\":{\"datatypeBean\":{\"shortName\":\"string\"},\"description\":" + "\"Qwerty\",\"priority\":\"High\",\"userDataTypeValues\":[{\"$$hashKey\":" + "\"object:641\",\"attributeValues\":\"test\",\"id\":\"choice1\"},{\"$$hashKey\":" + "\"object:646\",\"attributeValues\":\"test\",\"id\":\"choice2\"}],\"xacmlId\":" + "\"Qwerty\"},\"userid\":\"demo\"}"; BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.saveAttributeDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("attributeDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); } logger.info("testSaveAttributeDictionary: exit"); }