RESOLVED - issue BATCH-1481: Support injection of step-scoped dependencies into unit tests
Revert a few of the more complicated options: just support a factory method
This commit is contained in:
@@ -29,16 +29,12 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="itemReader" parent="itemReaderParent" scope="step" autowire-candidate="false">
|
||||
<bean id="itemReader" parent="itemReaderParent" scope="step">
|
||||
<property name="resource" value="#{jobParameters[fileName]}" />
|
||||
</bean>
|
||||
|
||||
<bean id="itemReaderForTest" parent="itemReaderParent" scope="prototype" >
|
||||
<property name="resource" value="data/iosample/input/delimited.csv" />
|
||||
</bean>
|
||||
|
||||
<bean id="itemWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
|
||||
<property name="resource" ref="outputResource" />
|
||||
<property name="resource" value="file:./target/test-outputs/delimitedOutput.csv" />
|
||||
<property name="lineAggregator">
|
||||
<bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
|
||||
<property name="delimiter" value=","/>
|
||||
@@ -50,9 +46,5 @@
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="outputResource" class="org.springframework.core.io.FileSystemResource">
|
||||
<constructor-arg value="target/test-outputs/delimitedOutput.csv" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -16,8 +16,11 @@ import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
import org.springframework.batch.sample.domain.trade.internal.CustomerCreditIncreaseProcessor;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.batch.test.StepScopeTestExecutionListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
|
||||
/**
|
||||
* Base class for IoSample tests that increase input customer credit by fixed
|
||||
@@ -27,6 +30,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/job-runner-context.xml", "/jobs/ioSampleJob.xml" })
|
||||
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, StepScopeTestExecutionListener.class})
|
||||
public abstract class AbstractIoSampleTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -16,14 +16,14 @@
|
||||
|
||||
package org.springframework.batch.sample.iosample;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.file.FlatFileItemReader;
|
||||
import org.springframework.batch.sample.domain.trade.CustomerCredit;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -35,13 +35,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration(locations = "/jobs/iosample/delimited.xml")
|
||||
public class DelimitedFunctionalTests extends AbstractIoSampleTests {
|
||||
|
||||
@Autowired
|
||||
private Resource outputResource;
|
||||
@SuppressWarnings("unused")
|
||||
private Map<String, String> jobParameters = Collections.singletonMap("fileName",
|
||||
"file:./target/test-outputs/delimitedOutput.csv");
|
||||
|
||||
@Override
|
||||
protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) {
|
||||
FlatFileItemReader<CustomerCredit> fileReader = (FlatFileItemReader<CustomerCredit>) reader;
|
||||
fileReader.setResource(outputResource);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user