@Test public void addNote_exception() throws Exception { Long parentId = 1329L; String parentType = "COMPLAINT"; Note incomingNote = new Note(); incomingNote.setId(700L); incomingNote.setCreator("testCreator"); incomingNote.setCreated(new Date()); incomingNote.setNote("Note"); incomingNote.setParentType(parentType); incomingNote.setParentId(parentId); Capture<Note> noteToSave = new Capture<>(); Capture<ApplicationNoteEvent> capturedEvent = new Capture<>(); expect(mockNoteDao.save(capture(noteToSave))).andThrow(new RuntimeException("testException")); mockNoteEventPublisher.publishNoteEvent(capture(capturedEvent)); expect(mockAuthentication.getName()).andReturn("userName").atLeastOnce(); replayAll(); ObjectMapper objectMapper = new ObjectMapper(); String in = objectMapper.writeValueAsString(incomingNote); log.debug("Input JSON: " + in); MvcResult result = mockMvc.perform( post("/api/latest/plugin/note") .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .contentType(MediaType.APPLICATION_JSON) .principal(mockAuthentication) .content(in)) .andReturn(); verifyAll(); assertEquals(incomingNote.getId(), noteToSave.getValue().getId()); }
protected void publishNoteEvent(HttpSession httpSession, Note note, String eventType, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationNoteEvent event = new ApplicationNoteEvent(note, eventType, succeeded, ipAddress); getNoteEventPublisher().publishNoteEvent(event); }
SaveNoteAPIController { protected void publishNoteEvent(HttpSession httpSession, Note note, String eventType, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationNoteEvent event = new ApplicationNoteEvent(note, eventType, succeeded, ipAddress); getNoteEventPublisher().publishNoteEvent(event); } }
SaveNoteAPIController { protected void publishNoteEvent(HttpSession httpSession, Note note, String eventType, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationNoteEvent event = new ApplicationNoteEvent(note, eventType, succeeded, ipAddress); getNoteEventPublisher().publishNoteEvent(event); }  }
SaveNoteAPIController { protected void publishNoteEvent(HttpSession httpSession, Note note, String eventType, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationNoteEvent event = new ApplicationNoteEvent(note, eventType, succeeded, ipAddress); getNoteEventPublisher().publishNoteEvent(event); }  @PreAuthorize("hasPermission(#note.parentId, #note.parentType, 'addComment')") @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody Note addNote(
            @RequestBody Note note, Authentication authentication, HttpSession httpSession); NoteEventPublisher getNoteEventPublisher(); void setNoteEventPublisher(NoteEventPublisher noteEventPublisher); NoteDao getNoteDao(); void setNoteDao(NoteDao noteDao); }
SaveNoteAPIController { protected void publishNoteEvent(HttpSession httpSession, Note note, String eventType, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationNoteEvent event = new ApplicationNoteEvent(note, eventType, succeeded, ipAddress); getNoteEventPublisher().publishNoteEvent(event); }  @PreAuthorize("hasPermission(#note.parentId, #note.parentType, 'addComment')") @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody Note addNote(
            @RequestBody Note note, Authentication authentication, HttpSession httpSession); NoteEventPublisher getNoteEventPublisher(); void setNoteEventPublisher(NoteEventPublisher noteEventPublisher); NoteDao getNoteDao(); void setNoteDao(NoteDao noteDao);  }