List of usage examples for org.springframework.integration.file.remote.session Session readRaw
InputStream readRaw(String source) throws IOException;
From source file:org.springframework.batch.integration.x.RemoteFileToHadoopTests.java
@SuppressWarnings({ "unchecked", "rawtypes" })
@Before/*from w ww .ja va 2 s .com*/
public void setup() throws Exception {
byte[] bytes = "foobarbaz".getBytes();
// using this trick here by getting hadoop minicluster from main test
// context and then using it to override 'hadoopConfiguration' bean
// which is imported from ftphdfs.xml.
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext();
ctx.setConfigLocations("org/springframework/batch/integration/x/RemoteFileToHadoopTests-context.xml",
"org/springframework/batch/integration/x/miniclusterconfig.xml");
Properties properties = new Properties();
properties.setProperty("restartable", "false");
properties.setProperty("xd.config.home", "file:../../config");
properties.setProperty("partitionResultsTimeout", "3600000");
PropertiesPropertySource propertiesPropertySource = new PropertiesPropertySource("props", properties);
ctx.getEnvironment().getPropertySources().addLast(propertiesPropertySource);
ctx.setParent(context);
ctx.refresh();
this.sessionFactory = ctx.getBean(SessionFactory.class);
Session session = mock(Session.class);
when(this.sessionFactory.getSession()).thenReturn(session);
when(session.readRaw("/foo/bar.txt")).thenReturn(new ByteArrayInputStream(bytes));
when(session.readRaw("/foo/baz.txt")).thenReturn(new ByteArrayInputStream(bytes));
when(session.finalizeRaw()).thenReturn(true);
Object[] fileList = new FTPFile[2];
FTPFile file = new FTPFile();
file.setName("bar.txt");
fileList[0] = file;
file = new FTPFile();
file.setName("baz.txt");
fileList[1] = file;
when(session.list("/foo/")).thenReturn(fileList);
this.launcher = ctx.getBean(JobLauncher.class);
this.job = ctx.getBean(Job.class);
this.requestsOut = ctx.getBean("stepExecutionRequests.output", MessageChannel.class);
this.requestsIn = ctx.getBean("stepExecutionRequests.input", MessageChannel.class);
this.repliesOut = ctx.getBean("stepExecutionReplies.output", MessageChannel.class);
this.repliesIn = ctx.getBean("stepExecutionReplies.input", MessageChannel.class);
this.bus = new LocalMessageBus();
((LocalMessageBus) this.bus).setApplicationContext(ctx);
this.bus.bindRequestor("foo", this.requestsOut, this.repliesIn, null);
this.bus.bindReplier("foo", this.requestsIn, this.repliesOut, null);
}
From source file:org.springframework.batch.integration.x.RemoteFileToTmpTests.java
@SuppressWarnings({ "unchecked", "rawtypes" })
@Before/* ww w. j av a2 s.c o m*/
public void setup() throws Exception {
byte[] bytes = "foo".getBytes();
Session session = mock(Session.class);
when(this.sessionFactory.getSession()).thenReturn(session);
when(session.readRaw("/foo/bar.txt")).thenReturn(new ByteArrayInputStream(bytes));
when(session.readRaw("/foo/baz.txt")).thenReturn(new ByteArrayInputStream(bytes));
when(session.finalizeRaw()).thenReturn(true);
Object[] fileList = new FTPFile[2];
FTPFile file = new FTPFile();
file.setName("bar.txt");
fileList[0] = file;
file = new FTPFile();
file.setName("baz.txt");
fileList[1] = file;
when(session.list("/foo/")).thenReturn(fileList);
this.bus = new LocalMessageBus();
this.bus.setApplicationContext(BusTestUtils.MOCK_AC);
this.bus.bindRequestor("foo", this.requestsOut, this.repliesIn, null);
this.bus.bindReplier("foo", this.requestsIn, this.repliesOut, null);
this.bus.afterPropertiesSet();
}
From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java
@Test public void testInt3100RawGET() throws Exception { Session<?> session = this.ftpSessionFactory.getSession(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); FileCopyUtils.copy(session.readRaw("ftpSource/ ftpSource1.txt"), baos); assertTrue(session.finalizeRaw());/*from ww w . j av a2 s.co m*/ assertEquals("source1", new String(baos.toByteArray())); baos = new ByteArrayOutputStream(); FileCopyUtils.copy(session.readRaw("ftpSource/ftpSource2.txt"), baos); assertTrue(session.finalizeRaw()); assertEquals("source2", new String(baos.toByteArray())); session.close(); }
From source file:org.springframework.integration.sftp.outbound.SftpServerOutboundTests.java
/** * Only runs with a real server (see class javadocs). *//*from w w w .j av a 2 s. c o m*/ @Test public void testInt3100RawGET() throws Exception { Session<?> session = this.sessionFactory.getSession(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); FileCopyUtils.copy(session.readRaw("sftpSource/ sftpSource1.txt"), baos); assertTrue(session.finalizeRaw()); assertEquals("source1", new String(baos.toByteArray())); baos = new ByteArrayOutputStream(); FileCopyUtils.copy(session.readRaw("sftpSource/sftpSource2.txt"), baos); assertTrue(session.finalizeRaw()); assertEquals("source2", new String(baos.toByteArray())); session.close(); }