【发布时间】:2017-08-29 02:11:18
【问题描述】:
我正在尝试集成测试 ItemReader - 这是类:
@Slf4j
public class StudioReader implements ItemReader<List<Studio>> {
@Setter private zoneDao zoneDao;
@Getter @Setter private BatchContext context;
private AreaApi areaApi = new AreaApi();
public List<Studio> read() throws Exception {
return areaApi.getStudioLocations();
}
这是我的 bean.xml:
<bean class="org.springframework.batch.core.scope.StepScope" />
<bean id="ItemReader" class="com.sync.studio.reader.StudioReader" scope="step">
<property name="context" ref="BatchContext" />
<property name="zoneDao" ref="zoneDao" />
</bean>
这是我正在尝试编写的测试:
@ContextConfiguration(locations = {
"classpath:config/studio-beans.xml",
"classpath:config/test-context.xml"})
@TestExecutionListeners({
DependencyInjectionTestExecutionListener.class,
StepScopeTestExecutionListener.class })
public class StudioSyncReaderIT extends BaseTest {
@Autowired
private ItemReader<List<Studio>> reader;
public StepExecution getStepExecution() {
JobParameters jobParameters = new JobParametersBuilder()
.toJobParameters();
StepExecution execution = createStepExecution(
jobParameters);
return execution;
}
@Before
public void setUp() {
((ItemStream) reader).open(new ExecutionContext()); } //ClassCastException
@Test
@DirtiesContext
public void testReader() throws Exception {
assertNotNull(reader.read());
}
@After
public void tearDown() {
((ItemStream) reader).close(); //ClassCastException
}
}
我得到 java.lang.ClassCastException: com.sun.proxy.$Proxy36 cannot be cast to ItemReader on the Before and After。我错过了什么?我还需要为此设置什么(例如,配置 xml 中的任何注释或条目)?
【问题讨论】:
标签: spring-boot java-8 integration-testing spring-batch