use of org.springframework.integration.file.remote.session.Session in project spring-integration by spring-projects.
the class AbstractRemoteFileSynchronizerTests method testRollback.
@Test
public void testRollback() throws Exception {
final AtomicBoolean failWhenCopyingBar = new AtomicBoolean(true);
final AtomicInteger count = new AtomicInteger();
SessionFactory<String> sf = new StringSessionFactory();
AbstractInboundFileSynchronizer<String> sync = new AbstractInboundFileSynchronizer<String>(sf) {
@Override
protected boolean isFile(String file) {
return true;
}
@Override
protected String getFilename(String file) {
return file;
}
@Override
protected long getModified(String file) {
return 0;
}
@Override
protected boolean copyFileToLocalDirectory(String remoteDirectoryPath, String remoteFile, File localDirectory, Session<String> session) throws IOException {
if ("bar".equals(remoteFile) && failWhenCopyingBar.getAndSet(false)) {
throw new IOException("fail");
}
count.incrementAndGet();
return true;
}
};
sync.setFilter(new AcceptOnceFileListFilter<String>());
sync.setRemoteDirectory("foo");
try {
sync.synchronizeToLocalDirectory(mock(File.class));
assertEquals(1, count.get());
fail("Expected exception");
} catch (MessagingException e) {
assertThat(e.getCause(), instanceOf(MessagingException.class));
assertThat(e.getCause().getCause(), instanceOf(IOException.class));
assertEquals("fail", e.getCause().getCause().getMessage());
}
sync.synchronizeToLocalDirectory(mock(File.class));
assertEquals(3, count.get());
sync.close();
}
use of org.springframework.integration.file.remote.session.Session in project spring-integration by spring-projects.
the class SftpServerOutboundTests method testInt3088MPutNotRecursive.
@Test
public void testInt3088MPutNotRecursive() throws Exception {
Session<?> session = sessionFactory.getSession();
session.close();
session = TestUtils.getPropertyValue(session, "targetSession", Session.class);
ChannelSftp channel = spy(TestUtils.getPropertyValue(session, "channel", ChannelSftp.class));
new DirectFieldAccessor(session).setPropertyValue("channel", channel);
String dir = "sftpSource/";
this.inboundMGetRecursive.send(new GenericMessage<Object>(dir + "*"));
while (output.receive(0) != null) {
// drain
}
this.inboundMPut.send(new GenericMessage<File>(getSourceLocalDirectory()));
@SuppressWarnings("unchecked") Message<List<String>> out = (Message<List<String>>) this.output.receive(1000);
assertNotNull(out);
assertEquals(2, out.getPayload().size());
assertThat(out.getPayload().get(0), not(equalTo(out.getPayload().get(1))));
assertThat(out.getPayload().get(0), anyOf(equalTo("sftpTarget/localSource1.txt"), equalTo("sftpTarget/localSource2.txt")));
assertThat(out.getPayload().get(1), anyOf(equalTo("sftpTarget/localSource1.txt"), equalTo("sftpTarget/localSource2.txt")));
// 384 = 600 octal
verify(channel).chmod(384, "sftpTarget/localSource1.txt");
verify(channel).chmod(384, "sftpTarget/localSource2.txt");
}
use of org.springframework.integration.file.remote.session.Session in project spring-integration by spring-projects.
the class RemoteFileOutboundGatewayTests method testLs_1_a_f_dirs_links_filtered.
@Test
public void testLs_1_a_f_dirs_links_filtered() throws Exception {
SessionFactory sessionFactory = mock(SessionFactory.class);
Session session = mock(Session.class);
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "ls", "payload");
gw.setOptions("-1 -a -f -dirs -links");
gw.setFilter(new TestPatternFilter("*4"));
gw.afterPropertiesSet();
when(sessionFactory.getSession()).thenReturn(session);
TestLsEntry[] files = fileList();
when(session.list("testremote/")).thenReturn(files);
@SuppressWarnings("unchecked") MessageBuilder<List<String>> out = (MessageBuilder<List<String>>) gw.handleRequestMessage(new GenericMessage<>("testremote"));
assertEquals(1, out.getPayload().size());
assertEquals("f4", out.getPayload().get(0));
}
use of org.springframework.integration.file.remote.session.Session in project spring-integration by spring-projects.
the class RemoteFileOutboundGatewayTests method testLs_1_dirs.
@Test
public void testLs_1_dirs() throws Exception {
SessionFactory sessionFactory = mock(SessionFactory.class);
Session session = mock(Session.class);
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "ls", "payload");
gw.setOptions("-1 -dirs");
gw.afterPropertiesSet();
when(sessionFactory.getSession()).thenReturn(session);
TestLsEntry[] files = fileList();
when(session.list("testremote/")).thenReturn(files);
@SuppressWarnings("unchecked") MessageBuilder<List<String>> out = (MessageBuilder<List<String>>) gw.handleRequestMessage(new GenericMessage<>("testremote"));
assertEquals(3, out.getPayload().size());
assertEquals("f1", out.getPayload().get(0));
assertEquals("f2", out.getPayload().get(1));
assertEquals("f3", out.getPayload().get(2));
}
use of org.springframework.integration.file.remote.session.Session in project spring-integration by spring-projects.
the class RemoteFileOutboundGatewayTests method testLs_f_R_dirs.
@Test
public void testLs_f_R_dirs() throws Exception {
SessionFactory sessionFactory = mock(SessionFactory.class);
Session session = mock(Session.class);
TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "ls", "payload");
gw.setOptions("-f -R -dirs");
gw.afterPropertiesSet();
when(sessionFactory.getSession()).thenReturn(session);
TestLsEntry[] level1 = level1List();
TestLsEntry[] level2 = level2List();
TestLsEntry[] level3 = level3List();
when(session.list("testremote/x/")).thenReturn(level1);
when(session.list("testremote/x/d1/")).thenReturn(level2);
when(session.list("testremote/x/d1/d2/")).thenReturn(level3);
@SuppressWarnings("unchecked") MessageBuilder<List<TestLsEntry>> out = (MessageBuilder<List<TestLsEntry>>) gw.handleRequestMessage(new GenericMessage<>("testremote/x"));
assertEquals(6, out.getPayload().size());
assertEquals("f1", out.getPayload().get(0).getFilename());
assertEquals("d1", out.getPayload().get(1).getFilename());
assertEquals("d1/d2", out.getPayload().get(2).getFilename());
assertEquals("d1/d2/f4", out.getPayload().get(3).getFilename());
assertEquals("d1/f3", out.getPayload().get(4).getFilename());
assertEquals("f2", out.getPayload().get(5).getFilename());
assertEquals("testremote/x/", out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
}
Aggregations