BATCH-1775: fix inner bean definition parser inside <chunk/> element
This commit is contained in:
@@ -3,7 +3,14 @@ package org.springframework.batch.core.configuration.xml;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.scope.context.StepSynchronizationManager;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.adapter.ItemProcessorAdapter;
|
||||
import org.springframework.batch.item.adapter.ItemReaderAdapter;
|
||||
import org.springframework.batch.item.adapter.ItemWriterAdapter;
|
||||
@@ -17,12 +24,21 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
*/
|
||||
public class InlineItemHandlerParserTests {
|
||||
|
||||
private ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
|
||||
"org/springframework/batch/core/configuration/xml/InlineItemHandlerParserTests-context.xml");
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
StepSynchronizationManager.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineHandlers() throws Exception {
|
||||
Object step = ctx.getBean("inlineHandlers");
|
||||
context = new ClassPathXmlApplicationContext(
|
||||
"org/springframework/batch/core/configuration/xml/InlineItemHandlerParserTests-context.xml");
|
||||
Object step = context.getBean("inlineHandlers");
|
||||
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
|
||||
Object chunkProvider = ReflectionTestUtils.getField(tasklet, "chunkProvider");
|
||||
Object reader = ReflectionTestUtils.getField(chunkProvider, "itemReader");
|
||||
@@ -37,7 +53,9 @@ public class InlineItemHandlerParserTests {
|
||||
|
||||
@Test
|
||||
public void testInlineAdapters() throws Exception {
|
||||
Object step = ctx.getBean("inlineAdapters");
|
||||
context = new ClassPathXmlApplicationContext(
|
||||
"org/springframework/batch/core/configuration/xml/InlineItemHandlerParserTests-context.xml");
|
||||
Object step = context.getBean("inlineAdapters");
|
||||
Object tasklet = ReflectionTestUtils.getField(step, "tasklet");
|
||||
Object chunkProvider = ReflectionTestUtils.getField(tasklet, "chunkProvider");
|
||||
Object reader = ReflectionTestUtils.getField(chunkProvider, "itemReader");
|
||||
@@ -64,4 +82,17 @@ public class InlineItemHandlerParserTests {
|
||||
assertEquals("dummyWrite", writerMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineHandlersWithStepScope() throws Exception {
|
||||
context = new ClassPathXmlApplicationContext(
|
||||
"org/springframework/batch/core/configuration/xml/InlineItemHandlerWithStepScopeParserTests-context.xml");
|
||||
StepSynchronizationManager.register(new StepExecution("step", new JobExecution(123L)));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String,ItemReader<?>> readers = context.getBeansOfType(ItemReader.class);
|
||||
// Should be 2 each (proxy and target) for the two readers in the steps defined
|
||||
assertEquals(4, readers.size());
|
||||
// System.err.println(readers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user