@Before
  public void init() throws Exception {

    earlierExecution =
        MetaDataInstanceFactory.createJobExecutionWithStepExecutions(122L, Arrays.asList("step"));
    earlierExecution.setStatus(BatchStatus.FAILED);
    earlierExecution.setExitStatus(ExitStatus.FAILED);
    earlierExecution.setStartTime(new Date());
    earlierExecution.setEndTime(new Date(earlierExecution.getStartTime().getTime() + 100));
    assertFalse(earlierExecution.isRunning());

    jobExecution =
        MetaDataInstanceFactory.createJobExecutionWithStepExecutions(
            123L, Arrays.asList("first", "step"));
    jobExecution.setStatus(BatchStatus.COMPLETED);
    jobExecution.setExitStatus(ExitStatus.COMPLETED);
    jobExecution.setStartTime(new Date());
    jobExecution.setEndTime(new Date(earlierExecution.getEndTime().getTime() + 100));
    assertFalse(jobExecution.isRunning());

    Iterator<StepExecution> iterator = jobExecution.getStepExecutions().iterator();
    iterator.next();
    StepExecution stepExecution = iterator.next();
    stepExecution.setStatus(BatchStatus.COMPLETED);
    stepExecution.setExitStatus(ExitStatus.COMPLETED.addExitDescription("Foo"));

    metrics = new SimpleJobExecutionMetrics(jobService, "job");
  }
  @Before
  public void setUp() {
    // Job 전체를 생성하지 않고, 특정 Step만을 Dummy로 생성하여 테스트 할 수 있다.

    stepExecution = MetaDataInstanceFactory.createStepExecution();
    jobExecution = MetaDataInstanceFactory.createJobExecution();
    decider = new NextDecider();
  }
  @Test
  public void testSimpleJob() throws Exception {

    JobInstance jobInstance = MetaDataInstanceFactory.createJobInstance("foo", 11L);
    JobExecution jobExecution = MetaDataInstanceFactory.createJobExecution("foo", 11L, 123L);
    jobExecution.setEndTime(new Date());
    jobExecution.setStatus(BatchStatus.FAILED);

    when(jobExplorer.getJobInstances("foo", 0, 100)).thenReturn(Arrays.asList(jobInstance));
    when(jobExplorer.getJobExecutions(jobInstance)).thenReturn(Arrays.asList(jobExecution));

    JobLaunchRequest request = adapter.adapt("foo");
    assertEquals("foo", request.getJob().getName());
    assertEquals(0, request.getJobParameters().getParameters().size());
  }
 /**
  * Test should read succesfully.
  *
  * @throws Exception
  */
 @Test
 public void testSuccessfulReading() throws Exception {
   // init linetokenizer
   DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
   lineTokenizer.setNames(new String[] {"id", "value"});
   // init linemapper
   DefaultLineMapper<FieldSet> lineMapper = new DefaultLineMapper<FieldSet>();
   lineMapper.setLineTokenizer(lineTokenizer);
   lineMapper.setFieldSetMapper(new PassThroughFieldSetMapper());
   // init reader
   reader.setLineMapper(lineMapper);
   reader.setResource(new FileSystemResource(INPUT_FILE));
   // open, provide "mock" ExecutionContext
   reader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext());
   // read
   try {
     int count = 0;
     FieldSet line;
     while ((line = reader.read()) != null) {
       // really test for the fieldSet names and values
       assertEquals("id", line.getNames()[0]);
       assertEquals(String.valueOf(count), line.getValues()[0]);
       assertEquals("value", line.getNames()[1]);
       // csv contains entry like '0,foo0'
       assertEquals("foo" + String.valueOf(count), line.getValues()[1]);
       count++;
     }
     assertEquals(EXPECTED_COUNT, count);
   } catch (Exception e) {
     throw e;
   } finally {
     reader.close();
   }
 }
  @Test
  public void testSimpleJobNotFailed() throws Exception {

    thrown.expect(JobParametersNotFoundException.class);
    thrown.expectMessage("No failed or stopped execution");

    JobInstance jobInstance = MetaDataInstanceFactory.createJobInstance("foo", 11L);
    JobExecution jobExecution = MetaDataInstanceFactory.createJobExecution("foo", 11L, 123L);
    jobExecution.setEndTime(new Date());
    jobExecution.setStatus(BatchStatus.COMPLETED);

    when(jobExplorer.getJobInstances("foo", 0, 100)).thenReturn(Arrays.asList(jobInstance));
    when(jobExplorer.getJobExecutions(jobInstance)).thenReturn(Arrays.asList(jobExecution));
    when(jobExplorer.getJobInstances("foo", 100, 100)).thenReturn(new ArrayList<JobInstance>());

    adapter.adapt("foo");
  }
 @Override
 protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) {
   JobParameters jobParameters =
       new JobParametersBuilder(super.getUniqueJobParameters())
           .addString("input.file.path", "file:build/test-outputs/multiResourceOutput.csv.*")
           .toJobParameters();
   StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(jobParameters);
   StepSynchronizationManager.close();
   StepSynchronizationManager.register(stepExecution);
 }
  /**
   * Read compressed test.
   *
   * @throws Exception
   */
  @Test
  public void readCompressed() throws Exception {
    // setup the reader
    reader.setBufferedReaderFactory(new GZipBufferedReaderFactory());
    reader.setLineMapper(new PassThroughLineMapper());
    reader.setResource(new FileSystemResource(PATH_TO_COMPRESSED_TEST_FILE));
    // open with dummy execution context
    reader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext());

    // read
    try {
      int count = 0;
      String line;
      while ((line = reader.read()) != null) {
        assertEquals(String.valueOf(count), line);
        count++;
      }
      assertEquals(count, EXPECTED_COUNT);
    } finally {
      reader.close();
    }
  }