@Override public void fire(NotificationActionDefinition action, TypedValue<?> data) { validateAction((Enum) action); notificationManager.fireNotification(new DefaultExtensionNotification(event, component, action, data)); }
@Override public void fireLazy(NotificationActionDefinition action, Supplier<?> data, DataType actualDataType) { validateAction((Enum) action); notificationManager.fireNotification(new DefaultExtensionNotification(event, component, action, data, actualDataType)); }
@Test public void responseNotificationFired() throws MuleException { when(mockContext.supportsAsynchronousProcessing()).thenReturn(false); when(mockRequestResponseTemplate.afterRouteEvent(any(CoreEvent.class))) .thenAnswer(invocation -> invocation.getArgument(0)); phase.runPhase(mockRequestResponseTemplate, mockContext, mockNotifier); ArgumentCaptor<ConnectorMessageNotification> notificationCaptor = ArgumentCaptor.forClass(ConnectorMessageNotification.class); verify(notificationManager).fireNotification(notificationCaptor.capture()); assertThat(notificationCaptor.getAllValues(), hasSize(1)); assertThat(notificationCaptor.getValue().getAction().getActionId(), is(MESSAGE_RESPONSE)); }
@Test public void errorResponseNotificationFired() throws Exception { when(mockContext.supportsAsynchronousProcessing()).thenReturn(false); when(mockRequestResponseTemplate.afterRouteEvent(any(CoreEvent.class))).thenThrow(mockMessagingException); phase.runPhase(mockRequestResponseTemplate, mockContext, mockNotifier); ArgumentCaptor<ConnectorMessageNotification> notificationCaptor = ArgumentCaptor.forClass(ConnectorMessageNotification.class); verify(notificationManager).fireNotification(notificationCaptor.capture()); assertThat(notificationCaptor.getAllValues(), hasSize(1)); assertThat(notificationCaptor.getValue().getAction().getActionId(), is(MESSAGE_ERROR_RESPONSE)); }
@Test public void fireSpecificNotificationForEvent() { TestServerNotification notification = new TestServerNotification(); helper.fireNotification(notification); verify(eventNotificationHandler).fireNotification(notification); }
@Test public void fireSpecificNotificationOnDefaultHandler() { TestServerNotification notification = new TestServerNotification(); helper.fireNotification(notification); verify(eventNotificationHandler).fireNotification(notification); }
@Test public void testSyncNotificationException() { ServerNotificationManager manager = new ServerNotificationManager(); manager.setMuleContext(muleContext); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); Notification notification = mock(CustomNotification.class); when(notification.isSynchronous()).thenReturn(true); NotificationListener notificationListener = mock(CustomNotificationListener.class); doThrow(new IllegalArgumentException()).when(notificationListener).onNotification(any(CustomNotification.class)); manager.addListener(notificationListener); manager.fireNotification(notification); verify(notificationListener, times(1)).onNotification(notification); }
@Test public void testSyncNotificationError() { ServerNotificationManager manager = new ServerNotificationManager(); manager.setMuleContext(muleContext); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); Notification notification = mock(CustomNotification.class); when(notification.isSynchronous()).thenReturn(true); NotificationListener notificationListener = mock(CustomNotificationListener.class); doThrow(new LinkageError()).when(notificationListener).onNotification(any(CustomNotification.class)); manager.addListener(notificationListener); manager.fireNotification(notification); verify(notificationListener, times(1)).onNotification(notification); }
@Test public void testAsyncNotificationRejectedExecution() { MuleContext muleContext = mock(MuleContext.class); SchedulerService schedulerService = mock(SchedulerService.class); Scheduler scheduler = mock(Scheduler.class); when(muleContext.getSchedulerService()).thenReturn(schedulerService); when(schedulerService.cpuLightScheduler()).thenReturn(scheduler); when(scheduler.submit(any(Callable.class))).thenThrow(new RejectedExecutionException()); Notification notification = mock(CustomNotification.class); when(notification.isSynchronous()).thenReturn(false); NotificationListener notificationListener = mock(CustomNotificationListener.class); ServerNotificationManager manager = new ServerNotificationManager(); manager.setMuleContext(muleContext); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); manager.addListener(notificationListener); manager.fireNotification(notification); verify(notificationListener, never()).onNotification(notification); }
@Test public void startWhenPrimaryNode() throws Exception { dontStartIfNotPrimaryNode(); muleContext.getNotificationManager() .fireNotification(new ClusterNodeNotification("you're up", PRIMARY_CLUSTER_NODE_SELECTED)); verify(sourceAdapter, atLeastOnce()).initialise(); verify(sourceAdapter, times(1)).start(); } }
@Override public void dispatch(Notification notification) { ServerNotificationManager notificationManager = context.getNotificationManager(); if (notificationManager != null) { notificationManager.fireNotification(notification); } else if (LOGGER.isDebugEnabled()) { LOGGER.debug("MuleEvent Manager is not enabled, ignoring notification: " + notification); } }
@Override public void fire(NotificationActionDefinition action, TypedValue<?> data) { validateAction((Enum) action); notificationManager.fireNotification(new DefaultExtensionNotification(event, component, action, data)); }
private void fireNotification(ServerNotificationManager serverNotificationManager, CoreEvent event, Processor processor, MessagingException exceptionThrown, int action) { if (serverNotificationManager != null && serverNotificationManager.isNotificationEnabled(MessageProcessorNotification.class)) { if (((Component) processor).getLocation() != null) { serverNotificationManager .fireNotification(createFrom(event, ((Component) processor).getLocation(), (Component) processor, exceptionThrown, action)); } } }
private void fireAsyncCompleteNotification(CoreEvent event, MessagingException exception) { muleContext.getNotificationManager() .fireNotification(new AsyncMessageNotification(createInfo(event, exception, this), getLocation(), PROCESS_ASYNC_COMPLETE)); }
private Consumer<CoreEvent> onMessageReceived(ModuleFlowProcessingPhaseTemplate template, MessageProcessContext messageProcessContext, FlowConstruct flowConstruct) { return request -> { fireNotification(messageProcessContext.getMessageSource(), request, flowConstruct, MESSAGE_RECEIVED); template.getNotificationFunctions().forEach(notificationFunction -> muleContext.getNotificationManager() .fireNotification(notificationFunction.apply(request, messageProcessContext.getMessageSource()))); }; }
@Test public void errorResponseNotificationFired() throws Exception { when(mockContext.supportsAsynchronousProcessing()).thenReturn(false); when(mockRequestResponseTemplate.afterRouteEvent(any(CoreEvent.class))).thenThrow(mockMessagingException); when(mockMessagingException.handled()).thenReturn(false); phase.runPhase(mockRequestResponseTemplate, mockContext, mockNotifier); ArgumentCaptor<ConnectorMessageNotification> notificationCaptor = ArgumentCaptor.forClass(ConnectorMessageNotification.class); verify(notificationManager).fireNotification(notificationCaptor.capture()); assertThat(notificationCaptor.getAllValues(), hasSize(1)); assertThat(notificationCaptor.getValue().getAction().getActionId(), is(MESSAGE_ERROR_RESPONSE)); }
@Test public void testSyncNotificationException() { ServerNotificationManager manager = new ServerNotificationManager(); manager.setMuleContext(muleContext); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); Notification notification = mock(CustomNotification.class); when(notification.isSynchronous()).thenReturn(true); NotificationListener notificationListener = mock(CustomNotificationListener.class); doThrow(new IllegalArgumentException()).when(notificationListener).onNotification(any(CustomNotification.class)); manager.addListener(notificationListener); manager.fireNotification(notification); verify(notificationListener, times(1)).onNotification(notification); }
@Test public void responseNotificationFired() throws MuleException { when(mockContext.supportsAsynchronousProcessing()).thenReturn(false); when(mockRequestResponseTemplate.afterRouteEvent(any(CoreEvent.class))) .thenAnswer(invocation -> invocation.getArgumentAt(0, CoreEvent.class)); phase.runPhase(mockRequestResponseTemplate, mockContext, mockNotifier); ArgumentCaptor<ConnectorMessageNotification> notificationCaptor = ArgumentCaptor.forClass(ConnectorMessageNotification.class); verify(notificationManager).fireNotification(notificationCaptor.capture()); assertThat(notificationCaptor.getAllValues(), hasSize(1)); assertThat(notificationCaptor.getValue().getAction().getActionId(), is(MESSAGE_RESPONSE)); }
@Test public void fireSpecificNotificationForEvent() { TestServerNotification notification = new TestServerNotification(); helper.fireNotification(notification); verify(eventNotificationHandler).fireNotification(notification); }
@Test public void fireSpecificNotificationOnDefaultHandler() { TestServerNotification notification = new TestServerNotification(); helper.fireNotification(notification); verify(eventNotificationHandler).fireNotification(notification); }