@Test public void addNotification() 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))).andReturn(incomingNotification); 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(); verifyAll(); assertEquals(incomingNotification.getId(), notificationToSave.getValue().getId()); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); }
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public Notification addNotification( @RequestBody Notification notification, HttpSession httpSession) throws AcmUserActionFailedException { if (log.isInfoEnabled()) { if (notification != null) { log.info("Notification ID : " + notification.getId()); } else { throw new AcmUserActionFailedException("addNote", NotificationConstants.OBJECT_TYPE, null, "Could not save note, missing parent type and ID", new NullPointerException()); } } try { Notification newNotification = new Notification(); newNotification.setId(notification.getId()); newNotification.setCreated(notification.getCreated()); newNotification.setCreator(notification.getCreator()); newNotification.setStatus(notification.getStatus()); newNotification.setAction(notification.getAction()); newNotification.setNote(notification.getNote()); newNotification.setModifier(notification.getModifier()); newNotification.setModified(notification.getModified()); newNotification.setData(notification.getData()); newNotification.setType(notification.getType()); newNotification.setUser(notification.getUser()); Notification savedNotification = getNotificationDao().save(notification); publishNotificationEvent(httpSession, savedNotification, true); return savedNotification; } catch (Exception e) { Notification fakeNotification = new Notification(); fakeNotification.setId(notification.getId()); log.info("fake id : " + fakeNotification.getId()); log.info("fake id 2: " + notification.getId()); fakeNotification.setId(notification.getId()); fakeNotification.setCreated(notification.getCreated()); fakeNotification.setCreator(notification.getCreator()); fakeNotification.setStatus(notification.getStatus()); fakeNotification.setAction(notification.getAction()); fakeNotification.setNote(notification.getNote()); fakeNotification.setModifier(notification.getModifier()); fakeNotification.setModified(notification.getModified()); fakeNotification.setData(notification.getData()); fakeNotification.setType(notification.getType()); fakeNotification.setUser(notification.getUser()); publishNotificationEvent(httpSession, fakeNotification, false); throw new AcmUserActionFailedException("unable to add notification from ", notification.getUser(), notification.getId(), e.getMessage(), e); } }
SaveNotificationAPIController { @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public Notification addNotification( @RequestBody Notification notification, HttpSession httpSession) throws AcmUserActionFailedException { if (log.isInfoEnabled()) { if (notification != null) { log.info("Notification ID : " + notification.getId()); } else { throw new AcmUserActionFailedException("addNote", NotificationConstants.OBJECT_TYPE, null, "Could not save note, missing parent type and ID", new NullPointerException()); } } try { Notification newNotification = new Notification(); newNotification.setId(notification.getId()); newNotification.setCreated(notification.getCreated()); newNotification.setCreator(notification.getCreator()); newNotification.setStatus(notification.getStatus()); newNotification.setAction(notification.getAction()); newNotification.setNote(notification.getNote()); newNotification.setModifier(notification.getModifier()); newNotification.setModified(notification.getModified()); newNotification.setData(notification.getData()); newNotification.setType(notification.getType()); newNotification.setUser(notification.getUser()); Notification savedNotification = getNotificationDao().save(notification); publishNotificationEvent(httpSession, savedNotification, true); return savedNotification; } catch (Exception e) { Notification fakeNotification = new Notification(); fakeNotification.setId(notification.getId()); log.info("fake id : " + fakeNotification.getId()); log.info("fake id 2: " + notification.getId()); fakeNotification.setId(notification.getId()); fakeNotification.setCreated(notification.getCreated()); fakeNotification.setCreator(notification.getCreator()); fakeNotification.setStatus(notification.getStatus()); fakeNotification.setAction(notification.getAction()); fakeNotification.setNote(notification.getNote()); fakeNotification.setModifier(notification.getModifier()); fakeNotification.setModified(notification.getModified()); fakeNotification.setData(notification.getData()); fakeNotification.setType(notification.getType()); fakeNotification.setUser(notification.getUser()); publishNotificationEvent(httpSession, fakeNotification, false); throw new AcmUserActionFailedException("unable to add notification from ", notification.getUser(), notification.getId(), e.getMessage(), e); } } }
SaveNotificationAPIController { @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public Notification addNotification( @RequestBody Notification notification, HttpSession httpSession) throws AcmUserActionFailedException { if (log.isInfoEnabled()) { if (notification != null) { log.info("Notification ID : " + notification.getId()); } else { throw new AcmUserActionFailedException("addNote", NotificationConstants.OBJECT_TYPE, null, "Could not save note, missing parent type and ID", new NullPointerException()); } } try { Notification newNotification = new Notification(); newNotification.setId(notification.getId()); newNotification.setCreated(notification.getCreated()); newNotification.setCreator(notification.getCreator()); newNotification.setStatus(notification.getStatus()); newNotification.setAction(notification.getAction()); newNotification.setNote(notification.getNote()); newNotification.setModifier(notification.getModifier()); newNotification.setModified(notification.getModified()); newNotification.setData(notification.getData()); newNotification.setType(notification.getType()); newNotification.setUser(notification.getUser()); Notification savedNotification = getNotificationDao().save(notification); publishNotificationEvent(httpSession, savedNotification, true); return savedNotification; } catch (Exception e) { Notification fakeNotification = new Notification(); fakeNotification.setId(notification.getId()); log.info("fake id : " + fakeNotification.getId()); log.info("fake id 2: " + notification.getId()); fakeNotification.setId(notification.getId()); fakeNotification.setCreated(notification.getCreated()); fakeNotification.setCreator(notification.getCreator()); fakeNotification.setStatus(notification.getStatus()); fakeNotification.setAction(notification.getAction()); fakeNotification.setNote(notification.getNote()); fakeNotification.setModifier(notification.getModifier()); fakeNotification.setModified(notification.getModified()); fakeNotification.setData(notification.getData()); fakeNotification.setType(notification.getType()); fakeNotification.setUser(notification.getUser()); publishNotificationEvent(httpSession, fakeNotification, false); throw new AcmUserActionFailedException("unable to add notification from ", notification.getUser(), notification.getId(), e.getMessage(), e); } }  }
SaveNotificationAPIController { @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public Notification addNotification( @RequestBody Notification notification, HttpSession httpSession) throws AcmUserActionFailedException { if (log.isInfoEnabled()) { if (notification != null) { log.info("Notification ID : " + notification.getId()); } else { throw new AcmUserActionFailedException("addNote", NotificationConstants.OBJECT_TYPE, null, "Could not save note, missing parent type and ID", new NullPointerException()); } } try { Notification newNotification = new Notification(); newNotification.setId(notification.getId()); newNotification.setCreated(notification.getCreated()); newNotification.setCreator(notification.getCreator()); newNotification.setStatus(notification.getStatus()); newNotification.setAction(notification.getAction()); newNotification.setNote(notification.getNote()); newNotification.setModifier(notification.getModifier()); newNotification.setModified(notification.getModified()); newNotification.setData(notification.getData()); newNotification.setType(notification.getType()); newNotification.setUser(notification.getUser()); Notification savedNotification = getNotificationDao().save(notification); publishNotificationEvent(httpSession, savedNotification, true); return savedNotification; } catch (Exception e) { Notification fakeNotification = new Notification(); fakeNotification.setId(notification.getId()); log.info("fake id : " + fakeNotification.getId()); log.info("fake id 2: " + notification.getId()); fakeNotification.setId(notification.getId()); fakeNotification.setCreated(notification.getCreated()); fakeNotification.setCreator(notification.getCreator()); fakeNotification.setStatus(notification.getStatus()); fakeNotification.setAction(notification.getAction()); fakeNotification.setNote(notification.getNote()); fakeNotification.setModifier(notification.getModifier()); fakeNotification.setModified(notification.getModified()); fakeNotification.setData(notification.getData()); fakeNotification.setType(notification.getType()); fakeNotification.setUser(notification.getUser()); publishNotificationEvent(httpSession, fakeNotification, false); throw new AcmUserActionFailedException("unable to add notification from ", notification.getUser(), notification.getId(), e.getMessage(), e); } }  @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 { @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public Notification addNotification( @RequestBody Notification notification, HttpSession httpSession) throws AcmUserActionFailedException { if (log.isInfoEnabled()) { if (notification != null) { log.info("Notification ID : " + notification.getId()); } else { throw new AcmUserActionFailedException("addNote", NotificationConstants.OBJECT_TYPE, null, "Could not save note, missing parent type and ID", new NullPointerException()); } } try { Notification newNotification = new Notification(); newNotification.setId(notification.getId()); newNotification.setCreated(notification.getCreated()); newNotification.setCreator(notification.getCreator()); newNotification.setStatus(notification.getStatus()); newNotification.setAction(notification.getAction()); newNotification.setNote(notification.getNote()); newNotification.setModifier(notification.getModifier()); newNotification.setModified(notification.getModified()); newNotification.setData(notification.getData()); newNotification.setType(notification.getType()); newNotification.setUser(notification.getUser()); Notification savedNotification = getNotificationDao().save(notification); publishNotificationEvent(httpSession, savedNotification, true); return savedNotification; } catch (Exception e) { Notification fakeNotification = new Notification(); fakeNotification.setId(notification.getId()); log.info("fake id : " + fakeNotification.getId()); log.info("fake id 2: " + notification.getId()); fakeNotification.setId(notification.getId()); fakeNotification.setCreated(notification.getCreated()); fakeNotification.setCreator(notification.getCreator()); fakeNotification.setStatus(notification.getStatus()); fakeNotification.setAction(notification.getAction()); fakeNotification.setNote(notification.getNote()); fakeNotification.setModifier(notification.getModifier()); fakeNotification.setModified(notification.getModified()); fakeNotification.setData(notification.getData()); fakeNotification.setType(notification.getType()); fakeNotification.setUser(notification.getUser()); publishNotificationEvent(httpSession, fakeNotification, false); throw new AcmUserActionFailedException("unable to add notification from ", notification.getUser(), notification.getId(), e.getMessage(), e); } }  @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);  }