ClosedLoopDictionaryController { @RequestMapping(value = {"/cl_dictionary/save_varbind"}, method = {RequestMethod.POST}) public ModelAndView saveVarbind(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()); VarbindDictionary varbindDictionary; String userId = null; if (fromAPI) { varbindDictionary = mapper.readValue(root.get(dictionaryFields).toString(), VarbindDictionary.class); userId = "API"; } else { varbindDictionary = mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { VarbindDictionary data = (VarbindDictionary) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { varbindDictionary.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != varbindDictionary.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { varbindDictionary.setUserModifiedBy(userInfo); if (varbindDictionary.getId() == 0) { varbindDictionary.setUserCreatedBy(userInfo); commonClassDao.save(varbindDictionary); } else { varbindDictionary.setModifiedDate(new Date()); commonClassDao.update(varbindDictionary); } responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, varbindDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  ClosedLoopDictionaryController(CommonClassDao commonClassDao);  ClosedLoopDictionaryController(); void setCommonClassDao(CommonClassDao commonClassDao); static void setCommonClassDao(CommonClassDaoImpl commonClassDaoImpl); @RequestMapping( value = {"/get_VSCLActionDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VSCLActionData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVSCLActionDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VNFTypeDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VNFTypeData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVNFTypeDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_PEPOptionsDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_PEPOptionsData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPEPOptionsDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VarbindDictionaryDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVarbindDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VarbindDictionaryData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVarbindDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_ClosedLoopServicesDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_ClosedLoopServicesData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_ClosedLoopSiteDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_ClosedLoopSiteData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_vsclAction"}, method = {RequestMethod.POST}) ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_VsclAction"}, method = {RequestMethod.POST}) void removeVSCLAction(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_vnfType"}, method = {RequestMethod.POST}) ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_vnfType"}, method = {RequestMethod.POST}) void removeVnfType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_pepOptions"}, method = {RequestMethod.POST}) ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_pepOptions"}, method = {RequestMethod.POST}) void removePEPOptions(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_service"}, method = {RequestMethod.POST}) ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_Service"}, method = {RequestMethod.POST}) void removeServiceType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_siteName"}, method = {RequestMethod.POST}) ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_site"}, method = {RequestMethod.POST}) void removeSiteType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_varbind"}, method = {RequestMethod.POST}) ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_varbindDict"}, method = {RequestMethod.POST}) void removeVarbind(HttpServletRequest request, HttpServletResponse response);  }
@Test public void testSaveVarbind() { jsonString = "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"description\":\"test\",\"varbindName\":\"Test\"}}"; try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveVarbind(request, response); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas")); } catch (Exception e) { logger.error("Exception" + e); } }
@Test public void testUpdateVarbind() { jsonString = "{\"userid\":\"demo\",\"varbindDictionaryData\":{\"id\":1,\"description\":\"test\",\"varbindName\":\"Test\"}}"; try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveVarbind(request, response); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("varbindDictionaryDatas")); } catch (Exception e) { logger.error("Exception" + e); } }