Announcement Announcement Module
No announcement yet.
Mocking Step Scoped ItemReader Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mocking Step Scoped ItemReader

    Hi All,
    I need to mock a webservice rest client (webService.fetchFeed()) injected into my custom ItemReader to test a step.
    1. CustomeReader implements ItemReader<DataSet>
    2. Testing my step using below code.
    JobExecution exec = jobLauncherTestUtils.launchStep("step1", jobParameters);

    Code snapshot:
    private JobLauncherTestUtils jobLauncherTestUtils;

    private ItemReader<DataSet> reader;

    private WebService webService;

    public void testLaunchJob() throws Exception {
    webService = mock(WebService.class);

    when(webService.exportFeed(anyString())).thenRetur n(new DataSet())

    JobParameters jobParameters = new JobParametersBuilder().addString("statusId", "STAT_123").toJobParameters();

    JobExecution exec = jobLauncherTestUtils.launchStep("webProcessor", jobParameters);

    assertEquals(BatchStatus.COMPLETED, exec.getStatus());


    <bean id="customReader" class="com.batch.custom.CustomeReader " scope="step">
    <property name="providerId" value="#{jobParameters['statusId']}" />
    <property name="webService" ref="webService"/>
    public WatchlistDataSet read() throws Exception {"Entity Reader=>"+this);

    return webService.exportFeed(providerId);


    I need to inject the mocked webService into the CustomReader bean created when we launch the job. As my reader bean is step scoped, I am not getting hold of the reader. The reader instance in is different that the instance available inside my

    Could you please guide me on the approach to achieve this Step testing.
    Last edited by sam.tiku; Jun 30th, 2013, 06:27 AM.

  • #2
    See section 10.4 - Testing Step Scoped Components,