BATCH-1209: add a Groovy job in samples using AntBuilder to do some file schlepping

This commit is contained in:
dsyer
2009-06-16 07:49:49 +00:00
parent 7b14a66a6e
commit 3a25f23218
5 changed files with 127 additions and 0 deletions

View File

@@ -134,6 +134,12 @@
<version>1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>1.6.3</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:batch="http://www.springframework.org/schema/batch"
xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<job id="tradeJob" xmlns="http://www.springframework.org/schema/batch">
<step id="unzip-step" next="zip-step">
<tasklet ref="unzip" />
</step>
<step id="zip-step">
<tasklet ref="zip" />
</step>
</job>
<bean id="unzip" class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter" scope="step">
<property name="targetObject" ref="unzip-script"/>
<property name="targetMethod" value="execute"/>
</bean>
<bean id="zip" class="org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter" scope="step">
<property name="targetObject" ref="zip-script"/>
<property name="targetMethod" value="execute"/>
</bean>
<lang:groovy id="unzip-script">
<lang:inline-script>
class UnzipTasklet {
void execute() {
def ant = new AntBuilder()
ant.unzip(src:"src/main/resources/data/groovyJob/input/files.zip",
dest:"target/groovyJob/staging")
}
}
</lang:inline-script>
</lang:groovy>
<lang:groovy id="zip-script">
<lang:inline-script>
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:"**")
}
}
</lang:inline-script>
</lang:groovy>
</beans>

View File

@@ -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());
}
}

View File

@@ -0,0 +1,10 @@
<?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/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<import resource="classpath:/simple-job-launcher-context.xml" />
<import resource="classpath:/jobs/groovyJob.xml" />
</beans>