@PrepareForTest(UserUtils.class) @Test public void testSaveDictionaryController() throws IOException { HttpServletRequest mockRequest = Mockito.mock(HttpServletRequest.class); HttpServletResponse mockResponse = Mockito.mock(HttpServletResponse.class); PolicyRestController controller = new PolicyRestController(); User mockUser = Mockito.mock(User.class); PowerMockito.mockStatic(UserUtils.class); PrintWriter mockPrintWriter = Mockito.mock(PrintWriter.class); when(mockRequest.getRequestURI()).thenReturn(" when(mockResponse.getWriter()).thenReturn(mockPrintWriter); when(UserUtils.getUserSession(mockRequest)).thenReturn(mockUser); when(mockUser.getOrgUserId()).thenReturn("testUserId"); controller.saveDictionaryController(mockRequest, mockResponse); verify(mockRequest).getRequestURI(); verify(mockResponse).getWriter(); verify(mockUser).getOrgUserId(); when(mockRequest.getRequestURI()).thenReturn("testRequestURI controller.saveDictionaryController(mockRequest, mockResponse); verify(mockRequest, atLeast(1)).getRequestURI(); }
@RequestMapping(value = {"/saveDictionary/*/*"}, method = {RequestMethod.POST}) public void saveDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException { String userId = ""; String uri = request.getRequestURI().replace("/saveDictionary", ""); if (uri.startsWith("/")) { uri = uri.substring(uri.indexOf('/') + 1); } uri = ONAP + uri.substring(uri.indexOf('/')); if (uri.contains(IMPORT_DICTIONARY)) { userId = UserUtils.getUserSession(request).getOrgUserId(); uri = uri + "?userId=" + userId; } policyLogger.info( "********************Logging UserID while Saving Dictionary**************************************"); policyLogger.info(USER_ID + userId); policyLogger.info( "************************************************************************************************"); String body = callPap(request, "POST", uri.replaceFirst("/", "").trim()); if (body != null && !body.isEmpty()) { response.getWriter().write(body); } else { response.getWriter().write("Failed"); } }
PolicyRestController extends RestrictedBaseController { @RequestMapping(value = {"/saveDictionary/*/*"}, method = {RequestMethod.POST}) public void saveDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException { String userId = ""; String uri = request.getRequestURI().replace("/saveDictionary", ""); if (uri.startsWith("/")) { uri = uri.substring(uri.indexOf('/') + 1); } uri = ONAP + uri.substring(uri.indexOf('/')); if (uri.contains(IMPORT_DICTIONARY)) { userId = UserUtils.getUserSession(request).getOrgUserId(); uri = uri + "?userId=" + userId; } policyLogger.info( "********************Logging UserID while Saving Dictionary**************************************"); policyLogger.info(USER_ID + userId); policyLogger.info( "************************************************************************************************"); String body = callPap(request, "POST", uri.replaceFirst("/", "").trim()); if (body != null && !body.isEmpty()) { response.getWriter().write(body); } else { response.getWriter().write("Failed"); } } }
PolicyRestController extends RestrictedBaseController { @RequestMapping(value = {"/saveDictionary/*/*"}, method = {RequestMethod.POST}) public void saveDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException { String userId = ""; String uri = request.getRequestURI().replace("/saveDictionary", ""); if (uri.startsWith("/")) { uri = uri.substring(uri.indexOf('/') + 1); } uri = ONAP + uri.substring(uri.indexOf('/')); if (uri.contains(IMPORT_DICTIONARY)) { userId = UserUtils.getUserSession(request).getOrgUserId(); uri = uri + "?userId=" + userId; } policyLogger.info( "********************Logging UserID while Saving Dictionary**************************************"); policyLogger.info(USER_ID + userId); policyLogger.info( "************************************************************************************************"); String body = callPap(request, "POST", uri.replaceFirst("/", "").trim()); if (body != null && !body.isEmpty()) { response.getWriter().write(body); } else { response.getWriter().write("Failed"); } } PolicyRestController(); @Autowired private  PolicyRestController(CommonClassDao commonClassDao); }
PolicyRestController extends RestrictedBaseController { @RequestMapping(value = {"/saveDictionary/*/*"}, method = {RequestMethod.POST}) public void saveDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException { String userId = ""; String uri = request.getRequestURI().replace("/saveDictionary", ""); if (uri.startsWith("/")) { uri = uri.substring(uri.indexOf('/') + 1); } uri = ONAP + uri.substring(uri.indexOf('/')); if (uri.contains(IMPORT_DICTIONARY)) { userId = UserUtils.getUserSession(request).getOrgUserId(); uri = uri + "?userId=" + userId; } policyLogger.info( "********************Logging UserID while Saving Dictionary**************************************"); policyLogger.info(USER_ID + userId); policyLogger.info( "************************************************************************************************"); String body = callPap(request, "POST", uri.replaceFirst("/", "").trim()); if (body != null && !body.isEmpty()) { response.getWriter().write(body); } else { response.getWriter().write("Failed"); } } PolicyRestController(); @Autowired private  PolicyRestController(CommonClassDao commonClassDao); static CommonClassDao getCommonClassDao(); static void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping(value = {"/policycreation/save_policy"}, method = {RequestMethod.POST}) void policyCreationController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/getDictionary/*"}, method = {RequestMethod.GET}) void getDictionaryController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/saveDictionary/*/*"}, method = {RequestMethod.POST}) void saveDictionaryController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/deleteDictionary/*/*"}, method = {RequestMethod.POST}) void deletetDictionaryController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/searchDictionary"}, method = {RequestMethod.POST}) ModelAndView searchDictionaryController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/searchPolicy"}, method = {RequestMethod.POST}) ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response); void deleteElasticData(String fileName); String notifyOtherPapsToUpdateConfigurations(String mode, String newName, String oldName); }
PolicyRestController extends RestrictedBaseController { @RequestMapping(value = {"/saveDictionary/*/*"}, method = {RequestMethod.POST}) public void saveDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException { String userId = ""; String uri = request.getRequestURI().replace("/saveDictionary", ""); if (uri.startsWith("/")) { uri = uri.substring(uri.indexOf('/') + 1); } uri = ONAP + uri.substring(uri.indexOf('/')); if (uri.contains(IMPORT_DICTIONARY)) { userId = UserUtils.getUserSession(request).getOrgUserId(); uri = uri + "?userId=" + userId; } policyLogger.info( "********************Logging UserID while Saving Dictionary**************************************"); policyLogger.info(USER_ID + userId); policyLogger.info( "************************************************************************************************"); String body = callPap(request, "POST", uri.replaceFirst("/", "").trim()); if (body != null && !body.isEmpty()) { response.getWriter().write(body); } else { response.getWriter().write("Failed"); } } PolicyRestController(); @Autowired private  PolicyRestController(CommonClassDao commonClassDao); static CommonClassDao getCommonClassDao(); static void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping(value = {"/policycreation/save_policy"}, method = {RequestMethod.POST}) void policyCreationController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/getDictionary/*"}, method = {RequestMethod.GET}) void getDictionaryController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/saveDictionary/*/*"}, method = {RequestMethod.POST}) void saveDictionaryController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/deleteDictionary/*/*"}, method = {RequestMethod.POST}) void deletetDictionaryController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/searchDictionary"}, method = {RequestMethod.POST}) ModelAndView searchDictionaryController(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/searchPolicy"}, method = {RequestMethod.POST}) ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response); void deleteElasticData(String fileName); String notifyOtherPapsToUpdateConfigurations(String mode, String newName, String oldName);  }