private void logComponentSubscriptionEvent(boolean add) { if (this.handler instanceof NamedComponent && this.inputChannel instanceof NamedComponent) { String channelName = ((NamedComponent) this.inputChannel).getComponentName(); String componentType = ((NamedComponent) this.handler).getComponentType(); componentType = StringUtils.hasText(componentType) ? componentType : ""; String componentName = getComponentName(); componentName = (StringUtils.hasText(componentName) && componentName.contains("#")) ? "" : ":" + componentName; StringBuffer buffer = new StringBuffer(); buffer.append("{" + componentType + componentName + "} as a subscriber to the '" + channelName + "' channel"); if (add) { buffer.insert(0, "Adding "); } else { buffer.insert(0, "Removing "); } logger.info(buffer.toString()); } } }
@Test @RedisAvailable public void validateConfiguration() { EventDrivenConsumer adapter = context.getBean("outboundAdapter", EventDrivenConsumer.class); Object handler = context.getBean("outboundAdapter.handler"); assertEquals("outboundAdapter", adapter.getComponentName()); DirectFieldAccessor accessor = new DirectFieldAccessor(handler); Object topicExpression = accessor.getPropertyValue("topicExpression"); assertNotNull(topicExpression); assertEquals("headers['topic'] ?: 'foo'", ((Expression) topicExpression).getExpressionString()); Object converterBean = context.getBean("testConverter"); assertEquals(converterBean, accessor.getPropertyValue("messageConverter")); assertEquals(context.getBean("serializer"), accessor.getPropertyValue("serializer")); Object endpointHandler = TestUtils.getPropertyValue(adapter, "handler"); assertTrue(AopUtils.isAopProxy(endpointHandler)); assertThat(TestUtils.getPropertyValue(endpointHandler, "h.advised.advisors[0].advice"), Matchers.instanceOf(RequestHandlerRetryAdvice.class)); }
@Test public void testOutboundChannelAdapterWithWithRemoteDirectoryAndFileExpression() { ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("OutboundChannelAdapterParserTests-context.xml", this.getClass()); Object consumer = context.getBean("sftpOutboundAdapterWithExpression"); assertTrue(consumer instanceof EventDrivenConsumer); assertEquals(context.getBean("inputChannel"), TestUtils.getPropertyValue(consumer, "inputChannel")); assertEquals("sftpOutboundAdapterWithExpression", ((EventDrivenConsumer) consumer).getComponentName()); FileTransferringMessageHandler<?> handler = TestUtils.getPropertyValue(consumer, "handler", FileTransferringMessageHandler.class); SpelExpression remoteDirectoryExpression = (SpelExpression) TestUtils.getPropertyValue(handler, "remoteFileTemplate.directoryExpressionProcessor.expression"); assertNotNull(remoteDirectoryExpression); assertEquals("'foo' + '/' + 'bar'", remoteDirectoryExpression.getExpressionString()); FileNameGenerator generator = (FileNameGenerator) TestUtils.getPropertyValue(handler, "remoteFileTemplate.fileNameGenerator"); Expression fileNameGeneratorExpression = TestUtils.getPropertyValue(generator, "expression", Expression.class); assertNotNull(fileNameGeneratorExpression); assertEquals("payload.getName() + '-foo'", fileNameGeneratorExpression.getExpressionString()); assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset")); assertNull(TestUtils.getPropertyValue(handler, "remoteFileTemplate.temporaryDirectoryExpressionProcessor")); context.close(); }
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);
private void logComponentSubscriptionEvent(boolean add) { if (this.handler instanceof NamedComponent && this.inputChannel instanceof NamedComponent) { String channelName = ((NamedComponent) this.inputChannel).getComponentName(); String componentType = ((NamedComponent) this.handler).getComponentType(); componentType = StringUtils.hasText(componentType) ? componentType : ""; String componentName = getComponentName(); componentName = (StringUtils.hasText(componentName) && componentName.contains("#")) ? "" : ":" + componentName; StringBuffer buffer = new StringBuffer(); buffer.append("{" + componentType + componentName + "} as a subscriber to the '" + channelName + "' channel"); if (add) { buffer.insert(0, "Adding "); } else { buffer.insert(0, "Removing "); } logger.info(buffer.toString()); } } }
@Test public void testFtpsOutboundChannelAdapterComplete() throws Exception { assertTrue(ftpOutbound instanceof EventDrivenConsumer); assertEquals(this.ftpChannel, TestUtils.getPropertyValue(ftpOutbound, "inputChannel")); assertEquals("ftpOutbound", ftpOutbound.getComponentName()); FileTransferringMessageHandler<?> handler = TestUtils.getPropertyValue(ftpOutbound, "handler", FileTransferringMessageHandler.class); assertEquals(this.fileNameGenerator, TestUtils.getPropertyValue(handler, "remoteFileTemplate.fileNameGenerator")); assertEquals("UTF-8", TestUtils.getPropertyValue(handler, "remoteFileTemplate.charset")); DefaultFtpsSessionFactory sf = TestUtils.getPropertyValue(handler, "remoteFileTemplate.sessionFactory", DefaultFtpsSessionFactory.class); assertEquals("localhost", TestUtils.getPropertyValue(sf, "host")); assertEquals(22, TestUtils.getPropertyValue(sf, "port")); }
@Test public void testFtpOutboundChannelAdapterComplete() throws Exception { assertEquals(ftpChannel, TestUtils.getPropertyValue(ftpOutbound, "inputChannel")); assertEquals("ftpOutbound", ftpOutbound.getComponentName()); FileTransferringMessageHandler<?> handler = TestUtils.getPropertyValue(ftpOutbound, "handler", FileTransferringMessageHandler.class);
@Test public void testSmbOutboundChannelAdapterComplete() { ApplicationContext ac = getApplicationContext(); Object consumer = ac.getBean("smbOutboundChannelAdapter"); assertTrue(consumer instanceof EventDrivenConsumer); PublishSubscribeChannel channel = ac.getBean("smbPubSubChannel", PublishSubscribeChannel.class); assertEquals(channel, TestUtils.getPropertyValue(consumer, "inputChannel")); assertEquals("smbOutboundChannelAdapter", ((EventDrivenConsumer) consumer).getComponentName()); Object messageHandler = TestUtils.getPropertyValue(consumer, "handler"); String remoteFileSeparator = (String) TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.remoteFileSeparator"); assertNotNull(remoteFileSeparator); assertEquals(".working.tmp", TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.temporaryFileSuffix", String.class)); assertEquals(".", remoteFileSeparator); assertEquals(ac.getBean("fileNameGenerator"), TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.fileNameGenerator")); assertEquals("UTF-8", TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.charset")); Object sessionFactoryProp = TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.sessionFactory"); assertEquals(SmbSessionFactory.class, sessionFactoryProp.getClass()); SmbSessionFactory smbSessionFactory = (SmbSessionFactory) sessionFactoryProp; assertEquals("localhost", TestUtils.getPropertyValue(smbSessionFactory, "host")); assertEquals(0, TestUtils.getPropertyValue(smbSessionFactory, "port")); assertEquals(23, TestUtils.getPropertyValue(messageHandler, "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(ac.getBean("smbOutboundChannelAdapter2"), "handler"), iterator.next()); assertSame(messageHandler, iterator.next()); }