use of org.springframework.integration.file.DefaultFileNameGenerator in project spring-integration by spring-projects.
the class FileTransferringMessageHandlerSpec method fileNameExpression.
/**
* Set the {@link DefaultFileNameGenerator} based on the provided SpEL expression.
* @param fileNameGeneratorExpression the SpEL expression for file names generation.
* @return the current Spec
*/
public S fileNameExpression(String fileNameGeneratorExpression) {
Assert.isNull(this.fileNameGenerator, "'fileNameGenerator' and 'fileNameGeneratorExpression' are mutually exclusive.");
this.defaultFileNameGenerator = new DefaultFileNameGenerator();
this.defaultFileNameGenerator.setExpression(fileNameGeneratorExpression);
return fileNameGenerator(this.defaultFileNameGenerator);
}
use of org.springframework.integration.file.DefaultFileNameGenerator in project spring-integration by spring-projects.
the class SftpOutboundTests method testHandleBytesMessage.
@Test
public void testHandleBytesMessage() throws Exception {
File file = new File("remote-target-dir", "foo.txt");
if (file.exists()) {
file.delete();
}
SessionFactory<LsEntry> sessionFactory = new TestSftpSessionFactory();
FileTransferringMessageHandler<LsEntry> handler = new FileTransferringMessageHandler<LsEntry>(sessionFactory);
DefaultFileNameGenerator fGenerator = new DefaultFileNameGenerator();
fGenerator.setBeanFactory(mock(BeanFactory.class));
fGenerator.setExpression("'foo.txt'");
handler.setFileNameGenerator(fGenerator);
handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
handler.handleMessage(new GenericMessage<byte[]>("byte[] data".getBytes()));
assertTrue(new File("remote-target-dir", "foo.txt").exists());
byte[] inFile = FileCopyUtils.copyToByteArray(file);
assertEquals("byte[] data", new String(inFile));
file.delete();
}
use of org.springframework.integration.file.DefaultFileNameGenerator in project spring-integration by spring-projects.
the class SftpOutboundTests method testHandleStringMessage.
@Test
public void testHandleStringMessage() throws Exception {
File file = new File("remote-target-dir", "foo.txt");
if (file.exists()) {
file.delete();
}
SessionFactory<LsEntry> sessionFactory = new TestSftpSessionFactory();
FileTransferringMessageHandler<LsEntry> handler = new FileTransferringMessageHandler<>(sessionFactory);
DefaultFileNameGenerator fGenerator = new DefaultFileNameGenerator();
fGenerator.setBeanFactory(mock(BeanFactory.class));
fGenerator.setExpression("'foo.txt'");
handler.setFileNameGenerator(fGenerator);
handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
handler.handleMessage(new GenericMessage<String>("String data"));
assertTrue(new File("remote-target-dir", "foo.txt").exists());
byte[] inFile = FileCopyUtils.copyToByteArray(file);
assertEquals("String data", new String(inFile));
file.delete();
}
use of org.springframework.integration.file.DefaultFileNameGenerator in project spring-integration by spring-projects.
the class FileTests method testFileHandler.
@Test
public void testFileHandler() throws Exception {
Message<?> message = MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, "foo").build();
try {
this.fileFlow1Input.send(message);
fail("NullPointerException expected");
} catch (Exception e) {
assertThat(e, instanceOf(MessageHandlingException.class));
assertThat(e.getCause(), instanceOf(NullPointerException.class));
}
DefaultFileNameGenerator fileNameGenerator = new DefaultFileNameGenerator();
fileNameGenerator.setBeanFactory(this.beanFactory);
Object targetFileWritingMessageHandler = this.fileWritingMessageHandler;
if (this.fileWritingMessageHandler instanceof Advised) {
TargetSource targetSource = ((Advised) this.fileWritingMessageHandler).getTargetSource();
if (targetSource != null) {
targetFileWritingMessageHandler = targetSource.getTarget();
}
}
DirectFieldAccessor dfa = new DirectFieldAccessor(targetFileWritingMessageHandler);
assertEquals(Boolean.FALSE, dfa.getPropertyValue("flushWhenIdle"));
assertEquals(60000L, dfa.getPropertyValue("flushInterval"));
dfa.setPropertyValue("fileNameGenerator", fileNameGenerator);
this.fileFlow1Input.send(message);
assertTrue(new File(tmpDir.getRoot(), "foo").exists());
this.fileTriggerFlowInput.send(new GenericMessage<>("trigger"));
assertTrue(this.flushPredicateCalled.await(10, TimeUnit.SECONDS));
}
use of org.springframework.integration.file.DefaultFileNameGenerator in project spring-integration by spring-projects.
the class FileOutboundGatewayParserTests method checkOrderedGateway.
@Test
public void checkOrderedGateway() throws Exception {
DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(ordered);
FileWritingMessageHandler handler = (FileWritingMessageHandler) gatewayAccessor.getPropertyValue("handler");
assertEquals(Boolean.FALSE, gatewayAccessor.getPropertyValue("autoStartup"));
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
assertEquals(777, handlerAccessor.getPropertyValue("order"));
assertEquals(Boolean.TRUE, handlerAccessor.getPropertyValue("requiresReply"));
DefaultFileNameGenerator fileNameGenerator = (DefaultFileNameGenerator) handlerAccessor.getPropertyValue("fileNameGenerator");
assertNotNull(fileNameGenerator);
Expression expression = TestUtils.getPropertyValue(fileNameGenerator, "expression", Expression.class);
assertNotNull(expression);
assertEquals("'foo.txt'", expression.getExpressionString());
Long sendTimeout = TestUtils.getPropertyValue(handler, "messagingTemplate.sendTimeout", Long.class);
assertEquals(Long.valueOf(777), sendTimeout);
}
Aggregations