INT-3746: Polishing
- move `InputStream` test later - add `name` for error messages - add test
This commit is contained in:
@@ -490,10 +490,7 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
|
||||
Object payload = message.getPayload();
|
||||
InputStream dataInputStream = null;
|
||||
String name = null;
|
||||
if (payload instanceof InputStream) {
|
||||
dataInputStream = (InputStream) payload;
|
||||
}
|
||||
else if (payload instanceof File) {
|
||||
if (payload instanceof File) {
|
||||
File inputFile = (File) payload;
|
||||
if (inputFile.exists()) {
|
||||
dataInputStream = new BufferedInputStream(new FileInputStream(inputFile));
|
||||
@@ -512,9 +509,13 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
|
||||
}
|
||||
dataInputStream = new ByteArrayInputStream(bytes);
|
||||
}
|
||||
else if (payload instanceof InputStream) {
|
||||
dataInputStream = (InputStream) payload;
|
||||
name = "InputStream payload";
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unsupported payload type. The only supported payloads are " +
|
||||
"java.io.File, java.lang.String, byte[] and InputStream");
|
||||
"java.io.File, java.lang.String, byte[], and InputStream");
|
||||
}
|
||||
if (dataInputStream == null) {
|
||||
return null;
|
||||
|
||||
@@ -25,13 +25,16 @@ import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
@@ -119,4 +122,12 @@ public class RemoteFileTemplateTests {
|
||||
verify(this.session).write(any(InputStream.class), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStream() throws IOException {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream("foo".getBytes());
|
||||
this.template.send(new GenericMessage<InputStream>(stream),
|
||||
FileExistsMode.IGNORE);
|
||||
verify(this.session).write(Mockito.eq(stream), Mockito.any());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user