@Test public void testCreateTaskItem() throws Exception { OutlookTaskItem taskItem = new OutlookTaskItem(); taskItem.setSubject("Task 1"); taskItem.setBody(""); long tomorrow = System.currentTimeMillis() + 1000 * 60 * 60 * 24; taskItem.setDueDate(new Date(tomorrow)); taskItem.setPercentComplete(20); taskItem.setComplete(false); taskItem.setStartDate(new Date(System.currentTimeMillis() + 1000 * 60)); assertNull(taskItem.getId()); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); String content = objectMapper.writeValueAsString(taskItem); expect(mockAuthentication.getName()).andReturn("user").times(2); OutlookDTO password = new OutlookDTO(); password.setOutlookPassword("outlookPassword"); expect(outlookService.retrieveOutlookPassword(mockAuthentication)).andReturn(password); AcmUser user = new AcmUser(); user.setMail("test@armedia.com"); session.setAttribute("acm_user", user); Capture<AcmOutlookUser> outlookUserCapture = new Capture<>(); Capture<OutlookTaskItem> taskItemCapture = new Capture<>(); taskItem.setId("some_fake_id"); expect(outlookService.createOutlookTaskItem(capture(outlookUserCapture), eq(WellKnownFolderName.Tasks), capture(taskItemCapture))) .andReturn(taskItem); replayAll(); MvcResult result = mockMvc .perform(post("/api/latest/plugin/outlook/tasks").session(session).accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON).principal(mockAuthentication).content(content)) .andExpect(status().isOk()).andReturn(); OutlookTaskItem item = objectMapper.readValue(result.getResponse().getContentAsString(), OutlookTaskItem.class); assertNotNull(item.getId()); }
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public OutlookTaskItem createTaskItem(@RequestBody OutlookTaskItem in, Authentication authentication, HttpSession session) throws AcmEncryptionException { AcmUser user = (AcmUser) session.getAttribute("acm_user"); OutlookDTO outlookDTO = getOutlookService().retrieveOutlookPassword(authentication); AcmOutlookUser outlookUser = new AcmOutlookUser(authentication.getName(), user.getMail(), outlookDTO.getOutlookPassword()); in = outlookService.createOutlookTaskItem(outlookUser, WellKnownFolderName.Tasks, in); return in; }
CreateTaskItemAPIController { @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public OutlookTaskItem createTaskItem(@RequestBody OutlookTaskItem in, Authentication authentication, HttpSession session) throws AcmEncryptionException { AcmUser user = (AcmUser) session.getAttribute("acm_user"); OutlookDTO outlookDTO = getOutlookService().retrieveOutlookPassword(authentication); AcmOutlookUser outlookUser = new AcmOutlookUser(authentication.getName(), user.getMail(), outlookDTO.getOutlookPassword()); in = outlookService.createOutlookTaskItem(outlookUser, WellKnownFolderName.Tasks, in); return in; } }
CreateTaskItemAPIController { @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public OutlookTaskItem createTaskItem(@RequestBody OutlookTaskItem in, Authentication authentication, HttpSession session) throws AcmEncryptionException { AcmUser user = (AcmUser) session.getAttribute("acm_user"); OutlookDTO outlookDTO = getOutlookService().retrieveOutlookPassword(authentication); AcmOutlookUser outlookUser = new AcmOutlookUser(authentication.getName(), user.getMail(), outlookDTO.getOutlookPassword()); in = outlookService.createOutlookTaskItem(outlookUser, WellKnownFolderName.Tasks, in); return in; }  }
CreateTaskItemAPIController { @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public OutlookTaskItem createTaskItem(@RequestBody OutlookTaskItem in, Authentication authentication, HttpSession session) throws AcmEncryptionException { AcmUser user = (AcmUser) session.getAttribute("acm_user"); OutlookDTO outlookDTO = getOutlookService().retrieveOutlookPassword(authentication); AcmOutlookUser outlookUser = new AcmOutlookUser(authentication.getName(), user.getMail(), outlookDTO.getOutlookPassword()); in = outlookService.createOutlookTaskItem(outlookUser, WellKnownFolderName.Tasks, in); return in; }  @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody OutlookTaskItem createTaskItem(@RequestBody OutlookTaskItem in, Authentication authentication, HttpSession session); UserOrgService getUserOrgService(); void setUserOrgService(UserOrgService userOrgService); OutlookService getOutlookService(); void setOutlookService(OutlookService outlookService); }
CreateTaskItemAPIController { @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public OutlookTaskItem createTaskItem(@RequestBody OutlookTaskItem in, Authentication authentication, HttpSession session) throws AcmEncryptionException { AcmUser user = (AcmUser) session.getAttribute("acm_user"); OutlookDTO outlookDTO = getOutlookService().retrieveOutlookPassword(authentication); AcmOutlookUser outlookUser = new AcmOutlookUser(authentication.getName(), user.getMail(), outlookDTO.getOutlookPassword()); in = outlookService.createOutlookTaskItem(outlookUser, WellKnownFolderName.Tasks, in); return in; }  @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody OutlookTaskItem createTaskItem(@RequestBody OutlookTaskItem in, Authentication authentication, HttpSession session); UserOrgService getUserOrgService(); void setUserOrgService(UserOrgService userOrgService); OutlookService getOutlookService(); void setOutlookService(OutlookService outlookService);  }