PolicyRestController extends RestrictedBaseController { @RequestMapping(value = {"/searchDictionary"}, method = {RequestMethod.POST}) public ModelAndView searchDictionaryController(HttpServletRequest request, HttpServletResponse response) throws IOException { Object resultList; String uri = request.getRequestURI(); if (uri.startsWith("/")) { uri = uri.substring(uri.indexOf('/') + 1); } uri = ONAP + uri.substring(uri.indexOf('/')); try { String body = callPap(request, "POST", uri.replaceFirst("/", "").trim()); if (body.contains("CouldNotConnectException")) { List<String> data = new ArrayList<>(); data.add("Elastic Search Server is down"); resultList = data; } else { resultList = new JSONObject(body).get("policyresult"); } } catch (Exception e) { policyLogger.error( XACMLErrorConstants.ERROR_PROCESS_FLOW + "Exception Occured while querying Elastic Search: " + e); List<String> data = new ArrayList<>(); data.add("Elastic Search Server is down"); resultList = data; } response.setCharacterEncoding(PolicyController.getCharacterencoding()); response.setContentType(PolicyController.getContenttype()); 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);  }
@Test public final void testSearchDictionaryController() throws IOException { 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/"); assertNull(controller.searchDictionaryController(request, response)); }