Search in sources :

Example 1 with ApplicationEventListeningMessageProducer

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

the class EventInboundChannelAdapterParserTests method validateEventParser.

@Test
public void validateEventParser() {
    Object adapter = context.getBean("eventAdapterSimple");
    Assert.assertNotNull(adapter);
    Assert.assertTrue(adapter instanceof ApplicationEventListeningMessageProducer);
    DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
    Assert.assertEquals(context.getBean("input"), adapterAccessor.getPropertyValue("outputChannel"));
    Assert.assertSame(errorChannel, adapterAccessor.getPropertyValue("errorChannel"));
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ApplicationEventListeningMessageProducer(org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer) Test(org.junit.Test)

Example 2 with ApplicationEventListeningMessageProducer

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

the class EventInboundChannelAdapterParserTests method validateEventParserWithEventTypes.

@Test
@SuppressWarnings("unchecked")
public void validateEventParserWithEventTypes() {
    Object adapter = context.getBean("eventAdapterFiltered");
    Assert.assertNotNull(adapter);
    Assert.assertTrue(adapter instanceof ApplicationEventListeningMessageProducer);
    DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
    Assert.assertEquals(context.getBean("inputFiltered"), adapterAccessor.getPropertyValue("outputChannel"));
    Set<ResolvableType> eventTypes = (Set<ResolvableType>) adapterAccessor.getPropertyValue("eventTypes");
    assertNotNull(eventTypes);
    assertTrue(eventTypes.size() == 3);
    assertTrue(eventTypes.contains(ResolvableType.forClass(SampleEvent.class)));
    assertTrue(eventTypes.contains(ResolvableType.forClass(AnotherSampleEvent.class)));
    assertTrue(eventTypes.contains(ResolvableType.forClass(Date.class)));
    assertNull(adapterAccessor.getPropertyValue("errorChannel"));
}
Also used : Set(java.util.Set) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ResolvableType(org.springframework.core.ResolvableType) ApplicationEventListeningMessageProducer(org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer) Test(org.junit.Test)

Example 3 with ApplicationEventListeningMessageProducer

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

the class EventInboundChannelAdapterParserTests method validatePayloadExpression.

@Test
public void validatePayloadExpression() {
    Object adapter = context.getBean("eventAdapterSpel");
    Assert.assertNotNull(adapter);
    Assert.assertTrue(adapter instanceof ApplicationEventListeningMessageProducer);
    DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
    Expression expression = (Expression) adapterAccessor.getPropertyValue("payloadExpression");
    Assert.assertEquals("source + '-test'", expression.getExpressionString());
}
Also used : Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ApplicationEventListeningMessageProducer(org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer) Test(org.junit.Test)

Example 4 with ApplicationEventListeningMessageProducer

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

the class TcpConnectionEventListenerTests method testFilter.

@Test
public void testFilter() {
    ApplicationEventListeningMessageProducer eventProducer = new ApplicationEventListeningMessageProducer();
    QueueChannel outputChannel = new QueueChannel();
    eventProducer.setOutputChannel(outputChannel);
    eventProducer.setEventTypes(FooEvent.class, BarEvent.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);
    assertFalse(eventProducer.supportsEventType(ResolvableType.forClass(TcpConnectionOpenEvent.class)));
    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(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 5 with ApplicationEventListeningMessageProducer

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

the class EventInboundChannelAdapterParserTests method validateEventParserWithEventTypesAndPlaceholder.

@Test
@SuppressWarnings("unchecked")
public void validateEventParserWithEventTypesAndPlaceholder() {
    Object adapter = context.getBean("eventAdapterFilteredPlaceHolder");
    Assert.assertNotNull(adapter);
    Assert.assertTrue(adapter instanceof ApplicationEventListeningMessageProducer);
    DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
    Assert.assertEquals(context.getBean("inputFilteredPlaceHolder"), adapterAccessor.getPropertyValue("outputChannel"));
    Set<ResolvableType> eventTypes = (Set<ResolvableType>) adapterAccessor.getPropertyValue("eventTypes");
    assertNotNull(eventTypes);
    assertTrue(eventTypes.size() == 2);
    assertTrue(eventTypes.contains(ResolvableType.forClass(SampleEvent.class)));
    assertTrue(eventTypes.contains(ResolvableType.forClass(AnotherSampleEvent.class)));
}
Also used : Set(java.util.Set) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ResolvableType(org.springframework.core.ResolvableType) ApplicationEventListeningMessageProducer(org.springframework.integration.event.inbound.ApplicationEventListeningMessageProducer) Test(org.junit.Test)

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