From 3a25f23218da28b2a57c2433356e86c71b536a2e Mon Sep 17 00:00:00 2001 From: dsyer Date: Tue, 16 Jun 2009 07:49:49 +0000 Subject: [PATCH] BATCH-1209: add a Groovy job in samples using AntBuilder to do some file schlepping --- spring-batch-samples/pom.xml | 6 ++ .../resources/data/groovyJob/input/files.zip | Bin 0 -> 227 bytes .../src/main/resources/jobs/groovyJob.xml | 56 ++++++++++++++++++ .../sample/GroovyJobFunctionalTests.java | 55 +++++++++++++++++ .../GroovyJobFunctionalTests-context.xml | 10 ++++ 5 files changed, 127 insertions(+) create mode 100644 spring-batch-samples/src/main/resources/data/groovyJob/input/files.zip create mode 100644 spring-batch-samples/src/main/resources/jobs/groovyJob.xml create mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/sample/GroovyJobFunctionalTests.java create mode 100644 spring-batch-samples/src/test/resources/org/springframework/batch/sample/GroovyJobFunctionalTests-context.xml diff --git a/spring-batch-samples/pom.xml b/spring-batch-samples/pom.xml index fbbe8a09d..19a2d65f2 100644 --- a/spring-batch-samples/pom.xml +++ b/spring-batch-samples/pom.xml @@ -134,6 +134,12 @@ 1.2 test + + org.codehaus.groovy + groovy + 1.6.3 + runtime + org.hibernate hibernate diff --git a/spring-batch-samples/src/main/resources/data/groovyJob/input/files.zip b/spring-batch-samples/src/main/resources/data/groovyJob/input/files.zip new file mode 100644 index 0000000000000000000000000000000000000000..20abaffa75b72661aaf1711e35a36fc773da4e2a GIT binary patch literal 227 zcmWIWW@Zs#U|`^2h-^M+#j|a9mphPG0>nHFq6{HLi7BaG`AK@o#bu!(oD9sCpOw9) z0dZ&r3&RWM7tFq=E%_Q8c$_cJ+Z-Wy&S}ylCeF^PclDxeU7B}ne)hX(o_oE=_Cn+f zq0hO0Y8pZ|wCpN!N_U*PW-9lc{aZ8E+*|RX(tKkbV}Lg!lQ=UjcklvT!@$4@#7i1M dEL2yqLR=ME!N3sU&B_K+zzBpOZ?u6p3;=75L{b0% literal 0 HcmV?d00001 diff --git a/spring-batch-samples/src/main/resources/jobs/groovyJob.xml b/spring-batch-samples/src/main/resources/jobs/groovyJob.xml new file mode 100644 index 000000000..d4c03fe64 --- /dev/null +++ b/spring-batch-samples/src/main/resources/jobs/groovyJob.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + class UnzipTasklet { + void execute() { + def ant = new AntBuilder() + ant.unzip(src:"src/main/resources/data/groovyJob/input/files.zip", + dest:"target/groovyJob/staging") + } + } + + + + + + class ZipTasklet { + void execute() { + def ant = new AntBuilder() + ant.mkdir(dir:"target/groovyJob/output") + ant.zip(destfile:"target/groovyJob/output/files.zip", + basedir:"target/groovyJob/staging", includes:"**") + } + } + + + + \ No newline at end of file diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/GroovyJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/GroovyJobFunctionalTests.java new file mode 100644 index 000000000..53e804449 --- /dev/null +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/GroovyJobFunctionalTests.java @@ -0,0 +1,55 @@ +/* + * 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 org.springframework.batch.sample; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.io.FileUtils; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration() +public class GroovyJobFunctionalTests extends AbstractValidatingBatchLauncherTests { + + @Before + public void removeOldData() throws IOException { + FileUtils.deleteDirectory(new File("target/groovyJob")); + } + + @Test + public void testLaunchJob() throws Exception{ + super.testLaunchJob(); + } + + protected void validatePostConditions() { + assertTrue(new File("target/groovyJob/output/files.zip").exists()); + } + + protected void validatePreConditions() { + assertFalse(new File("target/groovyJob/output/files.zip").exists()); + } + +} diff --git a/spring-batch-samples/src/test/resources/org/springframework/batch/sample/GroovyJobFunctionalTests-context.xml b/spring-batch-samples/src/test/resources/org/springframework/batch/sample/GroovyJobFunctionalTests-context.xml new file mode 100644 index 000000000..5c02eb4f7 --- /dev/null +++ b/spring-batch-samples/src/test/resources/org/springframework/batch/sample/GroovyJobFunctionalTests-context.xml @@ -0,0 +1,10 @@ + + + + + + +