@Test public void createAdHocTask() throws Exception { String name = "20140827_202"; String type = "COMPLAINT"; String query = "object_type_s:" + type; query += " AND name:" + name + " AND -status_s:DELETE"; String solrResponse = "{ \"responseHeader\": { \"status\": 0, \"QTime\": 5, \"params\": { \"indent\": \"true\", \"q\": \"name: 20140827_202,\", \"_\": \"1411491195199\", \"wt\": \"json\" } }, \"response\": { \"numFound\": 1, \"start\": 0, \"docs\": [ { \"status_s\": \"DRAFT\", \"create_dt\": \"2014-08-27T16:04:25Z\", \"title_t\": \"Test complaint for report\", \"object_id_s\": \"202\", \"owner_s\": \"ann-acm\", \"deny_acl_ss\": [ \"TEST-DENY-ACL\" ], \"object_type_s\": \"COMPLAINT\", \"allow_acl_ss\": [ \"TEST-ALLOW-ACL\" ], \"id\": \"202-Complaint\", \"modifier_s\": \"ann-acm\", \"author\": \"ann-acm\", \"author_s\": \"ann-acm\", \"last_modified\": \"2014-08-27T16:04:25Z\", \"name\": \"20140827_202\", \"_version_\": 1477621708197200000 } ] } } "; Long taskId = 500L; String ipAddress = "ipAddress"; AcmTask adHoc = new AcmTask(); adHoc.setAssignee("assignee"); adHoc.setAttachedToObjectType(type); adHoc.setDetails("details"); adHoc.setPercentComplete(23); adHoc.setStatus("ASSIGNED"); adHoc.setTaskStartDate(new Date()); adHoc.setTitle("title"); adHoc.setAttachedToObjectName(name); AcmTask found = new AcmTask(); found.setAssignee(adHoc.getAssignee()); found.setTaskId(taskId); found.setStatus("ASSIGNED"); Capture<AcmTask> taskSentToDao = Capture.newInstance(); Capture<AcmApplicationTaskEvent> capturedEvent = Capture.newInstance(); ObjectMapper objectMapper = new ObjectMapper(); String inJson = objectMapper.writeValueAsString(adHoc); mockHttpSession.setAttribute("acm_ip_address", ipAddress); expect(mockTaskDao.createAdHocTask(capture(taskSentToDao))).andReturn(found); expect(mockExecuteSolrQuery.getResultsByPredefinedQuery(mockAuthentication, SolrCore.QUICK_SEARCH, query, 0, 10, "")) .andReturn(solrResponse).atLeastOnce(); mockTaskEventPublisher.publishTaskEvent(capture(capturedEvent)); expect(mockAuthentication.getName()).andReturn("user").atLeastOnce(); replayAll(); MvcResult result = mockMvc.perform(post("/api/v1/plugin/task/adHocTask") .accept(MediaType.parseMediaType("application/json;charset=UTF-8")).session(mockHttpSession) .principal(mockAuthentication).contentType(MediaType.APPLICATION_JSON).content(inJson)).andReturn(); verifyAll(); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); assertTrue(result.getResponse().getContentType().startsWith(MediaType.APPLICATION_JSON_VALUE)); AcmTask sentToDao = taskSentToDao.getValue(); assertNull(sentToDao.getTaskId()); assertEquals(adHoc.getAssignee(), sentToDao.getAssignee()); String returned = result.getResponse().getContentAsString(); log.info("results: " + returned); AcmTask newTask = objectMapper.readValue(returned, AcmTask.class); assertNotNull(newTask); assertEquals(newTask.getTaskId(), found.getTaskId()); AcmApplicationTaskEvent event = capturedEvent.getValue(); assertEquals(taskId, event.getObjectId()); assertEquals("TASK", event.getObjectType()); assertTrue(event.isSucceeded()); }
@RequestMapping(value = "/adHocTask", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmTask createAdHocTask(@RequestBody AcmTask in, Authentication authentication, HttpSession httpSession) throws AcmAppErrorJsonMsg, AcmCreateObjectFailedException { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); return createAdHocTaskService.createAdHocTask(in, authentication, ipAddress); }
CreateAdHocTaskAPIController { @RequestMapping(value = "/adHocTask", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmTask createAdHocTask(@RequestBody AcmTask in, Authentication authentication, HttpSession httpSession) throws AcmAppErrorJsonMsg, AcmCreateObjectFailedException { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); return createAdHocTaskService.createAdHocTask(in, authentication, ipAddress); } }
CreateAdHocTaskAPIController { @RequestMapping(value = "/adHocTask", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmTask createAdHocTask(@RequestBody AcmTask in, Authentication authentication, HttpSession httpSession) throws AcmAppErrorJsonMsg, AcmCreateObjectFailedException { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); return createAdHocTaskService.createAdHocTask(in, authentication, ipAddress); }  }
CreateAdHocTaskAPIController { @RequestMapping(value = "/adHocTask", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmTask createAdHocTask(@RequestBody AcmTask in, Authentication authentication, HttpSession httpSession) throws AcmAppErrorJsonMsg, AcmCreateObjectFailedException { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); return createAdHocTaskService.createAdHocTask(in, authentication, ipAddress); }  @RequestMapping(value = "/adHocTask", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmTask createAdHocTask(@RequestBody AcmTask in, Authentication authentication, HttpSession httpSession); CreateAdHocTaskService getCreateAdHocTaskService(); void setCreateAdHocTaskService(CreateAdHocTaskService createAdHocTaskService); }
CreateAdHocTaskAPIController { @RequestMapping(value = "/adHocTask", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public AcmTask createAdHocTask(@RequestBody AcmTask in, Authentication authentication, HttpSession httpSession) throws AcmAppErrorJsonMsg, AcmCreateObjectFailedException { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); return createAdHocTaskService.createAdHocTask(in, authentication, ipAddress); }  @RequestMapping(value = "/adHocTask", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody AcmTask createAdHocTask(@RequestBody AcmTask in, Authentication authentication, HttpSession httpSession); CreateAdHocTaskService getCreateAdHocTaskService(); void setCreateAdHocTaskService(CreateAdHocTaskService createAdHocTaskService);  }