BATCH-63:improved <chunk-oriented> tests
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
public class AbstractTestComponent {
|
||||
|
||||
protected boolean executed = false;
|
||||
|
||||
public AbstractTestComponent() {
|
||||
super();
|
||||
}
|
||||
|
||||
public boolean isExecuted() {
|
||||
return executed;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
/**
|
||||
* @author Thomas Risberg
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class StepWithChunkOrientedJobParserTests {
|
||||
|
||||
@Autowired
|
||||
private Job job;
|
||||
|
||||
@Autowired
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@Autowired
|
||||
private TestReader reader;
|
||||
|
||||
@Autowired
|
||||
private TestProcessor processor;
|
||||
|
||||
@Autowired
|
||||
private TestWriter writer;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MapJobRepositoryFactoryBean.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStepWithTask() throws Exception {
|
||||
assertNotNull(job);
|
||||
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
|
||||
job.execute(jobExecution);
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
assertEquals(1, jobExecution.getStepExecutions().size());
|
||||
assertTrue(reader.isExecuted());
|
||||
assertTrue(processor.isExecuted());
|
||||
assertTrue(writer.isExecuted());
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -33,7 +34,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Thomas Risberg
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@@ -46,6 +47,9 @@ public class StepWithTaskJobParserTests {
|
||||
@Autowired
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@Autowired
|
||||
private AbstractTestComponent tasklet;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MapJobRepositoryFactoryBean.clear();
|
||||
@@ -57,6 +61,7 @@ public class StepWithTaskJobParserTests {
|
||||
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
|
||||
job.execute(jobExecution);
|
||||
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
|
||||
assertEquals(3, jobExecution.getStepExecutions().size());
|
||||
assertEquals(2, jobExecution.getStepExecutions().size());
|
||||
assertTrue(tasklet.isExecuted());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.springframework.batch.core.configuration.xml;
|
||||
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
|
||||
public class TestProcessor extends AbstractTestComponent implements ItemProcessor<String, String>{
|
||||
|
||||
public String process(String item) throws Exception {
|
||||
executed = true;
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ParseException;
|
||||
import org.springframework.batch.item.UnexpectedInputException;
|
||||
|
||||
public class TestReader implements ItemReader<String> {
|
||||
public class TestReader extends AbstractTestComponent implements ItemReader<String> {
|
||||
|
||||
List<String> items = null;
|
||||
|
||||
@@ -21,6 +21,7 @@ public class TestReader implements ItemReader<String> {
|
||||
|
||||
public String read() throws Exception, UnexpectedInputException,
|
||||
ParseException {
|
||||
executed = true;
|
||||
if (items.size() > 0) {
|
||||
String item = items.remove(0);
|
||||
return item;
|
||||
|
||||
@@ -5,10 +5,11 @@ import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.core.AttributeAccessor;
|
||||
|
||||
public class DummyTasklet implements Tasklet {
|
||||
public class TestTasklet extends AbstractTestComponent implements Tasklet {
|
||||
|
||||
public ExitStatus execute(StepContribution contribution,
|
||||
AttributeAccessor attributes) throws Exception {
|
||||
executed = true;
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@ import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
|
||||
public class TestWriter implements ItemWriter<String> {
|
||||
public class TestWriter extends AbstractTestComponent implements ItemWriter<String> {
|
||||
|
||||
public void write(List<? extends String> items) throws Exception {
|
||||
executed = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user