@Test
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public void testWrite() throws Exception {
		File file = new File(tmpDir, "foo.txt");
		file.delete();

		ByteArrayInputStream data = new ByteArrayInputStream("foobarbaz".getBytes());
		Session session = mock(Session.class);
		SessionFactory factory = mock(SessionFactory.class);
		when(factory.getSession()).thenReturn(session);
		when(session.readRaw("foo.txt")).thenReturn(data);
		when(session.finalizeRaw()).thenReturn(true);

		StepExecution stepExecution = new StepExecution("foo", null);
		ExecutionContext stepExecutionContext = new ExecutionContext();
		stepExecutionContext.putString("filePath", "foo.txt");
		stepExecution.setExecutionContext(stepExecutionContext);
		StepContext stepContext = new StepContext(stepExecution);
		ChunkContext chunkContext = new ChunkContext(stepContext);

		RemoteFileTemplate template = new RemoteFileTemplate(factory);
		template.setBeanFactory(mock(BeanFactory.class));
		template.afterPropertiesSet();

		// clean up from old tests
		FileSystem fs = FileSystem.get(configuration);
		Path p = new Path("/qux/foo.txt");
		fs.delete(p, true);
		assertFalse(fs.exists(p));

		RemoteFileToHadoopTasklet tasklet = new RemoteFileToHadoopTasklet(template,
				configuration, "/qux");

		assertEquals(RepeatStatus.FINISHED, tasklet.execute(null, chunkContext));

		assertTrue(fs.exists(p));

		FSDataInputStream stream = fs.open(p);
		byte[] out = new byte[9];
		stream.readFully(out);
		stream.close();
		assertEquals("foobarbaz", new String(out));

		fs.close();
	}
@author Gary Russell
@author David Turanski
extensions/spring-xd-extension-batch/src/test/java/org/springframework/batch/integration/x/RemoteFileToHadoopTaskletTests.java