@Test public void tasksForUser_exception() throws Exception { String user = "user"; String ipAddress = "ipAddress"; expect(mockTaskDao.tasksForUser(user)).andThrow(new PersistenceException("testMessage")); mockHttpSession.setAttribute("acm_ip_address", ipAddress); expect(mockAuthentication.getName()).andReturn("user"); replayAll(); mockMvc.perform( get("/api/v1/plugin/task/forUser/{user}", user) .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .principal(mockAuthentication) .session(mockHttpSession)) .andExpect(status().isInternalServerError()) .andExpect(content().contentType(MediaType.TEXT_PLAIN)); verifyAll(); }
@RequestMapping(value = "/forUser/{user:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public List<AcmTask> tasksForUser( @PathVariable("user") String user, Authentication authentication, HttpSession session) throws AcmListObjectsFailedException { if (log.isInfoEnabled()) { log.info("Finding tasks assigned to user '" + user + "'"); } String ipAddress = (String) session.getAttribute("acm_ip_address"); try { List<AcmTask> retval = getTaskDao().tasksForUser(user); for (AcmTask task : retval) { AcmApplicationTaskEvent event = new AcmApplicationTaskEvent(task, "searchResult", authentication.getName(), true, ipAddress); getTaskEventPublisher().publishTaskEvent(event); } return retval; } catch (Exception e) { log.error("List Tasks Failed: " + e.getMessage(), e); throw new AcmListObjectsFailedException("task", e.getMessage(), e); } }
ListTasksAPIController { @RequestMapping(value = "/forUser/{user:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public List<AcmTask> tasksForUser( @PathVariable("user") String user, Authentication authentication, HttpSession session) throws AcmListObjectsFailedException { if (log.isInfoEnabled()) { log.info("Finding tasks assigned to user '" + user + "'"); } String ipAddress = (String) session.getAttribute("acm_ip_address"); try { List<AcmTask> retval = getTaskDao().tasksForUser(user); for (AcmTask task : retval) { AcmApplicationTaskEvent event = new AcmApplicationTaskEvent(task, "searchResult", authentication.getName(), true, ipAddress); getTaskEventPublisher().publishTaskEvent(event); } return retval; } catch (Exception e) { log.error("List Tasks Failed: " + e.getMessage(), e); throw new AcmListObjectsFailedException("task", e.getMessage(), e); } } }
ListTasksAPIController { @RequestMapping(value = "/forUser/{user:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public List<AcmTask> tasksForUser( @PathVariable("user") String user, Authentication authentication, HttpSession session) throws AcmListObjectsFailedException { if (log.isInfoEnabled()) { log.info("Finding tasks assigned to user '" + user + "'"); } String ipAddress = (String) session.getAttribute("acm_ip_address"); try { List<AcmTask> retval = getTaskDao().tasksForUser(user); for (AcmTask task : retval) { AcmApplicationTaskEvent event = new AcmApplicationTaskEvent(task, "searchResult", authentication.getName(), true, ipAddress); getTaskEventPublisher().publishTaskEvent(event); } return retval; } catch (Exception e) { log.error("List Tasks Failed: " + e.getMessage(), e); throw new AcmListObjectsFailedException("task", e.getMessage(), e); } }  }
ListTasksAPIController { @RequestMapping(value = "/forUser/{user:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public List<AcmTask> tasksForUser( @PathVariable("user") String user, Authentication authentication, HttpSession session) throws AcmListObjectsFailedException { if (log.isInfoEnabled()) { log.info("Finding tasks assigned to user '" + user + "'"); } String ipAddress = (String) session.getAttribute("acm_ip_address"); try { List<AcmTask> retval = getTaskDao().tasksForUser(user); for (AcmTask task : retval) { AcmApplicationTaskEvent event = new AcmApplicationTaskEvent(task, "searchResult", authentication.getName(), true, ipAddress); getTaskEventPublisher().publishTaskEvent(event); } return retval; } catch (Exception e) { log.error("List Tasks Failed: " + e.getMessage(), e); throw new AcmListObjectsFailedException("task", e.getMessage(), e); } }  @RequestMapping(value = "/forUser/{user:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<AcmTask> tasksForUser(
            @PathVariable("user") String user,
            Authentication authentication,
            HttpSession session); TaskDao getTaskDao(); void setTaskDao(TaskDao taskDao); TaskEventPublisher getTaskEventPublisher(); void setTaskEventPublisher(TaskEventPublisher taskEventPublisher); }
ListTasksAPIController { @RequestMapping(value = "/forUser/{user:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public List<AcmTask> tasksForUser( @PathVariable("user") String user, Authentication authentication, HttpSession session) throws AcmListObjectsFailedException { if (log.isInfoEnabled()) { log.info("Finding tasks assigned to user '" + user + "'"); } String ipAddress = (String) session.getAttribute("acm_ip_address"); try { List<AcmTask> retval = getTaskDao().tasksForUser(user); for (AcmTask task : retval) { AcmApplicationTaskEvent event = new AcmApplicationTaskEvent(task, "searchResult", authentication.getName(), true, ipAddress); getTaskEventPublisher().publishTaskEvent(event); } return retval; } catch (Exception e) { log.error("List Tasks Failed: " + e.getMessage(), e); throw new AcmListObjectsFailedException("task", e.getMessage(), e); } }  @RequestMapping(value = "/forUser/{user:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<AcmTask> tasksForUser(
            @PathVariable("user") String user,
            Authentication authentication,
            HttpSession session); TaskDao getTaskDao(); void setTaskDao(TaskDao taskDao); TaskEventPublisher getTaskEventPublisher(); void setTaskEventPublisher(TaskEventPublisher taskEventPublisher);  }