Package org.springframework.batch.core

Examples of org.springframework.batch.core.Step


    // no failures on read
    reader.setItems("1", "2", "3", "4", "5");
    writer.setFailures("1");

    Step step = factory.getObject();

    step.execute(stepExecution);
    assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
    assertEquals(1, reader.getRead().size());
    assertEquals(ExitStatus.FAILED.getExitCode(), stepExecution.getExitStatus().getExitCode());
    assertTrue(stepExecution.getExitStatus().getExitDescription().contains("Intended Failure"));
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here


   */
  @Test
  public void testReadSkip() throws Exception {
    reader.setFailures("2");

    Step step = factory.getObject();

    step.execute(stepExecution);

    assertEquals(1, stepExecution.getSkipCount());
    assertEquals(1, stepExecution.getReadSkipCount());
    assertEquals(4, stepExecution.getReadCount());
    assertEquals(0, stepExecution.getWriteSkipCount());
    assertEquals(0, stepExecution.getRollbackCount());

    // writer did not skip "2" as it never made it to writer, only "4" did
    assertTrue(reader.getRead().contains("4"));
    assertFalse(reader.getRead().contains("2"));

    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,3,4,5"));
    assertEquals(expectedOutput, writer.getWritten());

    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here

      }
    });

    reader.setFailures("2");

    Step step = factory.getObject();

    step.execute(stepExecution);

    assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
    assertEquals(0, stepExecution.getReadSkipCount());
    assertEquals(1, stepExecution.getReadCount());
View Full Code Here

      }
    });

    writer.setFailures("2");

    Step step = factory.getObject();

    step.execute(stepExecution);

    assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
    assertEquals(0, stepExecution.getWriteSkipCount());
    assertEquals(2, stepExecution.getReadCount());
View Full Code Here

    Map<Class<? extends Throwable>, Boolean> map = new HashMap<Class<? extends Throwable>, Boolean>();
    map.put(ItemStreamException.class, true);
    factory.setSkippableExceptionClasses(map);

    Step step = factory.getObject();

    step.execute(stepExecution);

    assertEquals(1, stepExecution.getSkipCount());
    assertEquals(1, stepExecution.getReadSkipCount());
    assertEquals(4, stepExecution.getReadCount());
    assertEquals(0, stepExecution.getWriteSkipCount());
    assertEquals(0, stepExecution.getRollbackCount());

    // writer did not skip "2" as it never made it to writer, only "4" did
    assertTrue(reader.getRead().contains("4"));
    assertFalse(reader.getRead().contains("2"));

    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,3,4,5"));
    assertEquals(expectedOutput, writer.getWritten());

    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here

  @Test
  public void testProcessSkip() throws Exception {
    processor.setFailures("4");
    writer.setFailures("4");

    Step step = factory.getObject();

    step.execute(stepExecution);

    assertEquals(1, stepExecution.getSkipCount());
    assertEquals(0, stepExecution.getReadSkipCount());
    assertEquals(5, stepExecution.getReadCount());
    assertEquals(1, stepExecution.getProcessSkipCount());
    assertEquals(1, stepExecution.getRollbackCount());

    // writer skips "4"
    assertTrue(reader.getRead().contains("4"));
    assertFalse(writer.getWritten().contains("4"));

    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,2,3,5"));
    assertEquals(expectedOutput, writer.getWritten());

    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here

  public void testProcessFilter() throws Exception {
    processor.setFailures("4");
    processor.setFilter(true);
    ItemProcessListenerStub<String, String> listenerStub = new ItemProcessListenerStub<String, String>();
    factory.setListeners(new StepListener[] { listenerStub });
    Step step = factory.getObject();

    step.execute(stepExecution);

    assertEquals(0, stepExecution.getSkipCount());
    assertEquals(0, stepExecution.getReadSkipCount());
    assertEquals(5, stepExecution.getReadCount());
    assertEquals(1, stepExecution.getFilterCount());
    assertEquals(0, stepExecution.getRollbackCount());
    assertTrue(listenerStub.isFilterEncountered());

    // writer skips "4"
    assertTrue(reader.getRead().contains("4"));
    assertFalse(writer.getWritten().contains("4"));

    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,2,3,5"));
    assertEquals(expectedOutput, writer.getWritten());

    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here

  @Test
  public void testNullWriter() throws Exception {

    factory.setItemWriter(null);
    Step step = factory.getObject();

    step.execute(stepExecution);

    assertEquals(0, stepExecution.getSkipCount());
    assertEquals(0, stepExecution.getReadSkipCount());
    assertEquals(5, stepExecution.getReadCount());
    // Write count is incremented even if nothing happens
    assertEquals(5, stepExecution.getWriteCount());
    assertEquals(0, stepExecution.getFilterCount());
    assertEquals(0, stepExecution.getRollbackCount());

    // writer skips "4"
    assertTrue(reader.getRead().contains("4"));

    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here

   */
  @Test
  public void testWriteSkip() throws Exception {
    writer.setFailures("4");

    Step step = factory.getObject();

    step.execute(stepExecution);

    assertEquals(1, stepExecution.getSkipCount());
    assertEquals(0, stepExecution.getReadSkipCount());
    assertEquals(5, stepExecution.getReadCount());
    assertEquals(1, stepExecution.getWriteSkipCount());
    assertEquals(2, stepExecution.getRollbackCount());

    // writer skips "4"
    assertTrue(reader.getRead().contains("4"));
    assertFalse(writer.getCommitted().contains("4"));

    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("1,2,3,5"));
    assertEquals(expectedOutput, writer.getCommitted());

    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here

      public void write(List<? extends String> items) {
        throw new FatalRuntimeException("Ouch!");
      }
    });

    Step step = factory.getObject();

    step.execute(stepExecution);
    String message = stepExecution.getFailureExceptions().get(0).getCause().getMessage();
    assertEquals("Wrong message: ", "Ouch!", message);
    assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
        .getName()));
  }
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.Step

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.