MicroServiceDictionaryController { @RequestMapping(value = {"/ms_dictionary/save_modelAttribute"}, method = {RequestMethod.POST}) public ModelAndView saveMicroServiceAttributeDictionary(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()); MicroServiceAttribute microServiceAttribute; String checkValue; if (fromAPI) { microServiceAttribute = mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceAttribute.class); } else { microServiceAttribute = mapper.readValue(root.get("modelAttributeDictionaryData").toString(), MicroServiceAttribute.class); } checkValue = microServiceAttribute.getName() + ":" + microServiceAttribute.getValue() + ":" + microServiceAttribute.getModelName(); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkValue, "name:value:modelName", MicroServiceAttribute.class); boolean duplicateflag = false; if (duplicateData != null && !duplicateData.isEmpty()) { MicroServiceAttribute data = (MicroServiceAttribute) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { microServiceAttribute.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != microServiceAttribute.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { if (microServiceAttribute.getId() == 0) { commonClassDao.save(microServiceAttribute); } else { commonClassDao.update(microServiceAttribute); } responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, microServiceAttributeDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } MicroServiceDictionaryController(); @Autowired  MicroServiceDictionaryController(CommonClassDao commonClassDao); static void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping( value = {"/get_DCAEUUIDDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getDCAEUUIDDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_DCAEUUIDData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getDCAEUUIDDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_dcaeUUID"}, method = {RequestMethod.POST}) ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_dcaeuuid"}, method = {RequestMethod.POST}) void removeDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceConfigNameDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceConfigNameData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceConfigNameDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceDictData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceDictNameDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_DictionaryData"}, method = {RequestMethod.POST}) ModelAndView saveDictionaryData(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_msDictionaryData"}, method = {RequestMethod.POST}) void removeMicroServiceDictionaryData(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_configName"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_msConfigName"}, method = {RequestMethod.POST}) void removeMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceLocationDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceLocationByNameDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceLocationData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceLocationDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_location"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_msLocation"}, method = {RequestMethod.POST}) void removeMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceAttributeDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceAttributeData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceAttributeDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_modelAttribute"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_modelAttribute"}, method = {RequestMethod.POST}) void removeMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsDataByVersion"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryByVersionEntityData(HttpServletRequest request,
            HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsDataServiceVersion"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryEntityDataServiceVersion(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceModelsDataByClass"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceModelsDictionaryClassEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_model"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_msModel"}, method = {RequestMethod.POST}) void removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceHeaderDefaultsDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceHeaderDefaultsEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_MicroServiceHeaderDefaultsData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getMicroServiceHeaderDefaultsEntityData(HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/save_headerDefaults"}, method = {RequestMethod.POST}) ModelAndView saveMicroServiceHeaderDefaultValues(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ms_dictionary/remove_headerDefaults"}, method = {RequestMethod.POST}) void removeMicroServiceHeaderDefaults(HttpServletRequest request, HttpServletResponse response);  }
@Test public void testSaveMicroServiceAttributeDictionary() { logger.info("testSaveMicroServiceAttributeDictionary: Entering"); MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); try { jsonString = "{\"modelAttributeDictionaryData\": {\"modelName\": \"test\",\"inprocess\": false," + "\"model\": {\"name\": \"testingdata\",\"subScopename\": \"\",\"path\": []," + "\"type\": \"dir\",\"size\": 0,\"date\": \"2017-04-12T21:26:57.000Z\",\"version\": \"\"," + "\"createdBy\": \"someone\",\"modifiedBy\": \"someone\",\"content\": \"\"," + "\"recursive\": false},\"tempModel\": " + "{\"name\": \"testingdata\",\"subScopename\": \"\"}," + " \"policy\": {\"policyType\": \"Config\",\"configPolicyType\": \"Micro Service\"," + "\"policyName\": \"may1501\",\"policyDescription\": \"testing input\"," + "\"onapName\": \"RaviTest\",\"guard\": \"False\",\"riskType\": \"Risk12345\"," + "\"riskLevel\": \"2\",\"priority\": \"6\",\"serviceType\": \"DkatPolicyBody\"," + "\"version\": \"1707.41.02\",\"ruleGridData\": [[\"fileId\"]],\"ttlDate\": null}}," + "\"policyJSON\": {\"pmTableName\": \"test\",\"dmdTopic\": \"1\",\"fileId\": \"56\"}}"; BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.saveMicroServiceAttributeDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("microServiceAttributeDictionaryDatas")); } catch (Exception e) { fail("Exception: " + e); } logger.info("testSaveMicroServiceAttributeDictionary: exit"); }