@Before public void before() { when(muleContext.getNotificationManager()).thenReturn(eventNotificationHandler); when(event.getMessage()).thenReturn(message); initMocks(eventNotificationHandler); helper = new NotificationHelper(eventNotificationHandler, TestServerNotification.class, false); }
@Test public void fireNotificationForEvent() { when(messageSource.getLocation()).thenReturn(TEST_CONNECTOR_LOCATION); final FlowConstruct flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class)); when(flowConstruct.getMuleContext()).thenReturn(muleContext); final int action = 100; helper.fireNotification(messageSource, event, TEST_CONNECTOR_LOCATION, action); assertConnectorMessageNotification(eventNotificationHandler, messageSource, TEST_CONNECTOR_LOCATION, action); }
/** * Creates a new {@link NotificationHelper} that emits instances of {@code notificationClass} class. * * @param defaultNotificationHandler The {@link ServerNotificationHandler} to be used on notifications which don't relate to a * {@link CoreEvent} * @param notificationClass The {@link Class} of the notifications to be fired by this helper * @param dynamicNotifications If {@code true}, notifications will be fired directly to a {@link ServerNotificationHandler} * responsible to decide to emit it or not. If {@code false} the notification will be checked to be enable or not at * creation time */ public NotificationHelper(ServerNotificationHandler defaultNotificationHandler, Class<? extends Notification> notificationClass, boolean dynamicNotifications) { this.notificationClass = notificationClass; this.dynamicNotifications = dynamicNotifications; this.defaultNotificationHandler = adaptNotificationHandler(defaultNotificationHandler); }
@Test public void isNotificationEnabledForEvent() { assertThat(helper.isNotificationEnabled(), is(true)); verify(eventNotificationHandler).isNotificationEnabled(TestServerNotification.class); }
@Test public void isNotificationEnabled() { assertThat(helper.isNotificationEnabled(), is(true)); verify(eventNotificationHandler).isNotificationEnabled(TestServerNotification.class); }
@Test public void fireSpecificNotificationForEvent() { TestServerNotification notification = new TestServerNotification(); helper.fireNotification(notification); verify(eventNotificationHandler).fireNotification(notification); }
/** * @param muleContext application's context * @param scheduler the scheduler */ public DefaultSchedulerMessageSource(MuleContext muleContext, PeriodicScheduler scheduler, boolean disallowConcurrentExecution) { this.muleContext = muleContext; this.scheduler = scheduler; this.disallowConcurrentExecution = disallowConcurrentExecution; this.notificationHelper = new NotificationHelper(muleContext.getNotificationManager(), ConnectorMessageNotification.class, false); }
@Test public void isNotificationEnabled() { assertThat(helper.isNotificationEnabled(), is(true)); verify(eventNotificationHandler).isNotificationEnabled(TestServerNotification.class); }
@Test public void fireSpecificNotificationOnDefaultHandler() { TestServerNotification notification = new TestServerNotification(); helper.fireNotification(notification); verify(eventNotificationHandler).fireNotification(notification); }
@Inject public void setMuleContext(MuleContext context) { this.muleContext = context; this.notificationHelper = new NotificationHelper(muleContext.getNotificationManager(), ConnectorMessageNotification.class, false); } }
@Test public void isNotificationEnabledForEvent() { assertThat(helper.isNotificationEnabled(), is(true)); verify(eventNotificationHandler).isNotificationEnabled(TestServerNotification.class); }
@Test public void fireNotificationUsingLocation() { final LocationPart flowPart = mock(LocationPart.class); when(flowPart.getPartPath()).thenReturn("flowName"); final ComponentLocation location = mock(ComponentLocation.class); when(location.getParts()).thenReturn(Collections.singletonList(flowPart)); when(location.getComponentIdentifier()).thenReturn(TypedComponentIdentifier.builder() .type(SOURCE) .identifier(buildFromStringRepresentation("http:listener")) .build()); when(messageSource.getLocation()).thenReturn(location); final FlowConstruct flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class)); when(flowConstruct.getMuleContext()).thenReturn(muleContext); final int action = 100; helper.fireNotification(messageSource, event, location, action); assertConnectorMessageNotification(eventNotificationHandler, messageSource, location, action); }
@Before public void before() { when(muleContext.getNotificationManager()).thenReturn(eventNotificationHandler); when(event.getMessage()).thenReturn(message); when(message.getPayload()).thenReturn(new TypedValue("", DataType.STRING)); initMocks(eventNotificationHandler); helper = new NotificationHelper(eventNotificationHandler, TestServerNotification.class, false); }
protected void fireNotification(Component source, CoreEvent event, FlowConstruct flow, int action) { try { if (event == null) { // Null result only happens when there's a filter in the chain. // Unfortunately a filter causes the whole chain to return null // and there's no other way to retrieve the last event but using the RequestContext. // see https://www.mulesoft.org/jira/browse/MULE-8670 event = getCurrentEvent(); if (event == null) { return; } } notificationHelper.fireNotification(source, event, ((Component) flow).getLocation(), action); } catch (Exception e) { logger.warn("Could not fire notification. Action: " + action, e); } }
@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 fireNotificationForEvent() { when(messageSource.getLocation()).thenReturn(TEST_CONNECTOR_LOCATION); final FlowConstruct flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class)); when(flowConstruct.getMuleContext()).thenReturn(muleContext); final int action = 100; helper.fireNotification(messageSource, event, TEST_CONNECTOR_LOCATION, action); assertConnectorMessageNotification(eventNotificationHandler, messageSource, TEST_CONNECTOR_LOCATION, action); }
@Test public void fireNotificationUsingLocation() { final LocationPart flowPart = mock(LocationPart.class); when(flowPart.getPartPath()).thenReturn("flowName"); final ComponentLocation location = mock(ComponentLocation.class); when(location.getParts()).thenReturn(Collections.singletonList(flowPart)); when(location.getComponentIdentifier()).thenReturn(TypedComponentIdentifier.builder() .type(SOURCE) .identifier(buildFromStringRepresentation("http:listener")) .build()); when(messageSource.getLocation()).thenReturn(location); final FlowConstruct flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class)); when(flowConstruct.getMuleContext()).thenReturn(muleContext); final int action = 100; helper.fireNotification(messageSource, event, location, action); assertConnectorMessageNotification(eventNotificationHandler, messageSource, location, action); }
private void pollWith(final Message request) { try { just(request) .map(message -> InternalEvent.builder(create(flowConstruct, getLocation())).message(request) .build()) .doOnNext(event -> setCurrentEvent(event)) .doOnNext(event -> notificationHelper.fireNotification(this, event, getLocation(), MESSAGE_RECEIVED)) .cast(CoreEvent.class) .transform(listener) .doOnError(MessagingException.class, me -> ((BaseEventContext) me.getEvent().getContext()).error(me)) .doOnSuccess(result -> ((BaseEventContext) result.getContext()).success()) .doFinally(s -> { synchronized (DefaultSchedulerMessageSource.this) { executing = false; } }) .subscribe(requestUnbounded()); } catch (Exception e) { muleContext.getExceptionListener().handleException(e); } }