RESOLVED - BATCH-1404: archetype update

This commit is contained in:
robokaso
2009-09-15 19:41:27 +00:00
parent 4820c5bfc9
commit b689583ba8
4 changed files with 65 additions and 24 deletions

View File

@@ -76,6 +76,12 @@
<artifactId>spring-batch-infrastructure</artifactId>
<version>${spring.batch.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-test</artifactId>
<version>${spring.batch.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="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
xsi:schemaLocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<description>Example job to get you started. It provides a
skeleton for a typical batch application.</description>
<job id="job1" xmlns="http://www.springframework.org/schema/batch">
<job id="job1" xmlns="http://www.springframework.org/schema/batch" incrementer="jobParametersIncrementer">
<step id="step1" parent="simpleStep">
<tasklet>
<chunk reader="reader" writer="writer" />
@@ -17,6 +17,9 @@
<bean id="reader" class="example.ExampleItemReader" />
<bean id="writer" class="example.ExampleItemWriter" />
<!-- enables the functionality of JobOperator.startNextInstance(jobName) -->
<bean id="jobParametersIncrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer" />
<bean id="simpleStep"
class="org.springframework.batch.core.step.item.SimpleStepFactoryBean"

View File

@@ -7,6 +7,22 @@
<import resource="classpath:/META-INF/spring/module-context.xml"/>
<bean id="jobOperator"
class="org.springframework.batch.core.launch.support.SimpleJobOperator"
p:jobLauncher-ref="jobLauncher" p:jobExplorer-ref="jobExplorer"
p:jobRepository-ref="jobRepository" p:jobRegistry-ref="jobRegistry" />
<bean id="jobExplorer"
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"
p:dataSource-ref="dataSource" />
<bean id="jobRegistry"
class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
<bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
<property name="jobRegistry" ref="jobRegistry"/>
</bean>
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />

View File

@@ -15,39 +15,55 @@
*/
package example;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.batch.test.AbstractJobTests;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Dave Syer
*
*/
@ContextConfiguration(locations={"/launch-context.xml"})
@ContextConfiguration(locations = { "/launch-context.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
public class ExampleJobConfigurationTests {
@Autowired
private JobLauncher jobLauncher;
public class ExampleJobConfigurationTests extends AbstractJobTests {
@Autowired
private Job job;
@Test
public void testSimpleProperties() throws Exception {
assertNotNull(jobLauncher);
}
private JobOperator jobOperator;
/**
* Create a unique job instance and check it's execution completes
* successfully - uses the convenience methods provided by the testing
* superclass.
*/
@Test
public void testLaunchJob() throws Exception {
jobLauncher.run(job, new JobParameters());
JobExecution jobExecution = launchJob(getUniqueJobParameters());
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
}
/**
* Execute a fresh {@link JobInstance} using {@link JobOperator} - closer to
* a remote invocation scenario.
*/
@Test
public void testLaunchByJobOperator() throws Exception {
// assumes the job has a JobIncrementer set
long jobExecutionId = jobOperator.startNextInstance(getJob().getName());
// no need to wait for job completion in this case, the job is launched
// synchronously
String result = jobOperator.getSummary(jobExecutionId);
assertTrue(result.contains("status=" + BatchStatus.COMPLETED));
}
}