Search in sources :

Example 16 with SessionFactory

use of org.springframework.integration.file.remote.session.SessionFactory 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));
}
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 17 with SessionFactory

use of org.springframework.integration.file.remote.session.SessionFactory 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));
}
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 18 with SessionFactory

use of org.springframework.integration.file.remote.session.SessionFactory 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));
}
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 19 with SessionFactory

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

the class RemoteFileOutboundGatewayTests method testLs_1_dirs_links.

@Test
public void testLs_1_dirs_links() throws Exception {
    SessionFactory sessionFactory = mock(SessionFactory.class);
    Session session = mock(Session.class);
    TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "ls", "payload");
    gw.setOptions("-1 -dirs -links");
    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(4, out.getPayload().size());
    assertEquals("f1", out.getPayload().get(0));
    assertEquals("f2", out.getPayload().get(1));
    assertEquals("f3", out.getPayload().get(2));
    assertEquals("f4", out.getPayload().get(3));
}
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 20 with SessionFactory

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

the class RemoteFileOutboundGatewayTests method testBadFilterRm.

@Test
public void testBadFilterRm() throws Exception {
    SessionFactory sessionFactory = mock(SessionFactory.class);
    TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "rm", "payload");
    gw.setFilter(new TestPatternFilter(""));
    try {
        gw.afterPropertiesSet();
        fail("Exception expected");
    } catch (IllegalArgumentException e) {
        assertTrue(e.getMessage().startsWith("Filters are not supported"));
    }
}
Also used : SessionFactory(org.springframework.integration.file.remote.session.SessionFactory) Test(org.junit.Test)

Aggregations

SessionFactory (org.springframework.integration.file.remote.session.SessionFactory)31 Test (org.junit.Test)30 MessageBuilder (org.springframework.integration.support.MessageBuilder)19 GenericMessage (org.springframework.messaging.support.GenericMessage)19 Matchers.containsString (org.hamcrest.Matchers.containsString)17 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)17 Session (org.springframework.integration.file.remote.session.Session)15 ArrayList (java.util.ArrayList)14 List (java.util.List)14 File (java.io.File)9 FileOutputStream (java.io.FileOutputStream)9 IOException (java.io.IOException)9 OutputStream (java.io.OutputStream)8 CachingSessionFactory (org.springframework.integration.file.remote.session.CachingSessionFactory)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 RunWith (org.junit.runner.RunWith)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2