@Override protected void onInit() { this.remoteFileTemplate.setBeanFactory(this.getBeanFactory()); this.remoteFileTemplate.afterPropertiesSet(); }
@SuppressWarnings("unchecked") @Before public void setUp() throws Exception { SessionFactory<Object> sessionFactory = mock(SessionFactory.class); this.template = new RemoteFileTemplate<Object>(sessionFactory); this.template.setRemoteDirectoryExpression(new LiteralExpression("/foo")); this.template.setBeanFactory(mock(BeanFactory.class)); this.template.afterPropertiesSet(); this.session = mock(Session.class); when(sessionFactory.getSession()).thenReturn(this.session); this.file = this.folder.newFile(); }
@Test public void testDirtySession() throws Exception { @SuppressWarnings("unchecked") SessionFactory<Object> factory = mock(SessionFactory.class); @SuppressWarnings("unchecked") Session<Object> session = mock(Session.class); when(factory.getSession()).thenReturn(session); when(session.readRaw("foo")).thenReturn(new ByteArrayInputStream("".getBytes())); when(session.finalizeRaw()).thenReturn(true); CachingSessionFactory<Object> ccf = new CachingSessionFactory<Object>(factory); RemoteFileTemplate<Object> template = new RemoteFileTemplate<Object>(ccf); template.setFileNameExpression(new LiteralExpression("foo")); template.setBeanFactory(mock(BeanFactory.class)); template.afterPropertiesSet(); try { template.get(new GenericMessage<String>("foo"), (InputStreamCallback) stream -> { throw new RuntimeException("bar"); }); fail("Expected exception"); } catch (Exception e) { assertThat(e.getCause(), instanceOf(RuntimeException.class)); assertThat(e.getCause().getMessage(), equalTo("bar")); } verify(session).close(); }
template.setRemoteDirectoryExpression(new LiteralExpression("foo/")); template.setBeanFactory(mock(BeanFactory.class)); template.afterPropertiesSet(); TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(template, "mput", "payload"); gw.afterPropertiesSet();
template.setRemoteDirectoryExpression(new LiteralExpression("foo/")); template.setBeanFactory(mock(BeanFactory.class)); template.afterPropertiesSet(); TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(template, "mput", null); gw.setOptions("-R");
template.setRemoteDirectoryExpression(new LiteralExpression("foo/")); template.setBeanFactory(mock(BeanFactory.class)); template.afterPropertiesSet(); TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(template, "mput", "payload"); gw.afterPropertiesSet();
@Test public void testRawGETWithTemplate() throws Exception { RemoteFileTemplate<FTPFile> template = new RemoteFileTemplate<FTPFile>(this.ftpSessionFactory); template.setFileNameExpression(new SpelExpressionParser().parseExpression("payload")); template.setBeanFactory(mock(BeanFactory.class)); template.afterPropertiesSet(); final ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); assertTrue(template.get(new GenericMessage<String>("ftpSource/ ftpSource1.txt"), (InputStreamCallback) stream -> FileCopyUtils.copy(stream, baos1))); assertEquals("source1", new String(baos1.toByteArray())); final ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); assertTrue(template.get(new GenericMessage<String>("ftpSource/ftpSource2.txt"), (InputStreamCallback) stream -> FileCopyUtils.copy(stream, baos2))); assertEquals("source2", new String(baos2.toByteArray())); }
template.setRemoteDirectoryExpression(new LiteralExpression("foo/")); template.setBeanFactory(mock(BeanFactory.class)); template.afterPropertiesSet(); TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(template, "put", "payload"); FileTransferringMessageHandler<TestLsEntry> handler = new FileTransferringMessageHandler<TestLsEntry>(sessionFactory);
template.setRemoteDirectoryExpression(new LiteralExpression("foo/")); template.setBeanFactory(mock(BeanFactory.class)); template.afterPropertiesSet(); TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(template, "put", "payload"); FileTransferringMessageHandler<TestLsEntry> handler = new FileTransferringMessageHandler<TestLsEntry>(sessionFactory);