Java Reference
In-Depth Information
Listing 12-15. CarFileReaderIntegrationTest
package com.apress.springbatch.chapter12;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.test.MetaDataInstanceFactory;
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.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
@ContextConfiguration(locations = { "/test-context.xml" })
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
StepScopeTestExecutionListener.class })
@RunWith(SpringJUnit4ClassRunner.class)
public class CarFileReaderIntegrationTest {
@Autowired
private ItemReader<String> carFileReader;
@SuppressWarnings("serial")
private List<String> records = new ArrayList<String>() {{
add("1987,Nissan,Sentra");
add("1991,Plymouth,Laser");
add("1995,Mercury,Cougar");
add("2000,Infiniti,QX4");
add("2001,Infiniti,QX4");
}};
public StepExecution getStepExecution() {
JobParameters jobParams = new JobParametersBuilder().addString(
"carFile", "classpath:/data/carfile.txt").toJobParameters();
return MetaDataInstanceFactory.createStepExecution(jobParams);
}
Search WWH ::




Custom Search