Search in sources :

Example 16 with BeanFactoryChannelResolver

use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.

the class ChannelAdapterParserTests method expressionConsumer.

@Test
public /**
 * @since 2.1
 */
void expressionConsumer() {
    String beanName = "expressionConsumer";
    Object channel = this.applicationContext.getBean(beanName);
    assertTrue(channel instanceof DirectChannel);
    BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(this.applicationContext);
    assertNotNull(channelResolver.resolveDestination(beanName));
    Object adapter = this.applicationContext.getBean(beanName + ".adapter");
    assertNotNull(adapter);
    assertTrue(adapter instanceof EventDrivenConsumer);
    TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
    assertNull(testBean.getMessage());
    Message<?> message = new GenericMessage<String>("consumer test expression");
    assertTrue(((MessageChannel) channel).send(message));
    assertNotNull(testBean.getMessage());
    assertEquals("consumer test expression", testBean.getMessage());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) Test(org.junit.Test)

Example 17 with BeanFactoryChannelResolver

use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.

the class ChannelAdapterParserTests method methodInvokingSourceAdapterIsNotChannel.

@Test(expected = DestinationResolutionException.class)
public void methodInvokingSourceAdapterIsNotChannel() {
    BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(this.applicationContext);
    channelResolver.resolveDestination("methodInvokingSource");
}
Also used : BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) Test(org.junit.Test)

Example 18 with BeanFactoryChannelResolver

use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.

the class HeaderChannelRegistryTests method testBFCRNoRegistry.

@Test
public void testBFCRNoRegistry() {
    BeanFactoryChannelResolver resolver = new BeanFactoryChannelResolver();
    BeanFactory beanFactory = mock(BeanFactory.class);
    doAnswer(invocation -> {
        throw new NoSuchBeanDefinitionException("bar");
    }).when(beanFactory).getBean("foo", MessageChannel.class);
    resolver.setBeanFactory(beanFactory);
    try {
        resolver.resolveDestination("foo");
        fail("Expected exception");
    } catch (DestinationResolutionException e) {
        assertThat(e.getMessage(), Matchers.containsString("failed to look up MessageChannel with name 'foo' in the BeanFactory " + "(and there is no HeaderChannelRegistry present)."));
    }
}
Also used : DestinationResolutionException(org.springframework.messaging.core.DestinationResolutionException) BeanFactory(org.springframework.beans.factory.BeanFactory) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 19 with BeanFactoryChannelResolver

use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.

the class HeaderChannelRegistryTests method testBFCRWithRegistry.

@Test
public void testBFCRWithRegistry() {
    BeanFactoryChannelResolver resolver = new BeanFactoryChannelResolver();
    BeanFactory beanFactory = mock(BeanFactory.class);
    when(beanFactory.getBean(IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME, HeaderChannelRegistry.class)).thenReturn(mock(HeaderChannelRegistry.class));
    doAnswer(invocation -> {
        throw new NoSuchBeanDefinitionException("bar");
    }).when(beanFactory).getBean("foo", MessageChannel.class);
    resolver.setBeanFactory(beanFactory);
    try {
        resolver.resolveDestination("foo");
        fail("Expected exception");
    } catch (DestinationResolutionException e) {
        assertThat(e.getMessage(), Matchers.containsString("failed to look up MessageChannel with name 'foo' in the BeanFactory."));
    }
}
Also used : DestinationResolutionException(org.springframework.messaging.core.DestinationResolutionException) BeanFactory(org.springframework.beans.factory.BeanFactory) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) HeaderChannelRegistry(org.springframework.integration.support.channel.HeaderChannelRegistry) DefaultHeaderChannelRegistry(org.springframework.integration.channel.DefaultHeaderChannelRegistry) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 20 with BeanFactoryChannelResolver

use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.

the class MessageBusParserTests method testDefaultErrorChannel.

@Test
public void testDefaultErrorChannel() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("messageBusWithDefaults.xml", this.getClass());
    BeanFactoryChannelResolver resolver = new BeanFactoryChannelResolver(context);
    assertEquals(context.getBean("errorChannel"), resolver.resolveDestination("errorChannel"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) Test(org.junit.Test)

Aggregations

BeanFactoryChannelResolver (org.springframework.integration.support.channel.BeanFactoryChannelResolver)25 Test (org.junit.Test)11 MessageChannel (org.springframework.messaging.MessageChannel)7 ErrorHandlingTaskExecutor (org.springframework.integration.util.ErrorHandlingTaskExecutor)6 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)5 MessagePublishingErrorHandler (org.springframework.integration.channel.MessagePublishingErrorHandler)5 GenericMessage (org.springframework.messaging.support.GenericMessage)5 DirectChannel (org.springframework.integration.channel.DirectChannel)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 BeanFactory (org.springframework.beans.factory.BeanFactory)3 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)3 DestinationResolutionException (org.springframework.messaging.core.DestinationResolutionException)3 Date (java.util.Date)2 MimeMessage (javax.mail.internet.MimeMessage)2 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 SimpleAsyncTaskExecutor (org.springframework.core.task.SimpleAsyncTaskExecutor)2 Message (org.springframework.messaging.Message)2 MessagingException (org.springframework.messaging.MessagingException)2 PollableChannel (org.springframework.messaging.PollableChannel)2