@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 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 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); }
@Before public void setUpListeners() { listener1 = new Listener1(); listener2 = new Listener2(); manager = new ServerNotificationManager(); }
@Override protected ServerNotificationManager createNotificationManager() { ServerNotificationManager manager = new ServerNotificationManager(); manager.addInterfaceToType(MuleContextNotificationListener.class, MuleContextNotification.class); manager.addInterfaceToType(SecurityNotificationListener.class, SecurityNotification.class); manager.addInterfaceToType(ManagementNotificationListener.class, ManagementNotification.class); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); manager.addInterfaceToType(ConnectionNotificationListener.class, ConnectionNotification.class); manager.addInterfaceToType(ExceptionNotificationListener.class, ExceptionNotification.class); manager.addInterfaceToType(ClusterNodeNotificationListener.class, ClusterNodeNotification.class); manager.addInterfaceToType(ExceptionNotificationListener.class, ExtensionNotification.class); return manager; } }
@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); }
@Before public void setUpListeners() { listener1 = new Listener1(); listener2 = new Listener2(); manager = new ServerNotificationManager(); }
@Override protected ServerNotificationManager createNotificationManager() { ServerNotificationManager manager = new ServerNotificationManager(); manager.addInterfaceToType(MuleContextNotificationListener.class, MuleContextNotification.class); manager.addInterfaceToType(SecurityNotificationListener.class, SecurityNotification.class); manager.addInterfaceToType(ManagementNotificationListener.class, ManagementNotification.class); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); manager.addInterfaceToType(ConnectionNotificationListener.class, ConnectionNotification.class); manager.addInterfaceToType(ExceptionNotificationListener.class, ExceptionNotification.class); manager.addInterfaceToType(ClusterNodeNotificationListener.class, ClusterNodeNotification.class); manager.addInterfaceToType(ExceptionNotificationListener.class, ExtensionNotification.class); return manager; } }
/** * @return a {@link ServerNotificationManager} with the default configuration for Mule notifications */ public static ServerNotificationManager createDefaultNotificationManager() { ServerNotificationManager manager = new ServerNotificationManager(); manager.addInterfaceToType(MuleContextNotificationListener.class, MuleContextNotification.class); manager.addInterfaceToType(RoutingNotificationListener.class, RoutingNotification.class); manager.addInterfaceToType(SecurityNotificationListener.class, SecurityNotification.class); manager.addInterfaceToType(ManagementNotificationListener.class, ManagementNotification.class); manager.addInterfaceToType(CustomNotificationListener.class, CustomNotification.class); manager.addInterfaceToType(ConnectionNotificationListener.class, ConnectionNotification.class); manager.addInterfaceToType(ExceptionNotificationListener.class, ExceptionNotification.class); manager.addInterfaceToType(ErrorHandlerNotificationListener.class, ErrorHandlerNotification.class); manager.addInterfaceToType(TransactionNotificationListener.class, TransactionNotification.class); manager.addInterfaceToType(PipelineMessageNotificationListener.class, PipelineMessageNotification.class); manager.addInterfaceToType(AsyncMessageNotificationListener.class, AsyncMessageNotification.class); manager.addInterfaceToType(ClusterNodeNotificationListener.class, ClusterNodeNotification.class); manager.addInterfaceToType(ConnectorMessageNotificationListener.class, ConnectorMessageNotification.class); manager.addInterfaceToType(ErrorHandlerNotificationListener.class, ErrorHandlerNotification.class); manager.addInterfaceToType(FlowConstructNotificationListener.class, FlowConstructNotification.class); manager.addInterfaceToType(ExtensionNotificationListener.class, ExtensionNotification.class); return manager; } }