From c1be0af6fca533506d01b80fe8df95510d77df95 Mon Sep 17 00:00:00 2001 From: Chris Schaefer Date: Wed, 16 Jan 2013 01:04:28 -0500 Subject: [PATCH 1/2] BATCH-1935: Add quick start maven archetype --- .gitignore | 1 + archetypes/pom.xml | 3 +- archetypes/simple-cli/pom.xml | 555 ++++++++++-------- .../src/main/assembly/descriptor.xml | 25 + .../main/java/example/ExampleItemReader.java | 27 - .../main/java/example/ExampleItemWriter.java | 24 - .../src/main/java/example/Person.java | 47 ++ .../java/example/PersonItemProcessor.java | 38 ++ .../datasource/DataSourceInitializer.java | 179 ------ .../META-INF/spring/module-context.xml | 51 +- .../src/main/resources/batch.properties | 8 +- .../src/main/resources/launch-context.xml | 108 ++-- .../src/main/resources/log4j.properties | 5 - .../src/main/resources/support/person.sql | 7 + .../main/resources/support/sample-data.csv | 5 + .../simple-cli/src/main/scripts/runJob.bat | 8 + .../simple-cli/src/main/scripts/runJob.sh | 8 + archetypes/simple-cli/src/site/site.xml | 35 +- .../java/example/ExampleItemReaderTests.java | 18 - .../java/example/ExampleItemWriterTests.java | 13 - .../java/example/PersonItemProcessorTest.java | 38 ++ ...s.java => PersonJobConfigurationTest.java} | 61 +- .../src/test/resources/test-context.xml | 45 +- 23 files changed, 645 insertions(+), 664 deletions(-) create mode 100644 archetypes/simple-cli/src/main/assembly/descriptor.xml delete mode 100644 archetypes/simple-cli/src/main/java/example/ExampleItemReader.java delete mode 100644 archetypes/simple-cli/src/main/java/example/ExampleItemWriter.java create mode 100644 archetypes/simple-cli/src/main/java/example/Person.java create mode 100644 archetypes/simple-cli/src/main/java/example/PersonItemProcessor.java delete mode 100644 archetypes/simple-cli/src/main/java/test/jdbc/datasource/DataSourceInitializer.java create mode 100644 archetypes/simple-cli/src/main/resources/support/person.sql create mode 100644 archetypes/simple-cli/src/main/resources/support/sample-data.csv create mode 100644 archetypes/simple-cli/src/main/scripts/runJob.bat create mode 100644 archetypes/simple-cli/src/main/scripts/runJob.sh delete mode 100644 archetypes/simple-cli/src/test/java/example/ExampleItemReaderTests.java delete mode 100644 archetypes/simple-cli/src/test/java/example/ExampleItemWriterTests.java create mode 100644 archetypes/simple-cli/src/test/java/example/PersonItemProcessorTest.java rename archetypes/simple-cli/src/test/java/example/{ExampleJobConfigurationTests.java => PersonJobConfigurationTest.java} (54%) diff --git a/.gitignore b/.gitignore index 07fd09019..fbc1fdfff 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,5 @@ s3.properties *.ipr *.iws .*.swp +.DS_Store diff --git a/archetypes/pom.xml b/archetypes/pom.xml index 7cf415ad5..7cc023152 100644 --- a/archetypes/pom.xml +++ b/archetypes/pom.xml @@ -5,8 +5,7 @@ pom Archetypes http://static.springframework.org/spring-batch/${artifactId} - 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. - + 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. org.springframework.batch spring-batch-parent diff --git a/archetypes/simple-cli/pom.xml b/archetypes/simple-cli/pom.xml index 5bacf902d..2be2decca 100644 --- a/archetypes/simple-cli/pom.xml +++ b/archetypes/simple-cli/pom.xml @@ -1,260 +1,299 @@ - - 4.0.0 - org.springframework.batch - spring-batch-simple-cli - 2.2.0.BUILD-SNAPSHOT - jar - Commandline - http://www.springframework.org/spring-batch/archetypes/simple-cli-archetype - 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". - - 3.2.0.RELEASE - 2.2.0.BUILD-SNAPSHOT - false - 4.10 - - - - staging - - - staging - file:///${user.dir}/target/staging - - - staging - file:///${user.dir}/target/staging - - - - - bootstrap - - - Codehaus - http://repository.codehaus.org/ - - false - - - - - - - - junit - junit - ${junit.version} - test - - - org.springframework - spring-test - ${spring.framework.version} - test - - - org.springframework - spring-context - ${spring.framework.version} - - - org.springframework - spring-aop - ${spring.framework.version} - - - org.springframework - spring-jdbc - ${spring.framework.version} - - - org.springframework.batch - spring-batch-core - ${spring.batch.version} - - - org.springframework.batch - spring-batch-infrastructure - ${spring.batch.version} - - - org.springframework.batch - spring-batch-test - ${spring.batch.version} - test - - - commons-dbcp - commons-dbcp - 1.2.2 - - - org.slf4j - slf4j-log4j12 - 1.5.8 - true - - - log4j - log4j - 1.2.14 - true - - - commons-io - commons-io - 1.4 - - - hsqldb - hsqldb - 1.8.0.7 - - - org.aspectj - aspectjrt - 1.5.4 - - - org.aspectj - aspectjweaver - 1.5.4 - - - - - - org.springframework.build.aws - org.springframework.build.aws.maven - 3.0.0.RELEASE - - - - - - maven-assembly-plugin - false - - - project - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.maven.plugins - maven-dependency-plugin - [1.0,) - - copy-dependencies - - - - - - - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.6 - 1.6 - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*Tests.java - - - **/Abstract*.java - - junit:junit - - - - org.codehaus.mojo - exec-maven-plugin - 1.1 - - org.springframework.batch.core.launch.support.CommandLineJobRunner - - classpath:/launch-context.xml - job1 - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - package - - copy-dependencies - - - ${project.build.directory}/lib - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - false - - org.springframework.batch.core.launch.support.CommandLineJobRunner - true - lib/ - - - - - - - - http://www.springframework.org/download - - staging - file:///${user.dir}/target/staging/org.springframework.batch.archetype/${pom.artifactId} - - - spring-release - Spring Release Repository - file:///${user.dir}/target/staging/release - - - spring-snapshot - Spring Snapshot Repository - file:///${user.dir}/target/staging/snapshot - - + + 4.0.0 + org.springframework.batch + spring-batch-simple-cli + 2.2.0.BUILD-SNAPSHOT + jar + Commandline + http://www.springframework.org/spring-batch/archetypes/simple-cli-archetype + 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. + + + 3.2.0.RELEASE + 2.2.0.BUILD-SNAPSHOT + false + 4.10 + 1.6 + 1.6 + UTF-8 + + + + staging + + + staging + file:///${user.dir}/target/staging + + + staging + file:///${user.dir}/target/staging + + + + + bootstrap + + + Codehaus + http://repository.codehaus.org/ + + false + + + + com.springsource.repository.bundles.release + SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases + http://repository.springsource.com/maven/bundles/release + + false + + + + + + + + junit + junit + ${junit.version} + test + + + org.springframework + spring-test + ${spring.framework.version} + test + + + org.springframework + spring-aop + ${spring.framework.version} + + + org.springframework + spring-jdbc + ${spring.framework.version} + + + org.springframework.batch + spring-batch-core + ${spring.batch.version} + + + org.springframework.batch + spring-batch-infrastructure + ${spring.batch.version} + + + org.springframework.batch + spring-batch-test + ${spring.batch.version} + test + + + commons-dbcp + commons-dbcp + 1.2.2 + + + org.slf4j + slf4j-log4j12 + 1.5.8 + true + + + log4j + log4j + 1.2.14 + true + + + commons-io + commons-io + 1.4 + + + hsqldb + hsqldb + 1.8.0.7 + + + org.aspectj + aspectjrt + 1.6.8 + + + org.aspectj + aspectjweaver + 1.6.8 + + + + + + org.springframework.build.aws + org.springframework.build.aws.maven + 3.0.0.RELEASE + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + com.springsource.bundlor + com.springsource.bundlor.maven + [1.0,) + + bundlor + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + [1.0,) + + copy-dependencies + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + ${compiler.source.version} + ${compiler.target.version} + + + + com.springsource.bundlor + com.springsource.bundlor.maven + 1.0.0.RELEASE + + + bundlor-transform + compile + + bundlor + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.13 + + + org.codehaus.mojo + exec-maven-plugin + 1.1 + + org.springframework.batch.core.launch.support.CommandLineJobRunner + + classpath:/launch-context.xml + personJob + + + + + maven-assembly-plugin + 2.3 + + + src/main/assembly/descriptor.xml + + + + + make-distribution + package + + single + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/lib + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + + false + + org.springframework.batch.core.launch.support.CommandLineJobRunner + true + lib/ + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + + + + + + http://www.springframework.org/download + + staging + file:///${user.dir}/target/staging/org.springframework.batch.archetype/${project.artifactId} + + + spring-release + Spring Release Repository + file:///${user.dir}/target/staging/release + + + spring-snapshot + Spring Snapshot Repository + file:///${user.dir}/target/staging/snapshot + + diff --git a/archetypes/simple-cli/src/main/assembly/descriptor.xml b/archetypes/simple-cli/src/main/assembly/descriptor.xml new file mode 100644 index 000000000..c28873cb2 --- /dev/null +++ b/archetypes/simple-cli/src/main/assembly/descriptor.xml @@ -0,0 +1,25 @@ + + distribution + + tar.gz + + false + + + src/main/scripts + bin + true + + + src/main/resources + resources + true + true + + + + + lib + + + diff --git a/archetypes/simple-cli/src/main/java/example/ExampleItemReader.java b/archetypes/simple-cli/src/main/java/example/ExampleItemReader.java deleted file mode 100644 index 2874eea75..000000000 --- a/archetypes/simple-cli/src/main/java/example/ExampleItemReader.java +++ /dev/null @@ -1,27 +0,0 @@ -package example; - -import org.springframework.batch.item.ItemReader; - -/** - * {@link ItemReader} with hard-coded input data. - */ -public class ExampleItemReader implements ItemReader { - - 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; - } - - } - -} diff --git a/archetypes/simple-cli/src/main/java/example/ExampleItemWriter.java b/archetypes/simple-cli/src/main/java/example/ExampleItemWriter.java deleted file mode 100644 index 4cbea41ee..000000000 --- a/archetypes/simple-cli/src/main/java/example/ExampleItemWriter.java +++ /dev/null @@ -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 { - - private static final Log log = LogFactory.getLog(ExampleItemWriter.class); - - /** - * @see ItemWriter#write(Object) - */ - public void write(List data) throws Exception { - log.info(data); - } - -} diff --git a/archetypes/simple-cli/src/main/java/example/Person.java b/archetypes/simple-cli/src/main/java/example/Person.java new file mode 100644 index 000000000..43787449d --- /dev/null +++ b/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; + +/** + *

