@Test public void addNotification_exception() throws Exception { String user = "ann-acm"; Notification incomingNotification = new Notification(); incomingNotification.setId(700L); incomingNotification.setCreator("testCreator"); incomingNotification.setCreated(new Date()); incomingNotification.setUser(user); incomingNotification.setStatus("status"); incomingNotification.setAction("action"); incomingNotification.setModifier("modifier"); incomingNotification.setModified(new Date()); incomingNotification.setData("data"); incomingNotification.setType("type"); incomingNotification.setNote("note"); Capture<Notification> notificationToSave = new Capture<>(); Capture<ApplicationNotificationEvent> capturedEvent = new Capture<>(); expect(mockNotificationDao.save(capture(notificationToSave))).andThrow(new RuntimeException("testException")); mockNotificationEventPublisher.publishNotificationEvent(capture(capturedEvent)); expect(mockAuthentication.getName()).andReturn("userName").atLeastOnce(); replayAll(); ObjectMapper objectMapper = new ObjectMapper(); String in = objectMapper.writeValueAsString(incomingNotification); log.debug("Input JSON: " + in); MvcResult result = mockMvc.perform( post("/api/latest/plugin/notification") .accept(MediaType.parseMediaType("application/json;charset=UTF-8")) .contentType(MediaType.APPLICATION_JSON) .principal(mockAuthentication) .content(in)) .andReturn(); log.info("results: " + result.getResponse().getStatus()); verifyAll(); assertEquals(incomingNotification.getId(), notificationToSave.getValue().getId()); }
protected void publishNotificationEvent( HttpSession httpSession, Notification notification, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationNotificationEvent event = new ApplicationNotificationEvent(notification, "notification", succeeded, ipAddress); getNotificationEventPublisher().publishNotificationEvent(event); }
SaveNotificationAPIController { protected void publishNotificationEvent( HttpSession httpSession, Notification notification, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationNotificationEvent event = new ApplicationNotificationEvent(notification, "notification", succeeded, ipAddress); getNotificationEventPublisher().publishNotificationEvent(event); } }
SaveNotificationAPIController { protected void publishNotificationEvent( HttpSession httpSession, Notification notification, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationNotificationEvent event = new ApplicationNotificationEvent(notification, "notification", succeeded, ipAddress); getNotificationEventPublisher().publishNotificationEvent(event); }  }
SaveNotificationAPIController { protected void publishNotificationEvent( HttpSession httpSession, Notification notification, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationNotificationEvent event = new ApplicationNotificationEvent(notification, "notification", succeeded, ipAddress); getNotificationEventPublisher().publishNotificationEvent(event); }  @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody Notification addNotification(
            @RequestBody Notification notification,
            HttpSession httpSession); @RequestMapping(value = "/mentions", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody EmailMentionsDTO createPlainEmail(@RequestBody EmailMentionsDTO in,
                                             Authentication authentication, HttpSession session); NotificationEventPublisher getNotificationEventPublisher(); void setNotificationEventPublisher(
            NotificationEventPublisher notificationEventPublisher); NotificationDao getNotificationDao(); void setNotificationDao(NotificationDao notificationDao); AcmEmailMentionsService getAcmEmailMentionsService(); void setAcmEmailMentionsService(AcmEmailMentionsService acmEmailMentionsService); }
SaveNotificationAPIController { protected void publishNotificationEvent( HttpSession httpSession, Notification notification, boolean succeeded) { String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); ApplicationNotificationEvent event = new ApplicationNotificationEvent(notification, "notification", succeeded, ipAddress); getNotificationEventPublisher().publishNotificationEvent(event); }  @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody Notification addNotification(
            @RequestBody Notification notification,
            HttpSession httpSession); @RequestMapping(value = "/mentions", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody EmailMentionsDTO createPlainEmail(@RequestBody EmailMentionsDTO in,
                                             Authentication authentication, HttpSession session); NotificationEventPublisher getNotificationEventPublisher(); void setNotificationEventPublisher(
            NotificationEventPublisher notificationEventPublisher); NotificationDao getNotificationDao(); void setNotificationDao(NotificationDao notificationDao); AcmEmailMentionsService getAcmEmailMentionsService(); void setAcmEmailMentionsService(AcmEmailMentionsService acmEmailMentionsService);  }