Search in sources :

Example 1 with FileNameGenerator

use of org.springframework.integration.file.FileNameGenerator in project spring-integration by spring-projects.

the class OutboundChannelAdapterParserTests method testOutboundChannelAdapterWithWithRemoteDirectoryAndFileExpression.

@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();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) LiteralExpression(org.springframework.expression.common.LiteralExpression) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) FileNameGenerator(org.springframework.integration.file.FileNameGenerator) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 Expression (org.springframework.expression.Expression)1 LiteralExpression (org.springframework.expression.common.LiteralExpression)1 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)1 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)1 FileNameGenerator (org.springframework.integration.file.FileNameGenerator)1