BATCH-2072: Removed DecisionAdapter and replaced it with a DecisionStep and related classes

This commit is contained in:
Michael Minella
2013-08-20 20:07:11 -05:00
committed by Chris Schaefer
parent 3f85c34f00
commit 3201923299
17 changed files with 499 additions and 229 deletions

View File

@@ -17,16 +17,14 @@ package org.springframework.batch.core.jsr.configuration.xml;
import static org.junit.Assert.assertEquals;
import org.junit.Ignore;
import javax.batch.api.Decider;
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.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.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
@@ -43,19 +41,18 @@ public class DecisionParsingTests {
public JobLauncher jobLauncher;
@Test
@Ignore
public void test() throws Exception {
JobExecution execution = jobLauncher.run(job, new JobParameters());
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
assertEquals(2, execution.getStepExecutions().size());
assertEquals(3, execution.getStepExecutions().size());
}
public static class TestDecider implements JobExecutionDecider {
public static class JsrDecider implements Decider {
@Override
public FlowExecutionStatus decide(JobExecution jobExecution,
StepExecution stepExecution) {
return new FlowExecutionStatus("step2");
public String decide(javax.batch.runtime.StepExecution[] executions)
throws Exception {
return "next";
}
}
}

View File

@@ -1,100 +0,0 @@
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

@@ -0,0 +1,70 @@
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.Step;
import org.springframework.batch.core.jsr.step.DecisionStep;
public class DecisionStepFactoryBeanTests {
private DecisionStepFactoryBean factoryBean;
@Before
public void setUp() throws Exception {
factoryBean = new DecisionStepFactoryBean();
}
@Test
public void testGetObjectType() {
assertEquals(DecisionStep.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
public void testDeciderDeciderState() throws Exception {
factoryBean.setDecider(new DeciderSupport());
factoryBean.setName("IL");
factoryBean.afterPropertiesSet();
Step step = factoryBean.getObject();
assertEquals("IL", step.getName());
assertEquals(DecisionStep.class, step.getClass());
}
public static class DeciderSupport implements Decider {
@Override
public String decide(StepExecution[] executions) throws Exception {
return null;
}
}
}

View File

@@ -0,0 +1,122 @@
package org.springframework.batch.core.jsr.step;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.util.List;
import javax.batch.api.Decider;
import javax.batch.runtime.StepExecution;
import org.junit.Ignore;
import org.junit.Test;
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.launch.JobLauncher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
@SuppressWarnings("resource")
public class DecisionStepTests {
@Test
public void testDecisionAsFirstStepOfJob() throws Exception {
ApplicationContext context = new GenericXmlApplicationContext("classpath:/org/springframework/batch/core/jsr/step/DecisionStepTests-decisionAsFirstStep-context.xml");
JobLauncher launcher = context.getBean(JobLauncher.class);
Job job = context.getBean(Job.class);
JobExecution execution = launcher.run(job, new JobParameters());
assertEquals(BatchStatus.FAILED, execution.getStatus());
assertEquals(1, execution.getStepExecutions().size());
}
@Test
public void testDecisionThrowsException() throws Exception {
ApplicationContext context = new GenericXmlApplicationContext("classpath:/org/springframework/batch/core/jsr/step/DecisionStepTests-decisionThrowsException-context.xml");
JobLauncher launcher = context.getBean(JobLauncher.class);
Job job = context.getBean(Job.class);
JobExecution execution = launcher.run(job, new JobParameters());
assertEquals(BatchStatus.FAILED, execution.getStatus());
assertEquals(2, execution.getStepExecutions().size());
List<Throwable> allFailureExceptions = execution.getAllFailureExceptions();
boolean found = false;
for (Throwable throwable : allFailureExceptions) {
if(throwable.getMessage().equals("Expected")) {
found = true;
break;
}
}
if(!found) {
fail();
}
}
@Test
public void testDecisionValidExitStatus() throws Exception {
ApplicationContext context = new GenericXmlApplicationContext("classpath:/org/springframework/batch/core/jsr/step/DecisionStepTests-decisionValidExitStatus-context.xml");
JobLauncher launcher = context.getBean(JobLauncher.class);
Job job = context.getBean(Job.class);
JobExecution execution = launcher.run(job, new JobParameters());
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
assertEquals(3, execution.getStepExecutions().size());
}
@Test
public void testDecisionInvalidExitStatus() throws Exception {
ApplicationContext context = new GenericXmlApplicationContext("classpath:/org/springframework/batch/core/jsr/step/DecisionStepTests-decisionInvalidExitStatus-context.xml");
JobLauncher launcher = context.getBean(JobLauncher.class);
Job job = context.getBean(Job.class);
JobExecution execution = launcher.run(job, new JobParameters());
assertEquals(BatchStatus.FAILED, execution.getStatus());
assertEquals(2, execution.getStepExecutions().size());
for (org.springframework.batch.core.StepExecution curExecution : execution.getStepExecutions()) {
assertEquals(BatchStatus.COMPLETED, curExecution.getStatus());
}
}
@Test
@Ignore("Flows as first steps are not supported yet")
public void testDecisionAfterFlow() throws Exception {
ApplicationContext context = new GenericXmlApplicationContext("classpath:/org/springframework/batch/core/jsr/step/DecisionStepTests-decisionAfterFlow-context.xml");
JobLauncher launcher = context.getBean(JobLauncher.class);
Job job = context.getBean(Job.class);
JobExecution execution = launcher.run(job, new JobParameters());
assertEquals(BatchStatus.COMPLETED, execution.getStatus());
assertEquals(3, execution.getStepExecutions().size());
}
@Test
@Ignore("Splits are not implemented yet as part of our JSR implementation")
public void testDecisionAfterSplit() {
}
public static class NextDecider implements Decider {
@Override
public String decide(StepExecution[] executions) throws Exception {
return "next";
}
}
public static class FailureDecider implements Decider {
@Override
public String decide(StepExecution[] executions) throws Exception {
throw new RuntimeException("Expected");
}
}
}