BATCH-2072: Implemented wrapper for JSR-352 Decider

This commit is contained in:
Michael Minella
2013-08-12 09:11:02 -05:00
parent aa73805a24
commit 3f381ddb89
6 changed files with 419 additions and 126 deletions

View File

@@ -0,0 +1,100 @@
package org.springframework.batch.core.jsr.configuration.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import javax.batch.api.Decider;
import javax.batch.runtime.StepExecution;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.job.flow.FlowExecutionStatus;
import org.springframework.batch.core.job.flow.JobExecutionDecider;
import org.springframework.batch.core.job.flow.State;
import org.springframework.batch.core.job.flow.support.state.DecisionState;
public class DecisionStateFactoryBeanTests {
private DecisionStateFactoryBean factoryBean;
@Before
public void setUp() throws Exception {
factoryBean = new DecisionStateFactoryBean();
}
@Test
public void testGetObjectType() {
assertEquals(JobExecutionDecider.class, factoryBean.getObjectType());
}
@Test
public void testIsSingleton() {
assertTrue(factoryBean.isSingleton());
}
@Test(expected=IllegalArgumentException.class)
public void testNullDeciderAndName() throws Exception {
factoryBean.afterPropertiesSet();
}
@Test(expected=IllegalArgumentException.class)
public void testNullDecider() throws Exception{
factoryBean.setName("state1");
factoryBean.afterPropertiesSet();
}
@Test(expected=IllegalArgumentException.class)
public void testNullName() throws Exception {
factoryBean.setDecider(new DeciderSupport());
factoryBean.afterPropertiesSet();
}
@Test(expected=IllegalArgumentException.class)
public void setWrongDeciderType() {
factoryBean.setDecider("Some decider");
}
@Test
public void testJobExecutionDeciderState() throws Exception {
factoryBean.setDecider(new JobExecutionDeciderSupport());
factoryBean.setName("IL");
factoryBean.afterPropertiesSet();
State state = factoryBean.getObject();
assertEquals("IL", state.getName());
assertEquals(DecisionState.class, state.getClass());
}
@Test
public void testDeciderDeciderState() throws Exception {
factoryBean.setDecider(new DeciderSupport());
factoryBean.setName("IL");
factoryBean.afterPropertiesSet();
State state = factoryBean.getObject();
assertEquals("IL", state.getName());
assertEquals(DecisionState.class, state.getClass());
}
public static class DeciderSupport implements Decider {
@Override
public String decide(StepExecution[] executions) throws Exception {
return null;
}
}
public static class JobExecutionDeciderSupport implements JobExecutionDecider {
@Override
public FlowExecutionStatus decide(JobExecution jobExecution,
org.springframework.batch.core.StepExecution stepExecution) {
return null;
}
}
}

View File

@@ -24,6 +24,8 @@ import java.util.List;
import javax.batch.api.BatchProperty;
import javax.batch.api.Batchlet;
import javax.batch.api.Decider;
import javax.batch.api.chunk.CheckpointAlgorithm;
import javax.batch.api.chunk.ItemProcessor;
import javax.batch.api.chunk.ItemReader;
import javax.batch.api.chunk.ItemWriter;
@@ -37,13 +39,7 @@ import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.job.flow.FlowExecutionStatus;
import org.springframework.batch.core.job.flow.JobExecutionDecider;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.repeat.CompletionPolicy;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
@@ -335,32 +331,13 @@ public class JobPropertyTests {
}
}
public static final class TestCheckpointAlgorithm implements CompletionPolicy {
public static final class TestCheckpointAlgorithm implements CheckpointAlgorithm {
@Inject @BatchProperty String algorithmPropertyName1;
@Inject @BatchProperty String algorithmPropertyName2;
@Inject @BatchProperty(name = "annotationNamedAlgorithmPropertyName") String annotationNamedProperty;
@Inject @BatchProperty String notDefinedProperty;
@Inject @BatchProperty(name = "notDefinedAnnotationNamedProperty") String notDefinedAnnotationNamedProperty;
@Override
public boolean isComplete(RepeatContext context, RepeatStatus result) {
return true;
}
@Override
public boolean isComplete(RepeatContext context) {
return true;
}
@Override
public RepeatContext start(RepeatContext parent) {
return parent;
}
@Override
public void update(RepeatContext context) {
}
String getAlgorithmPropertyName1() {
return algorithmPropertyName1;
}
@@ -380,21 +357,33 @@ public class JobPropertyTests {
String getNotDefinedAnnotationNamedProperty() {
return notDefinedAnnotationNamedProperty;
}
@Override
public int checkpointTimeout() throws Exception {
return 0;
}
@Override
public void beginCheckpoint() throws Exception {
}
@Override
public boolean isReadyToCheckpoint() throws Exception {
return true;
}
@Override
public void endCheckpoint() throws Exception {
}
}
public static class TestDecider implements JobExecutionDecider {
public static class TestDecider implements Decider {
@Inject @BatchProperty String deciderPropertyName1;
@Inject @BatchProperty String deciderPropertyName2;
@Inject @BatchProperty(name = "annotationNamedDeciderPropertyName") String annotationNamedProperty;
@Inject @BatchProperty String notDefinedProperty;
@Inject @BatchProperty(name = "notDefinedAnnotationNamedProperty") String notDefinedAnnotationNamedProperty;
@Override
public FlowExecutionStatus decide(JobExecution jobExecution,
StepExecution stepExecution) {
return new FlowExecutionStatus("step2");
}
String getDeciderPropertyName1() {
return deciderPropertyName1;
}
@@ -414,6 +403,12 @@ public class JobPropertyTests {
String getNotDefinedAnnotationNamedProperty() {
return notDefinedAnnotationNamedProperty;
}
@Override
public String decide(javax.batch.runtime.StepExecution[] executions)
throws Exception {
return "step2";
}
}
public static class TestStepListener implements javax.batch.api.chunk.listener.ItemReadListener,