Search in sources :

Example 1 with Session

use of org.springframework.integration.file.remote.session.Session in project spring-integration by spring-projects.

the class RemoteFileOutboundGatewayTests method testLs_None.

@Test
public void testLs_None() throws Exception {
    SessionFactory sessionFactory = mock(SessionFactory.class);
    Session session = mock(Session.class);
    TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "ls", "payload");
    gw.afterPropertiesSet();
    when(sessionFactory.getSession()).thenReturn(session);
    TestLsEntry[] files = new TestLsEntry[0];
    when(session.list("testremote/")).thenReturn(files);
    @SuppressWarnings("unchecked") MessageBuilder<List<TestLsEntry>> out = (MessageBuilder<List<TestLsEntry>>) gw.handleRequestMessage(new GenericMessage<>("testremote"));
    assertEquals(0, out.getPayload().size());
}
Also used : SessionFactory(org.springframework.integration.file.remote.session.SessionFactory) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageBuilder(org.springframework.integration.support.MessageBuilder) List(java.util.List) ArrayList(java.util.ArrayList) Session(org.springframework.integration.file.remote.session.Session) Test(org.junit.Test)

Example 2 with Session

use of org.springframework.integration.file.remote.session.Session in project spring-integration by spring-projects.

the class RemoteFileOutboundGatewayTests method testLs_f.

@Test
public void testLs_f() throws Exception {
    SessionFactory sessionFactory = mock(SessionFactory.class);
    Session session = mock(Session.class);
    TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "ls", "payload");
    gw.setOptions("-f");
    gw.afterPropertiesSet();
    when(sessionFactory.getSession()).thenReturn(session);
    TestLsEntry[] files = fileList();
    when(session.list("testremote/x/")).thenReturn(files);
    @SuppressWarnings("unchecked") MessageBuilder<List<TestLsEntry>> out = (MessageBuilder<List<TestLsEntry>>) gw.handleRequestMessage(new GenericMessage<>("testremote/x"));
    assertEquals(2, out.getPayload().size());
    assertSame(files[0], out.getPayload().get(0));
    assertSame(files[1], out.getPayload().get(1));
    assertEquals("testremote/x/", out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
}
Also used : SessionFactory(org.springframework.integration.file.remote.session.SessionFactory) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageBuilder(org.springframework.integration.support.MessageBuilder) List(java.util.List) ArrayList(java.util.ArrayList) Session(org.springframework.integration.file.remote.session.Session) Test(org.junit.Test)

Example 3 with Session

use of org.springframework.integration.file.remote.session.Session in project spring-integration by spring-projects.

the class RemoteFileOutboundGatewayTests method testRm.

@Test
public void testRm() throws Exception {
    SessionFactory sessionFactory = mock(SessionFactory.class);
    Session session = mock(Session.class);
    TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "rm", "payload");
    gw.afterPropertiesSet();
    when(sessionFactory.getSession()).thenReturn(session);
    when(session.remove("testremote/x/f1")).thenReturn(Boolean.TRUE);
    @SuppressWarnings("unchecked") MessageBuilder<Boolean> out = (MessageBuilder<Boolean>) gw.handleRequestMessage(new GenericMessage<>("testremote/x/f1"));
    assertEquals(Boolean.TRUE, out.getPayload());
    verify(session).remove("testremote/x/f1");
    assertEquals("testremote/x/", out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
    assertEquals("f1", out.getHeaders().get(FileHeaders.REMOTE_FILE));
}
Also used : SessionFactory(org.springframework.integration.file.remote.session.SessionFactory) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageBuilder(org.springframework.integration.support.MessageBuilder) Session(org.springframework.integration.file.remote.session.Session) Test(org.junit.Test)

Example 4 with Session

use of org.springframework.integration.file.remote.session.Session in project spring-integration by spring-projects.

the class RemoteFileOutboundGatewayTests method testLs_1.

@Test
public void testLs_1() throws Exception {
    SessionFactory sessionFactory = mock(SessionFactory.class);
    Session session = mock(Session.class);
    TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "ls", "payload");
    gw.setOptions("-1");
    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(2, out.getPayload().size());
    assertEquals("f1", out.getPayload().get(0));
    assertEquals("f2", out.getPayload().get(1));
}
Also used : SessionFactory(org.springframework.integration.file.remote.session.SessionFactory) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageBuilder(org.springframework.integration.support.MessageBuilder) List(java.util.List) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Session(org.springframework.integration.file.remote.session.Session) Test(org.junit.Test)

Example 5 with Session

use of org.springframework.integration.file.remote.session.Session in project spring-integration by spring-projects.

the class RemoteFileOutboundGatewayTests method testLs.

@Test
public void testLs() throws Exception {
    SessionFactory sessionFactory = mock(SessionFactory.class);
    Session session = mock(Session.class);
    TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "ls", "payload");
    gw.afterPropertiesSet();
    when(sessionFactory.getSession()).thenReturn(session);
    TestLsEntry[] files = fileList();
    when(session.list("testremote/x/")).thenReturn(files);
    @SuppressWarnings("unchecked") MessageBuilder<List<TestLsEntry>> out = (MessageBuilder<List<TestLsEntry>>) gw.handleRequestMessage(new GenericMessage<>("testremote/x"));
    assertEquals(2, out.getPayload().size());
    // sort by default
    assertSame(files[1], out.getPayload().get(0));
    assertSame(files[0], out.getPayload().get(1));
    assertEquals("testremote/x/", out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
}
Also used : SessionFactory(org.springframework.integration.file.remote.session.SessionFactory) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageBuilder(org.springframework.integration.support.MessageBuilder) List(java.util.List) ArrayList(java.util.ArrayList) Session(org.springframework.integration.file.remote.session.Session) Test(org.junit.Test)

Aggregations

Session (org.springframework.integration.file.remote.session.Session)23 Test (org.junit.Test)22 SessionFactory (org.springframework.integration.file.remote.session.SessionFactory)16 List (java.util.List)13 GenericMessage (org.springframework.messaging.support.GenericMessage)13 ArrayList (java.util.ArrayList)12 MessageBuilder (org.springframework.integration.support.MessageBuilder)12 Matchers.containsString (org.hamcrest.Matchers.containsString)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 CachingSessionFactory (org.springframework.integration.file.remote.session.CachingSessionFactory)5 ChannelSftp (com.jcraft.jsch.ChannelSftp)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)4 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)3 JSch (com.jcraft.jsch.JSch)3 File (java.io.File)3 IOException (java.io.IOException)2 DefaultSftpSessionFactory (org.springframework.integration.sftp.session.DefaultSftpSessionFactory)2 SftpSession (org.springframework.integration.sftp.session.SftpSession)2 MessagingException (org.springframework.messaging.MessagingException)2