@Test public void testGetPeople() { List<String> searchTerms = new ArrayList<>(); searchTerms.add("q1"); searchTerms.add("q2"); IPerson person = new PersonImpl(); person.setUserName(USER_NAME); person.setFullName("john doe"); List<IPersonAttributes> personAttributes = getIPersonAttributes(); Mockito.when(personManager.getPerson(req)).thenReturn(person); Mockito.when(lookupHelper.searchForPeople(Mockito.any(), Mockito.anyMap())) .thenReturn(personAttributes); ModelAndView modelAndView = peopleRESTController.getPeople(searchTerms, req, res); Assert.assertEquals("json", modelAndView.getViewName()); List<IPersonAttributes> persons = (List<IPersonAttributes>) modelAndView.getModel().get("people"); Assert.assertEquals(1L, persons.size()); }
@RequestMapping(value = "/people.json", method = RequestMethod.GET) public ModelAndView getPeople( @RequestParam("searchTerms[]") List<String> searchTerms, HttpServletRequest request, HttpServletResponse response) { final IPerson person = personManager.getPerson((HttpServletRequest) request); if (person == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return null; } Map<String, Object> query = new HashMap<>(); for (String term : searchTerms) { String search = request.getParameter(term); if (StringUtils.isNotBlank(search)) { query.put(term, search); } } List<IPersonAttributes> people = lookupHelper.searchForPeople(person, query); ModelAndView mv = new ModelAndView(); mv.addObject("people", people); mv.setViewName("json"); return mv; }
PeopleRESTController { @RequestMapping(value = "/people.json", method = RequestMethod.GET) public ModelAndView getPeople( @RequestParam("searchTerms[]") List<String> searchTerms, HttpServletRequest request, HttpServletResponse response) { final IPerson person = personManager.getPerson((HttpServletRequest) request); if (person == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return null; } Map<String, Object> query = new HashMap<>(); for (String term : searchTerms) { String search = request.getParameter(term); if (StringUtils.isNotBlank(search)) { query.put(term, search); } } List<IPersonAttributes> people = lookupHelper.searchForPeople(person, query); ModelAndView mv = new ModelAndView(); mv.addObject("people", people); mv.setViewName("json"); return mv; } }
PeopleRESTController { @RequestMapping(value = "/people.json", method = RequestMethod.GET) public ModelAndView getPeople( @RequestParam("searchTerms[]") List<String> searchTerms, HttpServletRequest request, HttpServletResponse response) { final IPerson person = personManager.getPerson((HttpServletRequest) request); if (person == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return null; } Map<String, Object> query = new HashMap<>(); for (String term : searchTerms) { String search = request.getParameter(term); if (StringUtils.isNotBlank(search)) { query.put(term, search); } } List<IPersonAttributes> people = lookupHelper.searchForPeople(person, query); ModelAndView mv = new ModelAndView(); mv.addObject("people", people); mv.setViewName("json"); return mv; }  }
PeopleRESTController { @RequestMapping(value = "/people.json", method = RequestMethod.GET) public ModelAndView getPeople( @RequestParam("searchTerms[]") List<String> searchTerms, HttpServletRequest request, HttpServletResponse response) { final IPerson person = personManager.getPerson((HttpServletRequest) request); if (person == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return null; } Map<String, Object> query = new HashMap<>(); for (String term : searchTerms) { String search = request.getParameter(term); if (StringUtils.isNotBlank(search)) { query.put(term, search); } } List<IPersonAttributes> people = lookupHelper.searchForPeople(person, query); ModelAndView mv = new ModelAndView(); mv.addObject("people", people); mv.setViewName("json"); return mv; }  @Autowired void setPersonManager(IPersonManager personManager); @Autowired(required = true) void setPersonLookupHelper(PersonLookupHelperImpl lookupHelper); @RequestMapping(value = "/people.json", method = RequestMethod.GET) ModelAndView getPeople(
            @RequestParam("searchTerms[]") List<String> searchTerms,
            HttpServletRequest request,
            HttpServletResponse response); @RequestMapping(value = "/people/{username}.json", method = RequestMethod.GET) ModelAndView getPerson(
            @PathVariable String username,
            HttpServletRequest request,
            HttpServletResponse response); }
PeopleRESTController { @RequestMapping(value = "/people.json", method = RequestMethod.GET) public ModelAndView getPeople( @RequestParam("searchTerms[]") List<String> searchTerms, HttpServletRequest request, HttpServletResponse response) { final IPerson person = personManager.getPerson((HttpServletRequest) request); if (person == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return null; } Map<String, Object> query = new HashMap<>(); for (String term : searchTerms) { String search = request.getParameter(term); if (StringUtils.isNotBlank(search)) { query.put(term, search); } } List<IPersonAttributes> people = lookupHelper.searchForPeople(person, query); ModelAndView mv = new ModelAndView(); mv.addObject("people", people); mv.setViewName("json"); return mv; }  @Autowired void setPersonManager(IPersonManager personManager); @Autowired(required = true) void setPersonLookupHelper(PersonLookupHelperImpl lookupHelper); @RequestMapping(value = "/people.json", method = RequestMethod.GET) ModelAndView getPeople(
            @RequestParam("searchTerms[]") List<String> searchTerms,
            HttpServletRequest request,
            HttpServletResponse response); @RequestMapping(value = "/people/{username}.json", method = RequestMethod.GET) ModelAndView getPerson(
            @PathVariable String username,
            HttpServletRequest request,
            HttpServletResponse response);  }