GH-2996: Add Resource for remote file transfer (#3231)
* GH-2996: Add Resource for remote file transfer Fixes https://github.com/spring-projects/spring-integration/issues/2996 * Fix `RemoteFileTemplate.send()` to support a `Resource` payload for remote file transferring content * Code style clean up for `RemoteFileTemplate` * Remove `volatile` for configuration properties for better performance * Change a `charset` to the `Charset` for only once conversion from string during configuration phase * Fix (S)FTP tests for new functionality * Change affected tests to JUnit 5 * Document a new feature; mention all the supported types and `FileExistsMode` constants * * Fix language in `whats-new.adoc`
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,14 +32,16 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.integration.file.remote.session.Session;
|
||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
@@ -61,13 +63,13 @@ public class RemoteFileTemplateTests {
|
||||
|
||||
private Session<Object> session;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
@TempDir
|
||||
Path folder;
|
||||
|
||||
private File file;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
SessionFactory<Object> sessionFactory = mock(SessionFactory.class);
|
||||
this.template = new RemoteFileTemplate<>(sessionFactory);
|
||||
@@ -76,7 +78,7 @@ public class RemoteFileTemplateTests {
|
||||
this.template.afterPropertiesSet();
|
||||
this.session = mock(Session.class);
|
||||
when(sessionFactory.getSession()).thenReturn(this.session);
|
||||
this.file = this.folder.newFile();
|
||||
this.file = Files.createTempFile(this.folder, null, null).toFile();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -146,6 +148,12 @@ public class RemoteFileTemplateTests {
|
||||
verify(this.session).write(any(InputStream.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResource() throws IOException {
|
||||
this.template.send(new GenericMessage<>(new ByteArrayResource("foo".getBytes())), FileExistsMode.IGNORE);
|
||||
verify(this.session).write(any(InputStream.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingFile() {
|
||||
this.template.send(new GenericMessage<>(new File(UUID.randomUUID().toString())), FileExistsMode.IGNORE);
|
||||
|
||||
Reference in New Issue
Block a user