Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BATCH-1935: Add quick start maven archetype

  • Loading branch information...
commit c1be0af6fca533506d01b80fe8df95510d77df95 1 parent f1a8250
@chrisjs chrisjs authored mminella committed
Showing with 656 additions and 675 deletions.
  1. +1 −0  .gitignore
  2. +1 −2  archetypes/pom.xml
  3. +297 −258 archetypes/simple-cli/pom.xml
  4. +25 −0 archetypes/simple-cli/src/main/assembly/descriptor.xml
  5. +0 −27 archetypes/simple-cli/src/main/java/example/ExampleItemReader.java
  6. +0 −24 archetypes/simple-cli/src/main/java/example/ExampleItemWriter.java
  7. +47 −0 archetypes/simple-cli/src/main/java/example/Person.java
  8. +38 −0 archetypes/simple-cli/src/main/java/example/PersonItemProcessor.java
  9. +0 −179 archetypes/simple-cli/src/main/java/test/jdbc/datasource/DataSourceInitializer.java
  10. +19 −32 archetypes/simple-cli/src/main/resources/META-INF/spring/module-context.xml
  11. +6 −2 archetypes/simple-cli/src/main/resources/batch.properties
  12. +68 −58 archetypes/simple-cli/src/main/resources/launch-context.xml
  13. +0 −5 archetypes/simple-cli/src/main/resources/log4j.properties
  14. +7 −0 archetypes/simple-cli/src/main/resources/support/person.sql
  15. +5 −0 archetypes/simple-cli/src/main/resources/support/sample-data.csv
  16. +8 −0 archetypes/simple-cli/src/main/scripts/runJob.bat
  17. +8 −0 archetypes/simple-cli/src/main/scripts/runJob.sh
  18. +15 −20 archetypes/simple-cli/src/site/site.xml
  19. +0 −18 archetypes/simple-cli/src/test/java/example/ExampleItemReaderTests.java
  20. +0 −13 archetypes/simple-cli/src/test/java/example/ExampleItemWriterTests.java
  21. +38 −0 archetypes/simple-cli/src/test/java/example/PersonItemProcessorTest.java
  22. +36 −25 ...simple-cli/src/test/java/example/{ExampleJobConfigurationTests.java → PersonJobConfigurationTest.java}
  23. +37 −12 archetypes/simple-cli/src/test/resources/test-context.xml
