BATCH-2624: add tests on mandatory item reader/writer

This commit is contained in:
Mahmoud Ben Hassine
2018-04-05 11:54:53 +02:00
committed by Mahmoud Ben Hassine
parent 3ccc4ff430
commit 2b0532e910
3 changed files with 58 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2017 the original author or authors.
* Copyright 2008-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,8 +27,10 @@ import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ChunkListener;
@@ -77,6 +79,9 @@ import static org.junit.Assert.assertTrue;
*/
public class FaultTolerantStepFactoryBeanTests {
@Rule
public ExpectedException expectedException = ExpectedException.none();
protected final Log logger = LogFactory.getLog(getClass());
private FaultTolerantStepFactoryBean<String, String> factory;
@@ -135,6 +140,28 @@ public class FaultTolerantStepFactoryBeanTests {
repository.add(stepExecution);
}
@Test
public void testMandatoryReader() throws Exception {
factory = new FaultTolerantStepFactoryBean<>();
factory.setItemWriter(writer);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("ItemReader must be provided");
factory.getObject();
}
@Test
public void testMandatoryWriter() throws Exception {
factory = new FaultTolerantStepFactoryBean<>();
factory.setItemReader(reader);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("ItemWriter must be provided");
factory.getObject();
}
/**
* Non-skippable (and non-fatal) exception causes failure immediately.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2017 the original author or authors.
* Copyright 2006-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,8 +27,9 @@ import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ChunkListener;
import org.springframework.batch.core.ItemProcessListener;
@@ -64,6 +65,9 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor;
*/
public class SimpleStepFactoryBeanTests {
@Rule
public ExpectedException expectedException = ExpectedException.none();
private List<Exception> listened = new ArrayList<Exception>();
private SimpleJobRepository repository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(),
@@ -78,7 +82,7 @@ public class SimpleStepFactoryBeanTests {
}
};
private ItemReader<String> reader;
private ItemReader<String> reader = new ListItemReader<>(Arrays.asList("a", "b", "c"));
private SimpleJob job = new SimpleJob();
@@ -93,6 +97,28 @@ public class SimpleStepFactoryBeanTests {
new SimpleStepFactoryBean<String, String>().getObject();
}
@Test
public void testMandatoryReader() throws Exception {
SimpleStepFactoryBean<String, String> factory = new SimpleStepFactoryBean<>();
factory.setItemWriter(writer);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("ItemReader must be provided");
factory.getObject();
}
@Test
public void testMandatoryWriter() throws Exception {
SimpleStepFactoryBean<String, String> factory = new SimpleStepFactoryBean<>();
factory.setItemReader(reader);
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("ItemWriter must be provided");
factory.getObject();
}
@Test
public void testSimpleJob() throws Exception {