@Test public void testSearchPeople() throws IOException { Map<String, Object> query = getQuery(); IPerson person = new PersonImpl(); person.setUserName(USER_NAME); person.setFullName("john doe"); Mockito.when(personManager.getPerson(req)).thenReturn(person); Mockito.when(lookupHelper.searchForPeople(person, query)) .thenReturn(getIPersonAttributes()); peopleRESTControllerV50.searchPeople(query, req, res); Assert.assertEquals(200, res.getStatus()); Assert.assertNotNull(res.getOutputStream()); }
@RequestMapping(method = RequestMethod.GET) public void searchPeople( @RequestParam Map<String, Object> query, HttpServletRequest request, HttpServletResponse response) throws IOException { final IPerson user = personManager.getPerson((HttpServletRequest) request); if (user == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return; } List<IPersonAttributes> people = lookupHelper.searchForPeople(user, query); if (people == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } List<Object> results = new ArrayList<>(); for (IPersonAttributes p : people) { results.add(p.getAttributes()); } response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); jsonMapper.writeValue(response.getOutputStream(), results); }
PeopleRESTControllerV50 { @RequestMapping(method = RequestMethod.GET) public void searchPeople( @RequestParam Map<String, Object> query, HttpServletRequest request, HttpServletResponse response) throws IOException { final IPerson user = personManager.getPerson((HttpServletRequest) request); if (user == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return; } List<IPersonAttributes> people = lookupHelper.searchForPeople(user, query); if (people == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } List<Object> results = new ArrayList<>(); for (IPersonAttributes p : people) { results.add(p.getAttributes()); } response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); jsonMapper.writeValue(response.getOutputStream(), results); } }
PeopleRESTControllerV50 { @RequestMapping(method = RequestMethod.GET) public void searchPeople( @RequestParam Map<String, Object> query, HttpServletRequest request, HttpServletResponse response) throws IOException { final IPerson user = personManager.getPerson((HttpServletRequest) request); if (user == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return; } List<IPersonAttributes> people = lookupHelper.searchForPeople(user, query); if (people == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } List<Object> results = new ArrayList<>(); for (IPersonAttributes p : people) { results.add(p.getAttributes()); } response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); jsonMapper.writeValue(response.getOutputStream(), results); }  }
PeopleRESTControllerV50 { @RequestMapping(method = RequestMethod.GET) public void searchPeople( @RequestParam Map<String, Object> query, HttpServletRequest request, HttpServletResponse response) throws IOException { final IPerson user = personManager.getPerson((HttpServletRequest) request); if (user == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return; } List<IPersonAttributes> people = lookupHelper.searchForPeople(user, query); if (people == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } List<Object> results = new ArrayList<>(); for (IPersonAttributes p : people) { results.add(p.getAttributes()); } response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); jsonMapper.writeValue(response.getOutputStream(), results); }  @Autowired void setJsonMapper(ObjectMapper jsonMapper); @Autowired void setPersonManager(IPersonManager personManager); @Autowired(required = true) void setPersonLookupHelper(PersonLookupHelperImpl lookupHelper); @RequestMapping(method = RequestMethod.GET) void searchPeople(
            @RequestParam Map<String, Object> query,
            HttpServletRequest request,
            HttpServletResponse response); @RequestMapping(value = "/{username}", method = RequestMethod.GET) ModelAndView getPerson(
            @PathVariable String username,
            HttpServletRequest request,
            HttpServletResponse response); @RequestMapping(value = "/me", method = RequestMethod.GET) ModelAndView getMe(HttpServletRequest request, HttpServletResponse response); }
PeopleRESTControllerV50 { @RequestMapping(method = RequestMethod.GET) public void searchPeople( @RequestParam Map<String, Object> query, HttpServletRequest request, HttpServletResponse response) throws IOException { final IPerson user = personManager.getPerson((HttpServletRequest) request); if (user == null) { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return; } List<IPersonAttributes> people = lookupHelper.searchForPeople(user, query); if (people == null) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } List<Object> results = new ArrayList<>(); for (IPersonAttributes p : people) { results.add(p.getAttributes()); } response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); jsonMapper.writeValue(response.getOutputStream(), results); }  @Autowired void setJsonMapper(ObjectMapper jsonMapper); @Autowired void setPersonManager(IPersonManager personManager); @Autowired(required = true) void setPersonLookupHelper(PersonLookupHelperImpl lookupHelper); @RequestMapping(method = RequestMethod.GET) void searchPeople(
            @RequestParam Map<String, Object> query,
            HttpServletRequest request,
            HttpServletResponse response); @RequestMapping(value = "/{username}", method = RequestMethod.GET) ModelAndView getPerson(
            @PathVariable String username,
            HttpServletRequest request,
            HttpServletResponse response); @RequestMapping(value = "/me", method = RequestMethod.GET) ModelAndView getMe(HttpServletRequest request, HttpServletResponse response);  }