Search in sources :

Example 6 with MessageBuilder

use of org.springframework.integration.support.MessageBuilder in project spring-integration by spring-projects.

the class RemoteFileOutboundGatewayTests method testMove.

@Test
public void testMove() throws Exception {
    SessionFactory sessionFactory = mock(SessionFactory.class);
    TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "mv", "payload");
    gw.afterPropertiesSet();
    Session<?> session = mock(Session.class);
    final AtomicReference<String> args = new AtomicReference<String>();
    doAnswer(invocation -> {
        Object[] arguments = invocation.getArguments();
        args.set((String) arguments[0] + (String) arguments[1]);
        return null;
    }).when(session).rename(anyString(), anyString());
    when(sessionFactory.getSession()).thenReturn(session);
    Message<String> requestMessage = MessageBuilder.withPayload("foo").setHeader(FileHeaders.RENAME_TO, "bar").build();
    MessageBuilder<?> out = (MessageBuilder<?>) gw.handleRequestMessage(requestMessage);
    assertEquals("foo", out.getHeaders().get(FileHeaders.REMOTE_FILE));
    assertEquals("foobar", args.get());
    assertEquals(Boolean.TRUE, out.getPayload());
}
Also used : SessionFactory(org.springframework.integration.file.remote.session.SessionFactory) MessageBuilder(org.springframework.integration.support.MessageBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 7 with MessageBuilder

use of org.springframework.integration.support.MessageBuilder 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 8 with MessageBuilder

use of org.springframework.integration.support.MessageBuilder 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)

Example 9 with MessageBuilder

use of org.springframework.integration.support.MessageBuilder in project spring-integration by spring-projects.

the class RemoteFileOutboundGatewayTests method testLs_1_a_f_dirs_links.

@Test
public void testLs_1_a_f_dirs_links() 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.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(6, out.getPayload().size());
    assertEquals("f2", out.getPayload().get(0));
    assertEquals("f1", out.getPayload().get(1));
    assertEquals("f3", out.getPayload().get(2));
    assertEquals("f4", out.getPayload().get(3));
    assertEquals(".f5", out.getPayload().get(4));
    assertEquals(".f6", out.getPayload().get(5));
}
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 10 with MessageBuilder

use of org.springframework.integration.support.MessageBuilder in project spring-integration by spring-projects.

the class RemoteFileOutboundGatewayTests method testLs_1_f.

@Test
public void testLs_1_f() throws Exception {
    // no sort
    SessionFactory sessionFactory = mock(SessionFactory.class);
    Session session = mock(Session.class);
    TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "ls", "payload");
    gw.setOptions("-1 -f");
    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("f2", out.getPayload().get(0));
    assertEquals("f1", 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)

Aggregations

SessionFactory (org.springframework.integration.file.remote.session.SessionFactory)19 MessageBuilder (org.springframework.integration.support.MessageBuilder)19 Test (org.junit.Test)18 GenericMessage (org.springframework.messaging.support.GenericMessage)17 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Matchers.containsString (org.hamcrest.Matchers.containsString)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 Session (org.springframework.integration.file.remote.session.Session)12 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Calendar (java.util.Calendar)1 Date (java.util.Date)1