@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();
  }
 @Override
 public void update(final ExecutionContext executionContext) throws ItemStreamException {
   executionContext.putString(LAST_ID_RETURNED_EXECUTION_CONTEXT_KEY, lastIdReturned);
 }