@Test public final void testSearchPolicy() throws IOException { PolicyController.setjUnit(true); PolicyController.setPapUrl("http: PolicyRestController controller = new PolicyRestController(); BufferedReader reader = new BufferedReader(new StringReader("{\"foo\":\"bar\"}")); Mockito.when(request.getReader()).thenReturn(reader); Mockito.when(request.getRequestURI()).thenReturn("/pap/foo/"); assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> controller.searchPolicy(request, response)); }
@RequestMapping(value = {"/searchPolicy"}, method = {RequestMethod.POST}) public ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException { Object resultList; String uri = request.getRequestURI() + "?action=search"; if (uri.startsWith("/")) { uri = uri.substring(uri.indexOf('/') + 1); } uri = ONAP + uri.substring(uri.indexOf('/')); String body = callPap(request, "POST", uri.replaceFirst("/", "").trim()); JSONObject json = new JSONObject(body); try { resultList = json.get("policyresult"); } catch (Exception e) { List<String> data = new ArrayList<>(); resultList = json.get(DATA); data.add("Exception"); data.add(resultList.toString()); resultList = data; policyLogger.error("Exception Occured while searching for Policy in Elastic Database" + e); } response.setCharacterEncoding(UTF_8); response.setContentType("application / json"); request.setCharacterEncoding(UTF_8); response.getWriter().write(new JSONObject("{result: " + resultList + "}").toString()); return null; }
PolicyRestController extends RestrictedBaseController { @RequestMapping(value = {"/searchPolicy"}, method = {RequestMethod.POST}) public ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException { Object resultList; String uri = request.getRequestURI() + "?action=search"; if (uri.startsWith("/")) { uri = uri.substring(uri.indexOf('/') + 1); } uri = ONAP + uri.substring(uri.indexOf('/')); String body = callPap(request, "POST", uri.replaceFirst("/", "").trim()); JSONObject json = new JSONObject(body); try { resultList = json.get("policyresult"); } catch (Exception e) { List<String> data = new ArrayList<>(); resultList = json.get(DATA); data.add("Exception"); data.add(resultList.toString()); resultList = data; policyLogger.error("Exception Occured while searching for Policy in Elastic Database" + e); } response.setCharacterEncoding(UTF_8); response.setContentType("application / json"); request.setCharacterEncoding(UTF_8); response.getWriter().write(new JSONObject("{result: " + resultList + "}").toString()); return null; } }
PolicyRestController extends RestrictedBaseController { @RequestMapping(value = {"/searchPolicy"}, method = {RequestMethod.POST}) public ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException { Object resultList; String uri = request.getRequestURI() + "?action=search"; if (uri.startsWith("/")) { uri = uri.substring(uri.indexOf('/') + 1); } uri = ONAP + uri.substring(uri.indexOf('/')); String body = callPap(request, "POST", uri.replaceFirst("/", "").trim()); JSONObject json = new JSONObject(body); try { resultList = json.get("policyresult"); } catch (Exception e) { List<String> data = new ArrayList<>(); resultList = json.get(DATA); data.add("Exception"); data.add(resultList.toString()); resultList = data; policyLogger.error("Exception Occured while searching for Policy in Elastic Database" + e); } response.setCharacterEncoding(UTF_8); response.setContentType("application / json"); request.setCharacterEncoding(UTF_8); response.getWriter().write(new JSONObject("{result: " + resultList + "}").toString()); return null; } PolicyRestController(); @Autowired private  PolicyRestController(CommonClassDao commonClassDao); }
PolicyRestController extends RestrictedBaseController { @RequestMapping(value = {"/searchPolicy"}, method = {RequestMethod.POST}) public ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException { Object resultList; String uri = request.getRequestURI() + "?action=search"; if (uri.startsWith("/")) { uri = uri.substring(uri.indexOf('/') + 1); } uri = ONAP + uri.substring(uri.indexOf('/')); String body = callPap(request, "POST", uri.replaceFirst("/", "").trim()); JSONObject json = new JSONObject(body); try { resultList = json.get("policyresult"); } catch (Exception e) { List<String> data = new ArrayList<>(); resultList = json.get(DATA); data.add("Exception"); data.add(resultList.toString()); resultList = data; policyLogger.error("Exception Occured while searching for Policy in Elastic Database" + e); } response.setCharacterEncoding(UTF_8); response.setContentType("application / json"); request.setCharacterEncoding(UTF_8); response.getWriter().write(new JSONObject("{result: " + resultList + "}").toString()); return null; } 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 = {"/searchPolicy"}, method = {RequestMethod.POST}) public ModelAndView searchPolicy(HttpServletRequest request, HttpServletResponse response) throws IOException { Object resultList; String uri = request.getRequestURI() + "?action=search"; if (uri.startsWith("/")) { uri = uri.substring(uri.indexOf('/') + 1); } uri = ONAP + uri.substring(uri.indexOf('/')); String body = callPap(request, "POST", uri.replaceFirst("/", "").trim()); JSONObject json = new JSONObject(body); try { resultList = json.get("policyresult"); } catch (Exception e) { List<String> data = new ArrayList<>(); resultList = json.get(DATA); data.add("Exception"); data.add(resultList.toString()); resultList = data; policyLogger.error("Exception Occured while searching for Policy in Elastic Database" + e); } response.setCharacterEncoding(UTF_8); response.setContentType("application / json"); request.setCharacterEncoding(UTF_8); response.getWriter().write(new JSONObject("{result: " + resultList + "}").toString()); return null; } 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);  }