View
1  .gitignore
@@ -18,4 +18,5 @@ s3.properties
*.ipr
*.iws
.*.swp
+.DS_Store
View
3  archetypes/pom.xml
@@ -5,8 +5,7 @@
<packaging>pom</packaging>
<name>Archetypes</name>
<url>http://static.springframework.org/spring-batch/${artifactId}</url>
- <description> Spring Batch archetypes are simple project templates containing just enough code to get you started running a job. For more detailed examples of using particular features of the framework, look at the Spring Batch Samples project. Currently the archetypes are deployed as regular Maven projects (not archetypes), because of limitations in the archetype plugin (or our understanding of how it works). For most effective use, copy one into Eclipse and use Q4E to manage the dependencies.
- </description>
+ <description>Spring Batch archetypes are simple project templates containing just enough code to get you started running a job. For more detailed examples of using particular features of the framework, look at the Spring Batch Samples project. Currently the archetypes are deployed as regular Maven projects (not archetypes), because of limitations in the archetype plugin (or our understanding of how it works). For most effective use, copy one into Eclipse and use Q4E to manage the dependencies.</description>
<parent>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-parent</artifactId>
View
555 archetypes/simple-cli/pom.xml
@@ -1,260 +1,299 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.springframework.batch</groupId>
- <artifactId>spring-batch-simple-cli</artifactId>
- <version>2.2.0.BUILD-SNAPSHOT</version>
- <packaging>jar</packaging>
- <name>Commandline</name>
- <url>http://www.springframework.org/spring-batch/archetypes/simple-cli-archetype</url>
- <description>This project is a minimal command line batch sample from
- Spring Batch. Once installed you can use "mvn exec:java" to
- see the job run; or if you ship the lib directory you can put
- the project jar on the classpath and run the
- CommandLineJobRunner directly or with "java -jar launch-context.xml job1".</description>
- <properties>
- <spring.framework.version>3.2.0.RELEASE</spring.framework.version>
- <spring.batch.version>2.2.0.BUILD-SNAPSHOT</spring.batch.version>
- <dependency.locations.enabled>false</dependency.locations.enabled>
- <junit.version>4.10</junit.version>
- </properties>
- <profiles>
- <profile>
- <id>staging</id>
- <distributionManagement>
- <repository>
- <id>staging</id>
- <url>file:///${user.dir}/target/staging</url>
- </repository>
- <snapshotRepository>
- <id>staging</id>
- <url>file:///${user.dir}/target/staging</url>
- </snapshotRepository>
- </distributionManagement>
- </profile>
- <profile>
- <id>bootstrap</id>
- <pluginRepositories>
- <pluginRepository>
- <id>Codehaus</id>
- <url>http://repository.codehaus.org/</url>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </pluginRepository>
- </pluginRepositories>
- </profile>
- </profiles>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-test</artifactId>
- <version>${spring.framework.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>${spring.framework.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aop</artifactId>
- <version>${spring.framework.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-jdbc</artifactId>
- <version>${spring.framework.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.batch</groupId>
- <artifactId>spring-batch-core</artifactId>
- <version>${spring.batch.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.batch</groupId>
- <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>
- <version>1.2.2</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.5.8</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.14</version>
- <optional>true</optional>
- </dependency>
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>1.4</version>
- </dependency>
- <dependency>
- <groupId>hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- <version>1.8.0.7</version>
- </dependency>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjrt</artifactId>
- <version>1.5.4</version>
- </dependency>
- <dependency>
- <groupId>org.aspectj</groupId>
- <artifactId>aspectjweaver</artifactId>
- <version>1.5.4</version>
- </dependency>
- </dependencies>
- <build>
- <extensions>
- <extension>
- <groupId>org.springframework.build.aws</groupId>
- <artifactId>org.springframework.build.aws.maven</artifactId>
- <version>3.0.0.RELEASE</version>
- </extension>
- </extensions>
- <pluginManagement>
- <plugins>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <inherited>false</inherited>
- <configuration>
- <descriptorRefs>
- <descriptorRef>project</descriptorRef>
- </descriptorRefs>
- </configuration>
- </plugin>
- <!--This plugin's configuration is used to store Eclipse m2e settings
- only. It has no influence on the Maven build itself. -->
- <plugin>
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <versionRange>[1.0,)</versionRange>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore />
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <includes>
- <include>**/*Tests.java</include>
- </includes>
- <excludes>
- <exclude>**/Abstract*.java</exclude>
- </excludes>
- <junitArtifactName>junit:junit</junitArtifactName>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>exec-maven-plugin</artifactId>
- <version>1.1</version>
- <configuration>
- <mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass>
- <arguments>
- <argument>classpath:/launch-context.xml</argument>
- <argument>job1</argument>
- </arguments>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-dependencies</id>
- <phase>package</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.directory}/lib</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <index>false</index>
- <manifest>
- <mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass>
- <addClasspath>true</addClasspath>
- <classpathPrefix>lib/</classpathPrefix>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <distributionManagement>
- <downloadUrl>http://www.springframework.org/download</downloadUrl>
- <site>
- <id>staging</id>
- <url>file:///${user.dir}/target/staging/org.springframework.batch.archetype/${pom.artifactId}</url>
- </site>
- <repository>
- <id>spring-release</id>
- <name>Spring Release Repository</name>
- <url>file:///${user.dir}/target/staging/release</url>
- </repository>
- <snapshotRepository>
- <id>spring-snapshot</id>
- <name>Spring Snapshot Repository</name>
- <url>file:///${user.dir}/target/staging/snapshot</url>
- </snapshotRepository>
- </distributionManagement>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.springframework.batch</groupId>
+ <artifactId>spring-batch-simple-cli</artifactId>
+ <version>2.2.0.BUILD-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Commandline</name>
+ <url>http://www.springframework.org/spring-batch/archetypes/simple-cli-archetype</url>
+ <description>This project is a command line batch sample from Spring Batch demonstrating a typical batch job.
+ The job can be invoked via "mvn exec:java" to see the job run from the command line.
+ During an "mvn package", a distribution archive in the format defined in src/main/assembly/descriptor.xml will
+ be created in the target directory which can be deployed and extracted to your target location of choice.
+ The ./bin/runJob.(sh|bat) script from the extracted deployment archive can be invoked to run the job.
+ </description>
+ <properties>
+ <spring.framework.version>3.2.0.RELEASE</spring.framework.version>
+ <spring.batch.version>2.2.0.BUILD-SNAPSHOT</spring.batch.version>
+ <dependency.locations.enabled>false</dependency.locations.enabled>
+ <junit.version>4.10</junit.version>
+ <compiler.target.version>1.6</compiler.target.version>
+ <compiler.source.version>1.6</compiler.source.version>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <profiles>
+ <profile>
+ <id>staging</id>
+ <distributionManagement>
+ <repository>
+ <id>staging</id>
+ <url>file:///${user.dir}/target/staging</url>
+ </repository>
+ <snapshotRepository>
+ <id>staging</id>
+ <url>file:///${user.dir}/target/staging</url>
+ </snapshotRepository>
+ </distributionManagement>
+ </profile>
+ <profile>
+ <id>bootstrap</id>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>Codehaus</id>
+ <url>http://repository.codehaus.org/</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </pluginRepository>
+ <pluginRepository>
+ <id>com.springsource.repository.bundles.release</id>
+ <name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
+ <url>http://repository.springsource.com/maven/bundles/release</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${spring.framework.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring.framework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <version>${spring.framework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.batch</groupId>
+ <artifactId>spring-batch-core</artifactId>
+ <version>${spring.batch.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.batch</groupId>
+ <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>
+ <version>1.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.8</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ <version>1.6.8</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
+ <version>1.6.8</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <extensions>
+ <extension>
+ <groupId>org.springframework.build.aws</groupId>
+ <artifactId>org.springframework.build.aws.maven</artifactId>
+ <version>3.0.0.RELEASE</version>
+ </extension>
+ </extensions>
+ <pluginManagement>
+ <plugins>
+ <!--This plugin's configuration is used to store Eclipse m2e settings
+ only. It has no influence on the Maven build itself. -->
+ <plugin>
+ <groupId>org.eclipse.m2e</groupId>
+ <artifactId>lifecycle-mapping</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>com.springsource.bundlor</groupId>
+ <artifactId>com.springsource.bundlor.maven</artifactId>
+ <versionRange>[1.0,)</versionRange>
+ <goals>
+ <goal>bundlor</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore/>
+ </action>
+ </pluginExecution>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <versionRange>[1.0,)</versionRange>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <ignore/>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+ </lifecycleMappingMetadata>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>${compiler.source.version}</source>
+ <target>${compiler.target.version}</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.springsource.bundlor</groupId>
+ <artifactId>com.springsource.bundlor.maven</artifactId>
+ <version>1.0.0.RELEASE</version>
+ <executions>
+ <execution>
+ <id>bundlor-transform</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>bundlor</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.13</version>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.1</version>
+ <configuration>
+ <mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass>
+ <arguments>
+ <argument>classpath:/launch-context.xml</argument>
+ <argument>personJob</argument>
+ </arguments>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <descriptors>
+ <descriptor>src/main/assembly/descriptor.xml</descriptor>
+ </descriptors>
+ </configuration>
+ <executions>
+ <execution>
+ <id>make-distribution</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/lib</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.1</version>
+ <configuration>
+ <archive>
+ <index>false</index>
+ <manifest>
+ <mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass>
+ <addClasspath>true</addClasspath>
+ <classpathPrefix>lib/</classpathPrefix>
+ </manifest>
+ <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <distributionManagement>
+ <downloadUrl>http://www.springframework.org/download</downloadUrl>
+ <site>
+ <id>staging</id>
+ <url>file:///${user.dir}/target/staging/org.springframework.batch.archetype/${project.artifactId}</url>
+ </site>
+ <repository>
+ <id>spring-release</id>
+ <name>Spring Release Repository</name>
+ <url>file:///${user.dir}/target/staging/release</url>
+ </repository>
+ <snapshotRepository>
+ <id>spring-snapshot</id>
+ <name>Spring Snapshot Repository</name>
+ <url>file:///${user.dir}/target/staging/snapshot</url>
+ </snapshotRepository>
+ </distributionManagement>
</project>
View
25 archetypes/simple-cli/src/main/assembly/descriptor.xml
@@ -0,0 +1,25 @@
+<assembly>
+ <id>distribution</id>
+ <formats>
+ <format>tar.gz</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <fileSets>
+ <fileSet>
+ <directory>src/main/scripts</directory>
+ <outputDirectory>bin</outputDirectory>
+ <useDefaultExcludes>true</useDefaultExcludes>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/resources</directory>
+ <outputDirectory>resources</outputDirectory>
+ <useDefaultExcludes>true</useDefaultExcludes>
+ <filtered>true</filtered>
+ </fileSet>
+ </fileSets>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>lib</outputDirectory>
+ </dependencySet>
+ </dependencySets>
+</assembly>
View
27 archetypes/simple-cli/src/main/java/example/ExampleItemReader.java
@@ -1,27 +0,0 @@
-package example;
-
-import org.springframework.batch.item.ItemReader;
-
-/**
- * {@link ItemReader} with hard-coded input data.
- */
-public class ExampleItemReader implements ItemReader<String> {
-
- private String[] input = {"Hello world!", null};
-
- private int index = 0;
-
- /**
- * Reads next record from input
- */
- public String read() throws Exception {
- if (index < input.length) {
- return input[index++];
- }
- else {
- return null;
- }
-
- }
-
-}
View
24 archetypes/simple-cli/src/main/java/example/ExampleItemWriter.java
@@ -1,24 +0,0 @@
-package example;
-
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.batch.item.ItemWriter;
-
-
-/**
- * Dummy {@link ItemWriter} which only logs data it receives.
- */
-public class ExampleItemWriter implements ItemWriter<Object> {
-
- private static final Log log = LogFactory.getLog(ExampleItemWriter.class);
-
- /**
- * @see ItemWriter#write(Object)
- */
- public void write(List<? extends Object> data) throws Exception {
- log.info(data);
- }
-
-}
View
47 archetypes/simple-cli/src/main/java/example/Person.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2013 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 example;
+
+/**
+ * <p>
+ * Domain object representing information about a person.
+ * </p>
+ */
+public class Person {
+ private String lastName;
+ private String firstName;
+
+ public void setFirstName(final String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setLastName(final String lastName) {
+ this.lastName = lastName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ @Override
+ public String toString() {
+ return "firstName: " + firstName + ", lastName: " + lastName;
+ }
+}
View
38 archetypes/simple-cli/src/main/java/example/PersonItemProcessor.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2013 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 example;
+
+import org.springframework.batch.item.ItemProcessor;
+
+/**
+ * <p>
+ * An example {@link org.springframework.batch.item.ItemProcessor} implementation that upper cases attributes on the
+ * provided {@link Person} object.
+ * </p>
+ */
+public class PersonItemProcessor implements ItemProcessor<Person, Person> {
+ @Override
+ public Person process(final Person person) throws Exception {
+ final String firstName = person.getFirstName().toUpperCase();
+ final String lastName = person.getLastName().toUpperCase();
+
+ final Person transformedPerson = new Person();
+ transformedPerson.setFirstName(firstName);
+ transformedPerson.setLastName(lastName);
+
+ return transformedPerson;
+ }
+}
View
179 archetypes/simple-cli/src/main/java/test/jdbc/datasource/DataSourceInitializer.java
@@ -1,179 +0,0 @@
-/*
- * 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 test.jdbc.datasource;
-
-import java.io.IOException;
-import java.util.List;
-
-import javax.sql.DataSource;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.BeanInitializationException;
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.core.io.Resource;
-import org.springframework.dao.DataAccessException;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.datasource.DataSourceTransactionManager;
-import org.springframework.transaction.TransactionStatus;
-import org.springframework.transaction.support.TransactionCallback;
-import org.springframework.transaction.support.TransactionTemplate;
-import org.springframework.util.Assert;
-import org.springframework.util.StringUtils;
-
-/**
- * Wrapper for a {@link DataSource} that can run scripts on start up and shut
- * down. Us as a bean definition <br/><br/>
- *
- * Run this class to initialize a database in a running server process.
- * Make sure the server is running first by launching the "hsql-server" from the
- * <code>hsql.server</code> project. Then you can right click in Eclipse and
- * Run As -&gt; Java Application. Do the same any time you want to wipe the
- * database and start again.
- *
- * @author Dave Syer
- *
- */
-public class DataSourceInitializer implements InitializingBean, DisposableBean {
-
- private static final Log logger = LogFactory.getLog(DataSourceInitializer.class);
-
- private Resource[] initScripts;
-
- private Resource[] destroyScripts;
-
- private DataSource dataSource;
-
- private boolean ignoreFailedDrop = true;
-
- private static boolean initialized = false;
-
- /**
- * @throws Throwable
- * @see java.lang.Object#finalize()
- */
- protected void finalize() throws Throwable {
- super.finalize();
- initialized = false;
- logger.debug("finalize called");
- }
-
- public void destroy() {
- if (destroyScripts==null) return;
- for (int i = 0; i < destroyScripts.length; i++) {
- Resource destroyScript = destroyScripts[i];
- try {
- doExecuteScript(destroyScript);
- }
- catch (Exception e) {
- if (logger.isDebugEnabled()) {
- logger.warn("Could not execute destroy script [" + destroyScript + "]", e);
- }
- else {
- logger.warn("Could not execute destroy script [" + destroyScript + "]");
- }
- }
- }
- }
-
- public void afterPropertiesSet() throws Exception {
- Assert.notNull(dataSource);
- initialize();
- }
-
- private void initialize() {
- if (!initialized) {
- destroy();
- if (initScripts != null) {
- for (int i = 0; i < initScripts.length; i++) {
- Resource initScript = initScripts[i];
- doExecuteScript(initScript);
- }
- }
- initialized = true;
- }
- }
-
- private void doExecuteScript(final Resource scriptResource) {
- if (scriptResource == null || !scriptResource.exists())
- return;
- TransactionTemplate transactionTemplate = new TransactionTemplate(new DataSourceTransactionManager(dataSource));
- transactionTemplate.execute(new TransactionCallback() {
-
- @SuppressWarnings("unchecked")
- public Object doInTransaction(TransactionStatus status) {
- JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
- String[] scripts;
- try {
- scripts = StringUtils.delimitedListToStringArray(stripComments(IOUtils.readLines(scriptResource
- .getInputStream())), ";");
- }
- catch (IOException e) {
- throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e);
- }
- for (int i = 0; i < scripts.length; i++) {
- String script = scripts[i].trim();
- if (StringUtils.hasText(script)) {
- try {
- jdbcTemplate.execute(script);
- }
- catch (DataAccessException e) {
- if (ignoreFailedDrop && script.toLowerCase().startsWith("drop")) {
- logger.debug("DROP script failed (ignoring): " + script);
- }
- else {
- throw e;
- }
- }
- }
- }
- return null;
- }
-
- });
-
- }
-
- private String stripComments(List<String> list) {
- StringBuffer buffer = new StringBuffer();
- for (String line : list) {
- if (!line.startsWith("//") && !line.startsWith("--")) {
- buffer.append(line + "\n");
- }
- }
- return buffer.toString();
- }
-
- public void setInitScripts(Resource[] initScripts) {
- this.initScripts = initScripts;
- }
-
- public void setDestroyScripts(Resource[] destroyScripts) {
- this.destroyScripts = destroyScripts;
- }
-
- public void setDataSource(DataSource dataSource) {
- this.dataSource = dataSource;
- }
-
- public void setIgnoreFailedDrop(boolean ignoreFailedDrop) {
- this.ignoreFailedDrop = ignoreFailedDrop;
- }
-
-}
View
51 archetypes/simple-cli/src/main/resources/META-INF/spring/module-context.xml
@@ -1,35 +1,22 @@
<?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.1.xsd
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
+<beans:beans
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:batch="http://www.springframework.org/schema/batch"
+ 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-3.2.xsd">
- <description>Example job to get you started. It provides a
- skeleton for
- a typical batch application.
- </description>
+ <beans:description>Example job providing a skeleton for a typical batch application.</beans:description>
- <job id="job1" xmlns="http://www.springframework.org/schema/batch"
- incrementer="jobParametersIncrementer">
- <step id="step1" parent="simpleStep">
- <tasklet>
- <chunk reader="reader" writer="writer" />
- </tasklet>
- </step>
- </job>
-
- <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.factory.SimpleStepFactoryBean" abstract="true">
- <property name="transactionManager" ref="transactionManager" />
- <property name="jobRepository" ref="jobRepository" />
- <property name="startLimit" value="100" />
- <property name="commitInterval" value="1" />
- </bean>
-
-</beans>
+ <batch:job id="personJob" incrementer="jobParametersIncrementer">
+ <batch:step id="step1">
+ <batch:tasklet>
+ <batch:chunk reader="itemReader" processor="itemProcessor" writer="itemWriter"
+ commit-interval="${step1.commit.interval}"/>
+ </batch:tasklet>
+ <batch:fail on="FAILED"/>
+ <batch:end on="*"/>
+ </batch:step>
+ </batch:job>
+</beans:beans>
View
8 archetypes/simple-cli/src/main/resources/batch.properties
@@ -7,5 +7,9 @@ batch.jdbc.url=jdbc:hsqldb:mem:testdb;sql.enforce_strict_size=true
# batch.jdbc.url=jdbc:hsqldb:hsql://localhost:9005/samples
batch.jdbc.user=sa
batch.jdbc.password=
-batch.schema=
-batch.schema.script=org/springframework/batch/core/schema-hsqldb.sql
+batch.schema.script=classpath:org/springframework/batch/core/schema-hsqldb.sql
+batch.drop.script=classpath:org/springframework/batch/core/schema-drop-hsqldb.sql
+person.sql.location=classpath:support/person.sql
+person.test.data.location=classpath:support/sample-data.csv
+person.insert.sql=INSERT INTO people (first_name, last_name) VALUES (:firstName, :lastName)
+step1.commit.interval=5
View
126 archetypes/simple-cli/src/main/resources/launch-context.xml
@@ -1,59 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:p="http://www.springframework.org/schema/p"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
-
- <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" />
- </bean>
-
- <bean id="jobRepository"
- class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean"
- p:dataSource-ref="dataSource" p:transactionManager-ref="transactionManager" />
-
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
- <property name="driverClassName" value="${batch.jdbc.driver}" />
- <property name="url" value="${batch.jdbc.url}" />
- <property name="username" value="${batch.jdbc.user}" />
- <property name="password" value="${batch.jdbc.password}" />
- </bean>
-
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" lazy-init="true">
- <property name="dataSource" ref="dataSource" />
- </bean>
-
- <bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="location" value="classpath:batch.properties" />
- <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
- <property name="ignoreUnresolvablePlaceholders" value="true" />
- <property name="order" value="1" />
- </bean>
-
- <!-- Initialize the datasource - remove this bean definition for production use! -->
- <bean id="dataSourceInitializer" class="test.jdbc.datasource.DataSourceInitializer">
- <property name="dataSource" ref="dataSource"/>
- <property name="initScripts" value="${batch.schema.script}"/>
- </bean>
-
-</beans>
+
+<beans:beans
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:jdbc="http://www.springframework.org/schema/jdbc"
+ xmlns:batch="http://www.springframework.org/schema/batch"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:p="http://www.springframework.org/schema/p"
+ 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-3.1.xsd
+ http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
+
+ <beans:import resource="classpath:META-INF/spring/module-context.xml"/>
+
+ <context:property-placeholder location="classpath:batch.properties"/>
+
+ <jdbc:initialize-database data-source="dataSource">
+ <jdbc:script location="${batch.drop.script}"/>
+ <jdbc:script location="${person.sql.location}"/>
+ <jdbc:script location="${batch.schema.script}"/>
+ </jdbc:initialize-database>
+
+ <batch:job-repository id="jobRepository"/>
+
+ <beans:bean id="itemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
+ <beans:property name="resource" value="${person.test.data.location}"/>
+ <beans:property name="lineMapper">
+ <beans:bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
+ <beans:property name="lineTokenizer">
+ <beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
+ <beans:property name="names" value="firstName,lastName"/>
+ </beans:bean>
+ </beans:property>
+ <beans:property name="fieldSetMapper">
+ <beans:bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
+ <beans:property name="targetType" value="example.Person"/>
+ </beans:bean>
+ </beans:property>
+ </beans:bean>
+ </beans:property>
+ </beans:bean>
+
+ <beans:bean id="itemProcessor" class="example.PersonItemProcessor"/>
+
+ <beans:bean id="itemWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
+ <beans:property name="itemSqlParameterSourceProvider">
+ <beans:bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
+ </beans:property>
+ <beans:property name="sql" value="${person.insert.sql}" />
+ <beans:property name="dataSource" ref="dataSource" />
+ </beans:bean>
+
+ <beans:bean id="jobParametersIncrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer" />
+
+ <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
+ p:driverClassName="${batch.jdbc.driver}"
+ p:url="${batch.jdbc.url}"
+ p:username="${batch.jdbc.user}"
+ p:password="${batch.jdbc.password}"/>
+
+ <beans:bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
+ p:dataSource-ref="dataSource"/>
+
+ <beans:bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"
+ p:jobRepository-ref="jobRepository"/>
+</beans:beans>
View
5 archetypes/simple-cli/src/main/resources/log4j.properties
@@ -4,10 +4,5 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p %t [%c] - <%m>%n
-log4j.category.org.apache.activemq=ERROR
log4j.category.org.springframework.batch=DEBUG
log4j.category.org.springframework.transaction=INFO
-
-log4j.category.org.hibernate.SQL=DEBUG
-# for debugging datasource initialization
-# log4j.category.test.jdbc=DEBUG
View
7 archetypes/simple-cli/src/main/resources/support/person.sql
@@ -0,0 +1,7 @@
+DROP TABLE people IF EXISTS;
+
+CREATE TABLE people (
+ person_id BIGINT IDENTITY NOT NULL PRIMARY KEY,
+ first_name VARCHAR(20),
+ last_name VARCHAR(20)
+);
View
5 archetypes/simple-cli/src/main/resources/support/sample-data.csv
@@ -0,0 +1,5 @@
+Jill,Doe
+Joe,Doe
+Justin,Doe
+Jane,Doe
+John,Doe
View
8 archetypes/simple-cli/src/main/scripts/runJob.bat
@@ -0,0 +1,8 @@
+@echo off
+
+IF NOT DEFINED JAVA_HOME (
+ echo Error: JAVA_HOME environment variable is not set.
+ EXIT /B
+)
+
+%JAVA_HOME%\bin\java -cp resources\;lib\* org.springframework.batch.core.launch.support.CommandLineJobRunner classpath:/launch-context.xml personJob
View
8 archetypes/simple-cli/src/main/scripts/runJob.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+if [ "$JAVA_HOME" = "" ]; then
+ echo "Error: JAVA_HOME environment variable is not set."
+ exit 1
+fi
+
+$JAVA_HOME/bin/java -cp resources/:lib/* org.springframework.batch.core.launch.support.CommandLineJobRunner classpath:/launch-context.xml personJob
View
35 archetypes/simple-cli/src/site/site.xml
@@ -1,25 +1,20 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="Spring Batch: ${project.name}">
+ <bannerLeft>
+ <name>Spring Batch: ${project.name}</name>
+ <href>index.html</href>
+ </bannerLeft>
- <bannerLeft>
- <name>Spring Batch: ${project.name}</name>
- <href>index.html</href>
- </bannerLeft>
-
- <skin>
- <groupId>org.springframework.maven.skins</groupId>
- <artifactId>maven-spring-skin</artifactId>
- <version>1.0.5</version>
- </skin>
-
- <body>
-
- <links>
- <item name="${project.name}" href="index.html"/>
- </links>
-
- <menu ref="reports"/>
-
- </body>
+ <skin>
+ <groupId>org.springframework.maven.skins</groupId>
+ <artifactId>maven-spring-skin</artifactId>
+ <version>1.0.5</version>
+ </skin>
+ <body>
+ <links>
+ <item name="${project.name}" href="index.html"/>
+ </links>
+ <menu ref="reports"/>
+ </body>
</project>
View
18 archetypes/simple-cli/src/test/java/example/ExampleItemReaderTests.java
@@ -1,18 +0,0 @@
-package example;
-
-import junit.framework.TestCase;
-
-public class ExampleItemReaderTests extends TestCase {
-
- private ExampleItemReader reader = new ExampleItemReader();
-
- public void testReadOnce() throws Exception {
- assertEquals("Hello world!", reader.read());
- }
-
- public void testReadTwice() throws Exception {
- reader.read();
- assertEquals(null, reader.read());
- }
-
-}
View
13 archetypes/simple-cli/src/test/java/example/ExampleItemWriterTests.java
@@ -1,13 +0,0 @@
-package example;
-
-import junit.framework.TestCase;
-
-public class ExampleItemWriterTests extends TestCase {
-
- private ExampleItemWriter writer = new ExampleItemWriter();
-
- public void testWrite() throws Exception {
- writer.write(null); // nothing bad happens
- }
-
-}
View
38 archetypes/simple-cli/src/test/java/example/PersonItemProcessorTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2013 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 example;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * <p>
+ * Example test case processing a {@link Person} using the {@link PersonItemProcessor}.
+ * </p>
+ */
+public class PersonItemProcessorTest {
+ @Test
+ public void testProcessedPersonRecord() throws Exception {
+ final Person person = new Person();
+ person.setFirstName("Jane");
+ person.setLastName("Doe");
+
+ final Person processedPerson = new PersonItemProcessor().process(person);
+
+ assertEquals("First name does not match expected value.", "JANE", processedPerson.getFirstName());
+ assertEquals("Last name does not match expected value.", "DOE", processedPerson.getLastName());
+ }
+}
View
61 ...st/java/example/ExampleJobConfigurationTests.java → ...test/java/example/PersonJobConfigurationTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006-2007 the original author or authors.
+ * Copyright 2006-2013 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.
@@ -15,7 +15,8 @@
*/
package example;
-import static org.junit.Assert.*;
+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.BatchStatus;
@@ -30,10 +31,14 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-@ContextConfiguration(locations = { "/test-context.xml" })
+/**
+ * <p>
+ * Test cases asserting on the example job's configuration.
+ * </p>
+ */
+@ContextConfiguration(locations = "/test-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
-public class ExampleJobConfigurationTests {
-
+public class PersonJobConfigurationTest {
@Autowired
private JobLauncher jobLauncher;
@@ -45,41 +50,47 @@
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;
-
+
+ /**
+ * <p>
+ * Creates a new {@link JobExecution} using a {@link JobLauncher}.
+ * </p>
+ *
+ * @throws Exception if any {@link Exception}'s occur
+ */
@Test
public void testLaunchJobWithJobLauncher() throws Exception {
- JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
- assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
+ final JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
+ assertEquals("Batch status not COMPLETED", BatchStatus.COMPLETED, jobExecution.getStatus());
}
/**
- * Create a unique job instance and check it's execution completes
- * successfully - uses the convenience methods provided by the testing
- * superclass.
+ * <p>
+ * Create a unique job instance and check it's execution completes successfully.
+ * Uses the convenience methods provided by the testing superclass.
+ * </p>
+ *
+ * @throws Exception if any {@link Exception}'s occur
*/
@Test
public void testLaunchJob() throws Exception {
-
- JobExecution jobExecution = jobLauncherTestUtils.launchJob(jobLauncherTestUtils.getUniqueJobParameters());
- assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
+ final JobExecution jobExecution = jobLauncherTestUtils.launchJob(jobLauncherTestUtils.getUniqueJobParameters());
+ assertEquals("Batch status not COMPLETED", BatchStatus.COMPLETED, jobExecution.getStatus());
}
/**
- * Execute a fresh {@link JobInstance} using {@link JobOperator} - closer to
+ * <p>
+ * Execute a fresh {@link JobInstance} using {@link JobOperator} which is closer to
* a remote invocation scenario.
+ * </p>
+ *
+ * @throws Exception if any {@link Exception}'s occur
*/
@Test
public void testLaunchByJobOperator() throws Exception {
+ final long jobExecutionId = jobOperator.startNextInstance(jobLauncherTestUtils.getJob().getName());
- // assumes the job has a JobIncrementer set
- long jobExecutionId = jobOperator.startNextInstance(jobLauncherTestUtils.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));
-
+ final String result = jobOperator.getSummary(jobExecutionId);
+ assertTrue("Result does not contain status=COMPLETED", result.contains("status=" + BatchStatus.COMPLETED));
}
-
}
View
49 archetypes/simple-cli/src/test/resources/test-context.xml
@@ -1,13 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
-
- <import resource="classpath*:/launch-context.xml"/>
-
- <context:annotation-config/>
-
- <bean class="org.springframework.batch.test.JobLauncherTestUtils"/>
-
-</beans>
+<beans:beans
+ xmlns:beans="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:jdbc="http://www.springframework.org/schema/jdbc"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+ http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
+
+ <beans:import resource="classpath:launch-context.xml"/>
+
+ <context:annotation-config/>
+
+ <jdbc:initialize-database data-source="dataSource">
+ <jdbc:script location="${batch.drop.script}"/>
+ <jdbc:script location="${person.sql.location}"/>
+ <jdbc:script location="${batch.schema.script}"/>
+ </jdbc:initialize-database>
+
+ <beans:bean class="org.springframework.batch.test.JobLauncherTestUtils"/>
+
+ <beans: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"/>
+
+ <beans:bean id="jobExplorer"
+ class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"
+ p:dataSource-ref="dataSource"/>
+
+ <beans:bean id="jobRegistry"
+ class="org.springframework.batch.core.configuration.support.MapJobRegistry"/>
+
+ <beans:bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor"
+ p:jobRegistry-ref="jobRegistry"/>
+</beans:beans>
Please sign in to comment.
Something went wrong with that request. Please try again.