BATCH-1285: Raise an exception if a step cannot be reached.

This commit is contained in:
dhgarrette
2009-06-11 05:15:59 +00:00
parent 8cabd9544f
commit 254c3b41f1
8 changed files with 190 additions and 37 deletions

View File

@@ -17,10 +17,12 @@ package org.springframework.batch.core.configuration.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.batch.core.Job;
@@ -29,6 +31,7 @@ import org.springframework.batch.core.job.AbstractJob;
import org.springframework.batch.core.listener.JobExecutionListenerSupport;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.SimpleJobRepository;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -40,8 +43,13 @@ import org.springframework.test.util.ReflectionTestUtils;
*/
public class JobParserTests {
ConfigurableApplicationContext jobParserParentAttributeTestsCtx = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests-context.xml");
private static ConfigurableApplicationContext jobParserParentAttributeTestsCtx;
@BeforeClass
public static void loadAppCtx() {
jobParserParentAttributeTestsCtx = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/JobParserParentAttributeTests-context.xml");
}
@Test
public void testInheritListeners() throws Exception {
@@ -136,4 +144,28 @@ public class JobParserTests {
assertTrue(jobRepository instanceof JobRepository);
return (JobRepository) jobRepository;
}
@Test
public void testUnreachableStep() {
try {
new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/JobParserUnreachableStepTests-context.xml");
fail("Error expected");
}
catch (BeanDefinitionParsingException e) {
assertTrue(e.getMessage().contains("The element [s2] is unreachable"));
}
}
@Test
public void testNextOutOfScope() {
try {
new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/JobParserNextOutOfScopeTests-context.xml");
fail("Error expected");
}
catch (BeanDefinitionParsingException e) {
assertTrue(e.getMessage().contains("Missing state for [StateTransition: [state=s2, pattern=*, next=s3]]"));
}
}
}

View File

@@ -21,6 +21,7 @@ import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.batch.core.Step;
@@ -52,8 +53,13 @@ import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
*/
public class StepParserTests {
private static final ApplicationContext stepParserParentAttributeTestsCtx = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/StepParserParentAttributeTests-context.xml");
private static ApplicationContext stepParserParentAttributeTestsCtx;
@BeforeClass
public static void loadAppCtx() {
stepParserParentAttributeTestsCtx = new ClassPathXmlApplicationContext(
"org/springframework/batch/core/configuration/xml/StepParserParentAttributeTests-context.xml");
}
@SuppressWarnings("unchecked")
@Test

View File

@@ -7,7 +7,7 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" parent="baseStep">
<step id="s1" parent="baseStep" next="s2">
<tasklet>
<chunk reader="reader" writer="writer" commit-interval="5" skip-limit="5">
<skippable-exception-classes merge="true">

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<beans:import resource="common-context.xml" />
<job id="job1">
<step id="s1" parent="step1" next="split1"/>
<split id="split1">
<flow>
<step id="s2" parent="step2" next="s3"/>
</flow>
<flow>
<step id="s3" parent="step3"/>
</flow>
</split>
</job>
</beans:beans>

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/batch" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<beans:import resource="common-context.xml" />
<job id="job1">
<step id="s1" parent="step1"/>
<step id="s2" parent="step2"/>
<step id="s3" parent="step3"/>
</job>
</beans:beans>

View File

@@ -7,7 +7,7 @@
<beans:import resource="common-context.xml" />
<job id="job">
<step id="s1" parent="baseStep">
<step id="s1" parent="baseStep" next="s2">
<tasklet ref="dummyTasklet">
<listeners merge="true">
<listener class="org.springframework.batch.core.configuration.xml.DummyAnnotationStepExecutionListener"/>

View File

@@ -35,11 +35,11 @@
<step id="s8" parent="standalone8" next="s9" />
<step id="s9" parent="standalone9" next="s10" />
<step id="s10" parent="standalone10" next="s11"/>
<step id="s11" parent="dummyStep"/>
<step id="s12" parent="dummyStep">
<step id="s11" parent="dummyStep" next="s12"/>
<step id="s12" parent="dummyStep" next="s13">
<tasklet ref="dummyTasklet"/>
</step>
<step id="s13" parent="dummyStepWithTaskletOnParent"/>
<step id="s13" parent="dummyStepWithTaskletOnParent" next="s14"/>
<step id="s14" parent="standaloneStepWithTaskletAndDummyParent"/>
</job>
@@ -104,20 +104,20 @@
</step>
<job id="jobWithoutRepo">
<step id="defaultRepoStep"><tasklet ref="dummyTasklet"/></step>
<step id="defaultRepoStepWithParent" parent="defaultRepoStandaloneStep"><tasklet ref="dummyTasklet"/></step>
<step id="defaultRepoStep" next="defaultRepoStepWithParent"><tasklet ref="dummyTasklet"/></step>
<step id="defaultRepoStepWithParent" parent="defaultRepoStandaloneStep" next="overrideRepoStep"><tasklet ref="dummyTasklet"/></step>
<step id="overrideRepoStep" parent="specifiedRepoStandaloneStep"><tasklet ref="dummyTasklet"/></step>
</job>
<job id="jobWithRepo" job-repository="dummyJobRepository">
<step id="injectedRepoStep"><tasklet ref="dummyTasklet"/></step>
<step id="injectedRepoStepWithParent" parent="defaultRepoStandaloneStep"><tasklet ref="dummyTasklet"/></step>
<step id="injectedRepoStep" next="injectedRepoStepWithParent"><tasklet ref="dummyTasklet"/></step>
<step id="injectedRepoStepWithParent" parent="defaultRepoStandaloneStep" next="injectedOverrideRepoStep"><tasklet ref="dummyTasklet"/></step>
<step id="injectedOverrideRepoStep" parent="specifiedRepoStandaloneStep"><tasklet ref="dummyTasklet"/></step>
</job>
<job id="jobWithRepoOnParent" parent="baseJobWithRepo">
<step id="injectedRepoFromParentStep"><tasklet ref="dummyTasklet"/></step>
<step id="injectedRepoFromParentStepWithParent" parent="defaultRepoStandaloneStep"><tasklet ref="dummyTasklet"/></step>
<step id="injectedRepoFromParentStep" next="injectedRepoFromParentStepWithParent"><tasklet ref="dummyTasklet"/></step>
<step id="injectedRepoFromParentStepWithParent" parent="defaultRepoStandaloneStep" next="injectedOverrideRepoFromParentStep"><tasklet ref="dummyTasklet"/></step>
<step id="injectedOverrideRepoFromParentStep" parent="specifiedRepoStandaloneStep"><tasklet ref="dummyTasklet"/></step>
</job>
@@ -135,9 +135,9 @@
<beans:bean id="dummyJobRepository2" class="org.springframework.batch.core.configuration.xml.DummyJobRepository"/>
<job id="defaultTxMgrTestJob">
<step id="defaultTxMgrStep"><tasklet ref="dummyTasklet"/></step>
<step id="specifiedTxMgrStep"><tasklet ref="dummyTasklet" transaction-manager="dummyTxMgr"/></step>
<step id="defaultTxMgrWithParentStep" parent="specifiedRepoStandaloneStep"/>
<step id="defaultTxMgrStep" next="specifiedTxMgrStep"><tasklet ref="dummyTasklet"/></step>
<step id="specifiedTxMgrStep" next="defaultTxMgrWithParentStep"><tasklet ref="dummyTasklet" transaction-manager="dummyTxMgr"/></step>
<step id="defaultTxMgrWithParentStep" parent="specifiedRepoStandaloneStep" next="overrideTxMgrOnParentStep"/>
<step id="overrideTxMgrOnParentStep" parent="specifiedRepoStandaloneStep"><tasklet transaction-manager="dummyTxMgr2"/></step>
</job>