Search in sources :

Example 16 with PublishSubscribeChannel

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

the class OutboundChannelAdapterParserTests method testOutboundChannelAdapterWithId.

@Test
public void testOutboundChannelAdapterWithId() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("OutboundChannelAdapterParserTests-context.xml", this.getClass());
    Object consumer = context.getBean("sftpOutboundAdapter");
    assertTrue(consumer instanceof EventDrivenConsumer);
    PublishSubscribeChannel channel = context.getBean("inputChannel", PublishSubscribeChannel.class);
    assertEquals(channel, TestUtils.getPropertyValue(consumer, "inputChannel"));
    assertEquals("sftpOutboundAdapter", ((EventDrivenConsumer) consumer).getComponentName());
    FileTransferringMessageHandler<?> handler = TestUtils.getPropertyValue(consumer, "handler", FileTransferringMessageHandler.class);
    String remoteFileSeparator = (String) TestUtils.getPropertyValue(handler, "remoteFileTemplate.remoteFileSeparator");
    assertNotNull(remoteFileSeparator);
    assertEquals(".", remoteFileSeparator);
    assertEquals(".bar", TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryFileSuffix", String.class));
    Expression remoteDirectoryExpression = (Expression) TestUtils.getPropertyValue(handler, "remoteFileTemplate.directoryExpressionProcessor.expression");
    assertNotNull(remoteDirectoryExpression);
    assertTrue(remoteDirectoryExpression instanceof LiteralExpression);
    assertNotNull(TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryDirectoryExpressionProcessor"));
    assertEquals(context.getBean("fileNameGenerator"), TestUtils.getPropertyValue(handler, "remoteFileTemplate.fileNameGenerator"));
    assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset"));
    CachingSessionFactory<?> sessionFactory = TestUtils.getPropertyValue(handler, "remoteFileTemplate.sessionFactory", CachingSessionFactory.class);
    DefaultSftpSessionFactory clientFactory = TestUtils.getPropertyValue(sessionFactory, "sessionFactory", DefaultSftpSessionFactory.class);
    assertEquals("localhost", TestUtils.getPropertyValue(clientFactory, "host"));
    assertEquals(2222, TestUtils.getPropertyValue(clientFactory, "port"));
    assertEquals(23, TestUtils.getPropertyValue(handler, "order"));
    // verify subscription order
    @SuppressWarnings("unchecked") Set<MessageHandler> handlers = (Set<MessageHandler>) TestUtils.getPropertyValue(TestUtils.getPropertyValue(channel, "dispatcher"), "handlers");
    Iterator<MessageHandler> iterator = handlers.iterator();
    assertSame(TestUtils.getPropertyValue(context.getBean("sftpOutboundAdapterWithExpression"), "handler"), iterator.next());
    assertSame(handler, iterator.next());
    assertEquals(384, TestUtils.getPropertyValue(handler, "chmod"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) Set(java.util.Set) PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) MessageHandler(org.springframework.messaging.MessageHandler) FileTransferringMessageHandler(org.springframework.integration.file.remote.handler.FileTransferringMessageHandler) LiteralExpression(org.springframework.expression.common.LiteralExpression) DefaultSftpSessionFactory(org.springframework.integration.sftp.session.DefaultSftpSessionFactory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) LiteralExpression(org.springframework.expression.common.LiteralExpression) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) Test(org.junit.Test)

Aggregations

PublishSubscribeChannel (org.springframework.integration.channel.PublishSubscribeChannel)16 Test (org.junit.Test)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)7 BroadcastingDispatcher (org.springframework.integration.dispatcher.BroadcastingDispatcher)6 DirectChannel (org.springframework.integration.channel.DirectChannel)5 Executor (java.util.concurrent.Executor)3 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)3 TestApplicationContext (org.springframework.integration.test.util.TestUtils.TestApplicationContext)3 ErrorHandlingTaskExecutor (org.springframework.integration.util.ErrorHandlingTaskExecutor)3 BeanFactory (org.springframework.beans.factory.BeanFactory)2 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)2 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 ErrorMessage (org.springframework.messaging.support.ErrorMessage)2 GenericMessage (org.springframework.messaging.support.GenericMessage)2 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1