+ * Domain object representing information about a person. + *

+ */ +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; + } +} diff --git a/archetypes/simple-cli/src/main/java/example/PersonItemProcessor.java b/archetypes/simple-cli/src/main/java/example/PersonItemProcessor.java new file mode 100644 index 000000000..b9a25bdea --- /dev/null +++ b/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; + +/** + *

+ * An example {@link org.springframework.batch.item.ItemProcessor} implementation that upper cases attributes on the + * provided {@link Person} object. + *

+ */ +public class PersonItemProcessor implements ItemProcessor { + @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; + } +} diff --git a/archetypes/simple-cli/src/main/java/test/jdbc/datasource/DataSourceInitializer.java b/archetypes/simple-cli/src/main/java/test/jdbc/datasource/DataSourceInitializer.java deleted file mode 100644 index ea44808a2..000000000 --- a/archetypes/simple-cli/src/main/java/test/jdbc/datasource/DataSourceInitializer.java +++ /dev/null @@ -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

- * - * 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 - * hsql.server project. Then you can right click in Eclipse and - * Run As -> 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 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; - } - -} diff --git a/archetypes/simple-cli/src/main/resources/META-INF/spring/module-context.xml b/archetypes/simple-cli/src/main/resources/META-INF/spring/module-context.xml index 81050a616..b68d633dd 100644 --- a/archetypes/simple-cli/src/main/resources/META-INF/spring/module-context.xml +++ b/archetypes/simple-cli/src/main/resources/META-INF/spring/module-context.xml @@ -1,35 +1,22 @@ - + - Example job to get you started. It provides a - skeleton for - a typical batch application. - + Example job providing a skeleton for a typical batch application. - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + diff --git a/archetypes/simple-cli/src/main/resources/batch.properties b/archetypes/simple-cli/src/main/resources/batch.properties index 5c55586e4..dea386513 100644 --- a/archetypes/simple-cli/src/main/resources/batch.properties +++ b/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 diff --git a/archetypes/simple-cli/src/main/resources/launch-context.xml b/archetypes/simple-cli/src/main/resources/launch-context.xml index dfc3b52b0..19c4f5ac5 100644 --- a/archetypes/simple-cli/src/main/resources/launch-context.xml +++ b/archetypes/simple-cli/src/main/resources/launch-context.xml @@ -1,59 +1,69 @@ - - + - + - + - - - - - - - - - - - + + + + + - - - - - - + - - - + + + + + + + + + + + + + + + + + - - - - - - + - - - - - + + + + + + + - + + + + + + + + diff --git a/archetypes/simple-cli/src/main/resources/log4j.properties b/archetypes/simple-cli/src/main/resources/log4j.properties index fd06b94c7..2cdeeb81b 100644 --- a/archetypes/simple-cli/src/main/resources/log4j.properties +++ b/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 diff --git a/archetypes/simple-cli/src/main/resources/support/person.sql b/archetypes/simple-cli/src/main/resources/support/person.sql new file mode 100644 index 000000000..4e405e6de --- /dev/null +++ b/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) +); diff --git a/archetypes/simple-cli/src/main/resources/support/sample-data.csv b/archetypes/simple-cli/src/main/resources/support/sample-data.csv new file mode 100644 index 000000000..cead90f5a --- /dev/null +++ b/archetypes/simple-cli/src/main/resources/support/sample-data.csv @@ -0,0 +1,5 @@ +Jill,Doe +Joe,Doe +Justin,Doe +Jane,Doe +John,Doe diff --git a/archetypes/simple-cli/src/main/scripts/runJob.bat b/archetypes/simple-cli/src/main/scripts/runJob.bat new file mode 100644 index 000000000..72ed089a4 --- /dev/null +++ b/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 diff --git a/archetypes/simple-cli/src/main/scripts/runJob.sh b/archetypes/simple-cli/src/main/scripts/runJob.sh new file mode 100644 index 000000000..fe9e1c8bd --- /dev/null +++ b/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 diff --git a/archetypes/simple-cli/src/site/site.xml b/archetypes/simple-cli/src/site/site.xml index 4bba09c7c..42b3b297e 100644 --- a/archetypes/simple-cli/src/site/site.xml +++ b/archetypes/simple-cli/src/site/site.xml @@ -1,25 +1,20 @@ + + Spring Batch: ${project.name} + index.html + - - Spring Batch: ${project.name} - index.html - - - - org.springframework.maven.skins - maven-spring-skin - 1.0.5 - - - - - - - - - - - + + org.springframework.maven.skins + maven-spring-skin + 1.0.5 + + + + + + + diff --git a/archetypes/simple-cli/src/test/java/example/ExampleItemReaderTests.java b/archetypes/simple-cli/src/test/java/example/ExampleItemReaderTests.java deleted file mode 100644 index 46d83ddb0..000000000 --- a/archetypes/simple-cli/src/test/java/example/ExampleItemReaderTests.java +++ /dev/null @@ -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()); - } - -} diff --git a/archetypes/simple-cli/src/test/java/example/ExampleItemWriterTests.java b/archetypes/simple-cli/src/test/java/example/ExampleItemWriterTests.java deleted file mode 100644 index b23ccbee2..000000000 --- a/archetypes/simple-cli/src/test/java/example/ExampleItemWriterTests.java +++ /dev/null @@ -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 - } - -} diff --git a/archetypes/simple-cli/src/test/java/example/PersonItemProcessorTest.java b/archetypes/simple-cli/src/test/java/example/PersonItemProcessorTest.java new file mode 100644 index 000000000..49f0d3da0 --- /dev/null +++ b/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; + +/** + *

+ * Example test case processing a {@link Person} using the {@link PersonItemProcessor}. + *

+ */ +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()); + } +} diff --git a/archetypes/simple-cli/src/test/java/example/ExampleJobConfigurationTests.java b/archetypes/simple-cli/src/test/java/example/PersonJobConfigurationTest.java similarity index 54% rename from archetypes/simple-cli/src/test/java/example/ExampleJobConfigurationTests.java rename to archetypes/simple-cli/src/test/java/example/PersonJobConfigurationTest.java index b722cbe90..96fbf4cce 100644 --- a/archetypes/simple-cli/src/test/java/example/ExampleJobConfigurationTests.java +++ b/archetypes/simple-cli/src/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.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -@ContextConfiguration(locations = { "/test-context.xml" }) +/** + *

+ * Test cases asserting on the example job's configuration. + *

+ */ +@ContextConfiguration(locations = "/test-context.xml") @RunWith(SpringJUnit4ClassRunner.class) -public class ExampleJobConfigurationTests { - +public class PersonJobConfigurationTest { @Autowired private JobLauncher jobLauncher; @@ -45,41 +50,47 @@ public class ExampleJobConfigurationTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; - + + /** + *

+ * Creates a new {@link JobExecution} using a {@link JobLauncher}. + *

+ * + * @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. + *

+ * Create a unique job instance and check it's execution completes successfully. + * Uses the convenience methods provided by the testing superclass. + *

+ * + * @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 + *

+ * Execute a fresh {@link JobInstance} using {@link JobOperator} which is closer to * a remote invocation scenario. + *

+ * + * @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)); } - } diff --git a/archetypes/simple-cli/src/test/resources/test-context.xml b/archetypes/simple-cli/src/test/resources/test-context.xml index c4ec752e8..e14b4c2d6 100644 --- a/archetypes/simple-cli/src/test/resources/test-context.xml +++ b/archetypes/simple-cli/src/test/resources/test-context.xml @@ -1,13 +1,38 @@ - + - - - - - + - + + + + + + + + + + + + + + + + + + From e85a55ab9e2cdbdaf16e95b091e62d029a9c9ed7 Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Tue, 22 Jan 2013 11:37:37 -0600 Subject: [PATCH 2/2] BATCH-1935: Updated to support pom updates from previous merge --- archetypes/simple-cli/pom.xml | 88 +++++++++++++++-------------------- 1 file changed, 38 insertions(+), 50 deletions(-) diff --git a/archetypes/simple-cli/pom.xml b/archetypes/simple-cli/pom.xml index 2be2decca..ec19d7332 100644 --- a/archetypes/simple-cli/pom.xml +++ b/archetypes/simple-cli/pom.xml @@ -145,6 +145,15 @@ + + maven-assembly-plugin + false + + + project + + + @@ -154,19 +163,6 @@ - - - com.springsource.bundlor - com.springsource.bundlor.maven - [1.0,) - - bundlor - - - - - - org.apache.maven.plugins @@ -196,25 +192,19 @@ ${compiler.target.version} - - com.springsource.bundlor - com.springsource.bundlor.maven - 1.0.0.RELEASE - - - bundlor-transform - compile - - bundlor - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.13 - + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*Tests.java + + + **/Abstract*.java + + junit:junit + + org.codehaus.mojo exec-maven-plugin @@ -227,6 +217,22 @@ + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/lib + + + + maven-assembly-plugin 2.3 @@ -245,26 +251,9 @@ - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - package - - copy-dependencies - - - ${project.build.directory}/lib - - - - org.apache.maven.plugins maven-jar-plugin - 2.3.1 false @@ -273,7 +262,6 @@ true lib/ - ${project.build.outputDirectory}/META-INF/MANIFEST.MF