concept Tasklet in category spring

appears as: Tasklet, Tasklet
Spring Batch in Action

This is an excerpt from Manning's book Spring Batch in Action.

Spring Batch provides an extension point to handle processing in a batch process step: the Tasklet. You implement a Tasklet that decompresses a ZIP archive into its source flat file. The following listing shows the implementation of the DecompressTasklet class.

Listing 11.3. The echo Tasklet

Test class

Spring Batch domain object

ImportValidatorTest JobParametersValidator
CompositeItemProcessorTest ItemProcessor
ProductFieldSetMapperTest ItemReader
PriceMandatoryValidatorTest Validator in an ItemProcessor
PositivePriceValidatorTest Validator in an ItemProcessor
ProductItemWriterMockTest ItemWriter
ProductItemListener StepListener
NextDeciderTest JobExecutionDecider
CleanTaskletTest Tasklet

The Test module opens up Spring Batch domain objects to be tested. Classes like JobExecutionDecider and Tasklet, for example, have APIs that require the types of objects supplied by MetaDataInstanceFactory.

Testing a Tasklet

You can also manipulate complex Spring Batch domain objects like a ChunkContext (a requirement of the Tasklet API) with the MetaDataInstanceFactory class. The following listing demonstrates testing such a tasklet.

Listing 14.12. Testing a simple tasklet with Spring Batch domain mocks

In the CleanTaskletTest class, you create a ChunkContext to test the Tasklet, which doesn’t require any dependencies. The implementation of the CleanTasklet class always returns RepeatStatus.FINISHED.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest