org.springframework.batch.test.MetaDataInstanceFactory Java Examples

The following examples show how to use org.springframework.batch.test.MetaDataInstanceFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BatchJobConfigurationTest.java    From patient-batch-loader with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testWriter() throws Exception {
	PatientEntity entity = new PatientEntity("72739d22-3c12-539b-b3c2-13d9d4224d40",
		"Hettie",
		"P",
		"Schmidt",
		"[email protected]",
		"(805) 384-3727",
		"Hutij Terrace",
		"Kahgepu",
		"ID",
		"40239",
		LocalDate.of(1961, 6, 14),
		"071-81-2500");
	StepExecution execution = MetaDataInstanceFactory.createStepExecution();
       StepScopeTestUtils.doInStepScope(execution, () -> {
           writer.write(Arrays.asList(entity));
           return null;
       });
       assertTrue(patientRepository.findAll().size() > 0);
   }
 
Example #2
Source File: SpringBatchStepScopeIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenMockedStep_whenReaderCalled_thenSuccess() throws Exception {

    // given
    StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(defaultJobParameters());

    // when
    StepScopeTestUtils.doInStepScope(stepExecution, () -> {
        BookRecord bookRecord;
        itemReader.open(stepExecution.getExecutionContext());
        while ((bookRecord = itemReader.read()) != null) {

            // then
            assertThat(bookRecord.getBookName(), is("Foundation"));
            assertThat(bookRecord.getBookAuthor(), is("Asimov I."));
            assertThat(bookRecord.getBookISBN(), is("ISBN 12839"));
            assertThat(bookRecord.getBookFormat(), is("hardcover"));
            assertThat(bookRecord.getPublishingYear(), is("2018"));
        }
        itemReader.close();
        return null;
    });
}
 
Example #3
Source File: SpringBatchStepScopeIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenMockedStep_whenWriterCalled_thenSuccess() throws Exception {

    // given
    FileSystemResource expectedResult = new FileSystemResource(EXPECTED_OUTPUT_ONE);
    FileSystemResource actualResult = new FileSystemResource(TEST_OUTPUT);
    Book demoBook = new Book();
    demoBook.setAuthor("Grisham J.");
    demoBook.setName("The Firm");
    StepExecution stepExecution = MetaDataInstanceFactory.createStepExecution(defaultJobParameters());

    // when
    StepScopeTestUtils.doInStepScope(stepExecution, () -> {

        jsonItemWriter.open(stepExecution.getExecutionContext());
        jsonItemWriter.write(Arrays.asList(demoBook));
        jsonItemWriter.close();
        return null;
    });

    // then
    AssertFile.assertFileEquals(expectedResult, actualResult);
}
 
Example #4
Source File: BirthdayFilterProcessorTest.java    From spring-batch-article with MIT License 4 votes vote down vote up
public StepExecution getStepExecution() {
    log.info("getting step execution");
    return MetaDataInstanceFactory.createStepExecution();
}