@Test public void deleteNoteById_notFound() throws Exception { Long noteId = 234L; Long parentId = 800L; expect(mockNote.getId()).andReturn(noteId); expect(mockNote.getCreated()).andReturn(new Date()); expect(mockNote.getModifier()).andReturn("user"); expect(mockNote.getParentId()).andReturn(parentId); expect(mockNote.getParentType()).andReturn("PARENT_TYPE"); expect(mockNoteDao.find(eq(noteId))).andReturn(mockNote); mockNoteDao.deleteNoteById(eq(noteId)); expectLastCall(); Capture<ApplicationNoteEvent> capturedEvent = newCapture(); mockNoteEventPublisher.publishNoteEvent(capture(capturedEvent)); expectLastCall(); expect(mockAuthentication.getName()).andReturn("user"); replayAll(); mockMvc.perform( delete("/api/latest/plugin/note/{noteId}", noteId) .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .principal(mockAuthentication)); verifyAll(); }
@RequestMapping(value = "/{noteId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public String deleteNoteById( @PathVariable("noteId") Long id, HttpSession session ) throws AcmObjectNotFoundException, AcmUserActionFailedException { log.info("Finding note with ID : [{}]", id); String ipAddress = (String) session.getAttribute("acm_ip_address"); if (id != null) { Note note = getNoteDao().find(id); try { log.info("Deleting note by ID : [{}]", id); JSONObject objectToReturnJSON = new JSONObject(); getNoteDao().deleteNoteById(id); ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", true, ipAddress); getNoteEventPublisher().publishNoteEvent(event); objectToReturnJSON.put("deletedNoteId", id); String objectToReturn; objectToReturn = objectToReturnJSON.toString(); return objectToReturn; } catch (PersistenceException e) { ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", false, ipAddress); getNoteEventPublisher().publishNoteEvent(event); throw new AcmUserActionFailedException("Delete", "note", id, e.getMessage(), e); } } throw new AcmObjectNotFoundException("Note", id, "Could not find note", null); }
DeleteNoteByIdAPIController { @RequestMapping(value = "/{noteId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public String deleteNoteById( @PathVariable("noteId") Long id, HttpSession session ) throws AcmObjectNotFoundException, AcmUserActionFailedException { log.info("Finding note with ID : [{}]", id); String ipAddress = (String) session.getAttribute("acm_ip_address"); if (id != null) { Note note = getNoteDao().find(id); try { log.info("Deleting note by ID : [{}]", id); JSONObject objectToReturnJSON = new JSONObject(); getNoteDao().deleteNoteById(id); ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", true, ipAddress); getNoteEventPublisher().publishNoteEvent(event); objectToReturnJSON.put("deletedNoteId", id); String objectToReturn; objectToReturn = objectToReturnJSON.toString(); return objectToReturn; } catch (PersistenceException e) { ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", false, ipAddress); getNoteEventPublisher().publishNoteEvent(event); throw new AcmUserActionFailedException("Delete", "note", id, e.getMessage(), e); } } throw new AcmObjectNotFoundException("Note", id, "Could not find note", null); } }
DeleteNoteByIdAPIController { @RequestMapping(value = "/{noteId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public String deleteNoteById( @PathVariable("noteId") Long id, HttpSession session ) throws AcmObjectNotFoundException, AcmUserActionFailedException { log.info("Finding note with ID : [{}]", id); String ipAddress = (String) session.getAttribute("acm_ip_address"); if (id != null) { Note note = getNoteDao().find(id); try { log.info("Deleting note by ID : [{}]", id); JSONObject objectToReturnJSON = new JSONObject(); getNoteDao().deleteNoteById(id); ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", true, ipAddress); getNoteEventPublisher().publishNoteEvent(event); objectToReturnJSON.put("deletedNoteId", id); String objectToReturn; objectToReturn = objectToReturnJSON.toString(); return objectToReturn; } catch (PersistenceException e) { ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", false, ipAddress); getNoteEventPublisher().publishNoteEvent(event); throw new AcmUserActionFailedException("Delete", "note", id, e.getMessage(), e); } } throw new AcmObjectNotFoundException("Note", id, "Could not find note", null); }  }
DeleteNoteByIdAPIController { @RequestMapping(value = "/{noteId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public String deleteNoteById( @PathVariable("noteId") Long id, HttpSession session ) throws AcmObjectNotFoundException, AcmUserActionFailedException { log.info("Finding note with ID : [{}]", id); String ipAddress = (String) session.getAttribute("acm_ip_address"); if (id != null) { Note note = getNoteDao().find(id); try { log.info("Deleting note by ID : [{}]", id); JSONObject objectToReturnJSON = new JSONObject(); getNoteDao().deleteNoteById(id); ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", true, ipAddress); getNoteEventPublisher().publishNoteEvent(event); objectToReturnJSON.put("deletedNoteId", id); String objectToReturn; objectToReturn = objectToReturnJSON.toString(); return objectToReturn; } catch (PersistenceException e) { ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", false, ipAddress); getNoteEventPublisher().publishNoteEvent(event); throw new AcmUserActionFailedException("Delete", "note", id, e.getMessage(), e); } } throw new AcmObjectNotFoundException("Note", id, "Could not find note", null); }  @RequestMapping(value = "/{noteId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String deleteNoteById(
            @PathVariable("noteId") Long id,
            HttpSession session

    ); NoteDao getNoteDao(); void setNoteDao(NoteDao noteDao); NoteEventPublisher getNoteEventPublisher(); void setNoteEventPublisher(NoteEventPublisher noteEventPublisher); }
DeleteNoteByIdAPIController { @RequestMapping(value = "/{noteId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public String deleteNoteById( @PathVariable("noteId") Long id, HttpSession session ) throws AcmObjectNotFoundException, AcmUserActionFailedException { log.info("Finding note with ID : [{}]", id); String ipAddress = (String) session.getAttribute("acm_ip_address"); if (id != null) { Note note = getNoteDao().find(id); try { log.info("Deleting note by ID : [{}]", id); JSONObject objectToReturnJSON = new JSONObject(); getNoteDao().deleteNoteById(id); ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", true, ipAddress); getNoteEventPublisher().publishNoteEvent(event); objectToReturnJSON.put("deletedNoteId", id); String objectToReturn; objectToReturn = objectToReturnJSON.toString(); return objectToReturn; } catch (PersistenceException e) { ApplicationNoteEvent event = new ApplicationNoteEvent(note, "deleted", false, ipAddress); getNoteEventPublisher().publishNoteEvent(event); throw new AcmUserActionFailedException("Delete", "note", id, e.getMessage(), e); } } throw new AcmObjectNotFoundException("Note", id, "Could not find note", null); }  @RequestMapping(value = "/{noteId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String deleteNoteById(
            @PathVariable("noteId") Long id,
            HttpSession session

    ); NoteDao getNoteDao(); void setNoteDao(NoteDao noteDao); NoteEventPublisher getNoteEventPublisher(); void setNoteEventPublisher(NoteEventPublisher noteEventPublisher);  }