@Test public void completeTask() throws Exception { Long taskId = 500L; String ipAddress = "ipAddress"; AcmTask found = new AcmTask(); found.setTaskId(taskId); Capture<AcmApplicationTaskEvent> capturedEvent = new Capture<>(); mockHttpSession.setAttribute("acm_ip_address", ipAddress); expect(mockTaskDao.completeTask(eq(mockAuthentication), eq(taskId))).andReturn(found); mockTaskEventPublisher.publishTaskEvent(capture(capturedEvent)); expect(mockAuthentication.getName()).andReturn("user").atLeastOnce(); replayAll(); MvcResult result = mockMvc.perform( post("/api/v1/plugin/task/completeTask/{taskId}", taskId) .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .session(mockHttpSession) .principal(mockAuthentication)) .andReturn(); verifyAll(); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); assertTrue(result.getResponse().getContentType().startsWith(MediaType.APPLICATION_JSON_VALUE)); String returned = result.getResponse().getContentAsString(); log.info("results: " + returned); ObjectMapper objectMapper = new ObjectMapper(); AcmTask completedTask = objectMapper.readValue(returned, AcmTask.class); assertNotNull(completedTask); assertEquals(completedTask.getTaskId(), taskId); AcmApplicationTaskEvent event = capturedEvent.getValue(); assertEquals(taskId, event.getObjectId()); assertEquals("TASK", event.getObjectType()); assertTrue(event.isSucceeded()); }
@RequestMapping(value = "/completeTask/{taskId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmTask completeTask( @PathVariable("taskId") Long taskId, Authentication authentication, HttpSession httpSession, HttpServletResponse response) throws AcmUserActionFailedException { if (log.isInfoEnabled()) { log.info("Completing task '" + taskId + "'"); } try { AcmTask completed = getTaskDao().completeTask(authentication, taskId); completed.setStatus("CLOSED"); publishTaskCompletedEvent(authentication, httpSession, completed, true); return completed; } catch (AcmTaskException e) { AcmTask fakeTask = new AcmTask(); fakeTask.setTaskId(taskId); publishTaskCompletedEvent(authentication, httpSession, fakeTask, false); throw new AcmUserActionFailedException("complete", "task", taskId, e.getMessage(), e); } }
CompleteTaskAPIController { @RequestMapping(value = "/completeTask/{taskId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmTask completeTask( @PathVariable("taskId") Long taskId, Authentication authentication, HttpSession httpSession, HttpServletResponse response) throws AcmUserActionFailedException { if (log.isInfoEnabled()) { log.info("Completing task '" + taskId + "'"); } try { AcmTask completed = getTaskDao().completeTask(authentication, taskId); completed.setStatus("CLOSED"); publishTaskCompletedEvent(authentication, httpSession, completed, true); return completed; } catch (AcmTaskException e) { AcmTask fakeTask = new AcmTask(); fakeTask.setTaskId(taskId); publishTaskCompletedEvent(authentication, httpSession, fakeTask, false); throw new AcmUserActionFailedException("complete", "task", taskId, e.getMessage(), e); } } }
CompleteTaskAPIController { @RequestMapping(value = "/completeTask/{taskId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmTask completeTask( @PathVariable("taskId") Long taskId, Authentication authentication, HttpSession httpSession, HttpServletResponse response) throws AcmUserActionFailedException { if (log.isInfoEnabled()) { log.info("Completing task '" + taskId + "'"); } try { AcmTask completed = getTaskDao().completeTask(authentication, taskId); completed.setStatus("CLOSED"); publishTaskCompletedEvent(authentication, httpSession, completed, true); return completed; } catch (AcmTaskException e) { AcmTask fakeTask = new AcmTask(); fakeTask.setTaskId(taskId); publishTaskCompletedEvent(authentication, httpSession, fakeTask, false); throw new AcmUserActionFailedException("complete", "task", taskId, e.getMessage(), e); } }  }
CompleteTaskAPIController { @RequestMapping(value = "/completeTask/{taskId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmTask completeTask( @PathVariable("taskId") Long taskId, Authentication authentication, HttpSession httpSession, HttpServletResponse response) throws AcmUserActionFailedException { if (log.isInfoEnabled()) { log.info("Completing task '" + taskId + "'"); } try { AcmTask completed = getTaskDao().completeTask(authentication, taskId); completed.setStatus("CLOSED"); publishTaskCompletedEvent(authentication, httpSession, completed, true); return completed; } catch (AcmTaskException e) { AcmTask fakeTask = new AcmTask(); fakeTask.setTaskId(taskId); publishTaskCompletedEvent(authentication, httpSession, fakeTask, false); throw new AcmUserActionFailedException("complete", "task", taskId, e.getMessage(), e); } }  @RequestMapping(value = "/completeTask/{taskId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmTask completeTask(
            @PathVariable("taskId") Long taskId,
            Authentication authentication,
            HttpSession httpSession,
            HttpServletResponse response); TaskDao getTaskDao(); void setTaskDao(TaskDao taskDao); TaskEventPublisher getTaskEventPublisher(); void setTaskEventPublisher(TaskEventPublisher taskEventPublisher); }
CompleteTaskAPIController { @RequestMapping(value = "/completeTask/{taskId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmTask completeTask( @PathVariable("taskId") Long taskId, Authentication authentication, HttpSession httpSession, HttpServletResponse response) throws AcmUserActionFailedException { if (log.isInfoEnabled()) { log.info("Completing task '" + taskId + "'"); } try { AcmTask completed = getTaskDao().completeTask(authentication, taskId); completed.setStatus("CLOSED"); publishTaskCompletedEvent(authentication, httpSession, completed, true); return completed; } catch (AcmTaskException e) { AcmTask fakeTask = new AcmTask(); fakeTask.setTaskId(taskId); publishTaskCompletedEvent(authentication, httpSession, fakeTask, false); throw new AcmUserActionFailedException("complete", "task", taskId, e.getMessage(), e); } }  @RequestMapping(value = "/completeTask/{taskId}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmTask completeTask(
            @PathVariable("taskId") Long taskId,
            Authentication authentication,
            HttpSession httpSession,
            HttpServletResponse response); TaskDao getTaskDao(); void setTaskDao(TaskDao taskDao); TaskEventPublisher getTaskEventPublisher(); void setTaskEventPublisher(TaskEventPublisher taskEventPublisher);  }