INT-4141: (S)FTP Streaming - throw Exception

JIRA: https://jira.spring.io/browse/INT-4141

MessageSource incorrectly returned the exception instead of throwing it.

(cherry picked from commit 0c1a765)
This commit is contained in:
Gary Russell
2016-10-18 15:29:59 -04:00
committed by Artem Bilan
parent 211647d6fe
commit 9b713762e2
2 changed files with 23 additions and 1 deletions

View File

@@ -141,7 +141,7 @@ public abstract class AbstractRemoteFileStreamingMessageSource<F> extends Abstra
.build();
}
catch (IOException e) {
return new MessagingException("IOException when retrieving " + remotePath, e);
throw new MessagingException("IOException when retrieving " + remotePath, e);
}
}
return null;

View File

@@ -20,17 +20,21 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.IntegrationMessageHeaderAccessor;
@@ -41,6 +45,7 @@ import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.integration.file.splitter.FileSplitter;
import org.springframework.integration.transformer.StreamTransformer;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
/**
* @author Gary Russell
@@ -49,6 +54,9 @@ import org.springframework.messaging.Message;
*/
public class StreamingInboundTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private final StreamTransformer transformer = new StreamTransformer();
@SuppressWarnings("unchecked")
@@ -73,6 +81,17 @@ public class StreamingInboundTests {
verify(new IntegrationMessageHeaderAccessor(received).getCloseableResource()).close();
}
@Test
public void testExceptionOnFetch() {
exception.expect(MessagingException.class);
StringSessionFactory sessionFactory = new StringSessionFactory();
Streamer streamer = new Streamer(new StringRemoteFileTemplate(sessionFactory), null);
streamer.setBeanFactory(mock(BeanFactory.class));
streamer.setRemoteDirectory("/bad");
streamer.afterPropertiesSet();
streamer.receive();
}
@SuppressWarnings("unchecked")
@Test
public void testLineByLine() throws Exception {
@@ -208,6 +227,9 @@ public class StreamingInboundTests {
willReturn(foo2).given(session).readRaw("/bar/foo");
willReturn(bar2).given(session).readRaw("/bar/bar");
willReturn(new String[] { "/bad/file" }).given(session).list("/bad");
willThrow(new IOException("No file")).given(session).readRaw("/bad/file");
given(session.finalizeRaw()).willReturn(true);
return session;
}