Search in sources :

Example 6 with ApplicationEventListeningMessageProducer

use of org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer in project spring-integration by spring-projects.

the class TcpConnectionEventListenerTests method testNoFilter.

@Test
public void testNoFilter() {
    ApplicationEventListeningMessageProducer eventProducer = new ApplicationEventListeningMessageProducer();
    QueueChannel outputChannel = new QueueChannel();
    eventProducer.setOutputChannel(outputChannel);
    eventProducer.setEventTypes(TcpConnectionEvent.class);
    BeanFactory mock = mock(BeanFactory.class);
    given(mock.getBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class)).willReturn(mock(ApplicationEventMulticaster.class));
    eventProducer.setBeanFactory(mock);
    eventProducer.afterPropertiesSet();
    eventProducer.start();
    TcpConnectionSupport connection = Mockito.mock(TcpConnectionSupport.class);
    assertTrue(eventProducer.supportsEventType(ResolvableType.forClass(TcpConnectionOpenEvent.class)));
    TcpConnectionEvent event1 = new TcpConnectionOpenEvent(connection, "foo");
    eventProducer.onApplicationEvent(event1);
    assertTrue(eventProducer.supportsEventType(ResolvableType.forClass(FooEvent.class)));
    FooEvent event2 = new FooEvent(connection, "foo");
    eventProducer.onApplicationEvent(event2);
    assertTrue(eventProducer.supportsEventType(ResolvableType.forClass(BarEvent.class)));
    BarEvent event3 = new BarEvent(connection, "foo");
    eventProducer.onApplicationEvent(event3);
    Message<?> message = outputChannel.receive(0);
    assertNotNull(message);
    assertSame(event1, message.getPayload());
    message = outputChannel.receive(0);
    assertNotNull(message);
    assertSame(event2, message.getPayload());
    message = outputChannel.receive(0);
    assertNotNull(message);
    assertSame(event3, message.getPayload());
    message = outputChannel.receive(0);
    assertNull(message);
}
Also used : ApplicationEventMulticaster(org.springframework.context.event.ApplicationEventMulticaster) QueueChannel(org.springframework.integration.channel.QueueChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) ApplicationEventListeningMessageProducer(org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer) Test(org.junit.Test)

Example 7 with ApplicationEventListeningMessageProducer

use of org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer in project faf-java-server by FAForever.

the class IntegrationConfig method applicationEventListeningMessageProducer.

/**
 * Turns specific application events into messages.
 */
@Bean
public ApplicationEventListeningMessageProducer applicationEventListeningMessageProducer() {
    ApplicationEventListeningMessageProducer producer = new ApplicationEventListeningMessageProducer();
    producer.setEventTypes(ClientDisconnectedEvent.class);
    producer.setOutputChannelName(ChannelNames.INBOUND_DISPATCH);
    return producer;
}
Also used : ApplicationEventListeningMessageProducer(org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer) Bean(org.springframework.context.annotation.Bean)

Aggregations

ApplicationEventListeningMessageProducer (org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer)7 Test (org.junit.Test)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)4 Set (java.util.Set)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 ApplicationEventMulticaster (org.springframework.context.event.ApplicationEventMulticaster)2 ResolvableType (org.springframework.core.ResolvableType)2 QueueChannel (org.springframework.integration.channel.QueueChannel)2 Bean (org.springframework.context.annotation.Bean)1 Expression (org.springframework.expression.Expression)1