BATCH-220: Half way to rename StepHandler -> Tasklet

This commit is contained in:
dsyer
2008-08-28 10:38:26 +00:00
parent 223a58da18
commit ad5b0010dd
38 changed files with 200 additions and 110 deletions

View File

@@ -22,7 +22,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepListener;
import org.springframework.batch.core.listener.MulticasterBatchListener;
import org.springframework.batch.core.step.handler.StepHandler;
import org.springframework.batch.core.step.tasklet.StepHandler;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
@@ -114,7 +114,7 @@ public class ItemOrientedStepHandler<T, S> implements StepHandler {
* {@link ItemProcessor} returns null, the write is omitted and another item
* taken from the reader.
*
* @see org.springframework.batch.core.step.handler.StepHandler#handle(org.springframework.batch.core.StepContribution,
* @see org.springframework.batch.core.step.tasklet.StepHandler#handle(org.springframework.batch.core.StepContribution,
* AttributeAccessor)
*/
public ExitStatus handle(final StepContribution contribution, AttributeAccessor attributes) throws Exception {

View File

@@ -21,7 +21,7 @@ import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.StepListener;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.handler.StepHandlerStep;
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;

View File

@@ -9,11 +9,11 @@ import java.util.List;
import org.springframework.batch.core.SkipListener;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.step.handler.StepHandlerStep;
import org.springframework.batch.core.step.skip.ItemSkipPolicy;
import org.springframework.batch.core.step.skip.LimitCheckingItemSkipPolicy;
import org.springframework.batch.core.step.skip.SkipLimitExceededException;
import org.springframework.batch.core.step.skip.SkipListenerFailedException;
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import org.springframework.core.AttributeAccessorSupport;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import java.util.concurrent.Callable;

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import org.springframework.batch.repeat.ExitStatus;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.item.ItemReader;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.item.adapter.AbstractMethodInvokingDelegator;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
@@ -25,6 +25,7 @@ import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.StepListener;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.step.AbstractStep;
import org.springframework.batch.core.step.StepExecutionSynchronizer;
@@ -82,6 +83,13 @@ public class StepHandlerStep extends AbstractStep {
private StepExecutionSynchronizer synchronizer;
/**
* Default constructor.
*/
public StepHandlerStep() {
this(null);
}
/**
* @param name
*/
@@ -114,6 +122,9 @@ public class StepHandlerStep extends AbstractStep {
*/
public void setStepHandler(StepHandler stepHandler) {
this.stepHandler = stepHandler;
if (stepHandler instanceof StepExecutionListener) {
registerStepExecutionListener((StepExecutionListener) stepHandler);
}
}
/**
@@ -195,9 +206,9 @@ public class StepHandlerStep extends AbstractStep {
* Process the step and update its context so that progress can be monitored
* by the caller. The step is broken down into chunks, each one executing in
* a transaction. The step and its execution and execution context are all
* given an up to date {@link BatchStatus}, and the {@link JobRepository} is
* used to store the result. Various reporting information are also added to
* the current context (the {@link RepeatContext} governing the step
* given an up to date {@link BatchStatus}, and the {@link JobRepository}
* is used to store the result. Various reporting information are also added
* to the current context (the {@link RepeatContext} governing the step
* execution, which would normally be available to the caller somehow
* through the step's {@link ExecutionContext}.<br/>
*
@@ -369,8 +380,8 @@ public class StepHandlerStep extends AbstractStep {
}
catch (Exception e) {
/*
* If we already failed to commit, it doesn't help to do this again
* - it's better to allow the CommitFailedException to propagate
* If we already failed to commit, it doesn't help to do this again -
* it's better to allow the CommitFailedException to propagate
*/
if (!fatalException.hasException()) {
fatalException.setException(e);

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
/**
* Exception indicating failed execution of system command.

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import java.io.File;
import java.io.IOException;

View File

@@ -1,6 +1,6 @@
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import org.springframework.batch.core.step.handler.SystemCommandStepHandler;
import org.springframework.batch.core.step.tasklet.SystemCommandStepHandler;
import org.springframework.batch.repeat.ExitStatus;
/**

View File

@@ -28,10 +28,10 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.step.handler.BasicAttributeAccessor;
import org.springframework.batch.core.step.item.SkipLimitStepFactoryBean.StatefulRetryStepHandler;
import org.springframework.batch.core.step.skip.ItemSkipPolicy;
import org.springframework.batch.core.step.skip.SkipLimitExceededException;
import org.springframework.batch.core.step.tasklet.BasicAttributeAccessor;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -21,6 +21,7 @@ import static org.junit.Assert.fail;
import java.util.concurrent.Callable;
import org.junit.Test;
import org.springframework.batch.core.step.tasklet.CallableStepHandlerAdapter;
import org.springframework.batch.repeat.ExitStatus;
public class CallableStepHandlerAdapterTests {

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
@@ -7,7 +7,7 @@ import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.batch.core.step.handler.ConfigurableSystemProcessExitCodeMapper;
import org.springframework.batch.core.step.tasklet.ConfigurableSystemProcessExitCodeMapper;
import org.springframework.batch.repeat.ExitStatus;
/**

View File

@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import org.springframework.batch.core.step.handler.StepHandler;
import org.springframework.batch.core.step.item.ItemOrientedStepHandler;
import org.springframework.batch.core.step.tasklet.StepHandler;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.support.PassthroughItemProcessor;

View File

@@ -1,8 +1,9 @@
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.batch.core.step.tasklet.SimpleSystemProcessExitCodeMapper;
import org.springframework.batch.repeat.ExitStatus;
/**

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import java.util.List;
@@ -33,7 +33,7 @@ import org.springframework.batch.core.repository.dao.MapJobInstanceDao;
import org.springframework.batch.core.repository.dao.MapStepExecutionDao;
import org.springframework.batch.core.repository.support.SimpleJobRepository;
import org.springframework.batch.core.step.StepExecutionSynchronizer;
import org.springframework.batch.core.step.handler.StepHandlerStep;
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;

View File

@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.springframework.batch.core.step.tasklet.StepHandlerAdapter;
import org.springframework.batch.repeat.ExitStatus;
/**

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -39,7 +39,7 @@ import org.springframework.batch.core.repository.dao.MapJobExecutionDao;
import org.springframework.batch.core.repository.dao.MapJobInstanceDao;
import org.springframework.batch.core.repository.dao.MapStepExecutionDao;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.core.step.handler.StepHandlerStep;
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -47,7 +47,7 @@ import org.springframework.batch.core.repository.dao.MapStepExecutionDao;
import org.springframework.batch.core.repository.support.SimpleJobRepository;
import org.springframework.batch.core.step.JobRepositorySupport;
import org.springframework.batch.core.step.StepInterruptionPolicy;
import org.springframework.batch.core.step.handler.StepHandlerStep;
import org.springframework.batch.core.step.tasklet.StepHandlerStep;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.core.step.handler;
package org.springframework.batch.core.step.tasklet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -15,6 +15,9 @@ import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.step.tasklet.SystemCommandException;
import org.springframework.batch.core.step.tasklet.SystemCommandStepHandler;
import org.springframework.batch.core.step.tasklet.SystemProcessExitCodeMapper;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.util.Assert;

View File

@@ -44,7 +44,7 @@ import org.springframework.batch.retry.policy.SimpleRetryPolicy;
* Template class that simplifies the execution of operations with retry
* semantics. <br/> Retryable operations are encapsulated in implementations of
* the {@link RetryCallback} interface and are executed using one of the
* supplied {@link #execute} methods. <br/>
* supplied execute methods. <br/>
*
* By default, an operation is retried if is throws any {@link Exception} or
* subclass of {@link Exception}. This behaviour can be changed by using the

View File

@@ -16,7 +16,7 @@
package org.springframework.batch.integration.job;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.step.handler.StepHandler;
import org.springframework.batch.core.step.tasklet.StepHandler;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.AttributeAccessor;

View File

@@ -1,47 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:context="http://www.springframework.org/schema/context"
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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<import resource="classpath:/simple-job-launcher-context.xml" />
<integration:annotation-driven/>
<integration:message-bus auto-create-channels="true" />
<integration:channel id="requests" />
<integration:channel id="replies" />
<bean id="job" parent="simpleJob">
<property name="steps">
<bean
class="org.springframework.batch.integration.job.MessageOrientedStep">
<property name="name" value="TODO: I shouldn't have to set this"/>
<property name="target" ref="requests" />
<property name="source" ref="replies" />
<property name="jobRepository" ref="jobRepository" />
</bean>
</property>
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="step"
class="org.springframework.batch.integration.job.StepExecutionMessageHandler">
<property name="step">
<bean parent="taskletStep">
<property name="tasklet">
<bean
class="org.springframework.batch.integration.job.TestTasklet" />
</property>
</bean>
</property>
<property name="jobRepository" ref="jobRepository" />
</bean>
<integration:service-activator ref="step" method="handle" input-channel="requests"
output-channel="replies" />
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:integration="http://www.springframework.org/schema/integration"
xmlns:context="http://www.springframework.org/schema/context"
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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<import resource="classpath:/simple-job-launcher-context.xml" />
<integration:annotation-driven/>
<integration:message-bus auto-create-channels="true" />
<integration:channel id="requests" />
<integration:channel id="replies" />
<bean id="job" parent="simpleJob">
<property name="steps">
<bean
class="org.springframework.batch.integration.job.MessageOrientedStep">
<property name="name" value="TODO: I shouldn't have to set this"/>
<property name="target" ref="requests" />
<property name="source" ref="replies" />
<property name="jobRepository" ref="jobRepository" />
</bean>
</property>
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="step"
class="org.springframework.batch.integration.job.StepExecutionMessageHandler">
<property name="step">
<bean parent="taskletStep">
<property name="tasklet">
<bean
class="org.springframework.batch.integration.job.TestTasklet" />
</property>
</bean>
</property>
<property name="jobRepository" ref="jobRepository" />
</bean>
<integration:service-activator ref="step" method="handle" input-channel="requests"
output-channel="replies" />
</beans>

View File

@@ -26,8 +26,8 @@
<property name="jobRepository" ref="jobRepository" />
<property name="restartable" value="true" />
</bean>
<bean id="handlerStep"
class="org.springframework.batch.core.step.handler.StepHandlerStep"
<bean id="taskletStep"
class="org.springframework.batch.core.step.tasklet.StepHandlerStep"
abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="jobRepository" ref="jobRepository" />

View File

@@ -12,16 +12,22 @@ import org.springframework.batch.item.validator.ValidationException;
public class ItemTrackingItemWriter<T> implements ItemWriter<T> {
private List<T> items = new ArrayList<T>();
private T failed = null;
private int failure = -1;
private int counter = 0;
public void write(List<? extends T> item) throws Exception {
items.addAll(item);
public void write(List<? extends T> items) throws Exception {
if (failed!=null && items.contains(failed)) {
throw new ValidationException("validation failed");
}
this.items.addAll(items);
int current = counter;
counter += item.size();
counter += items.size();
if (current < failure && counter >= failure) {
failed = items.get(failure-current-1);
throw new ValidationException("validation failed");
}
}

View File

@@ -5,7 +5,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
import org.springframework.batch.core.step.handler.StepHandler;
import org.springframework.batch.core.step.tasklet.StepHandler;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.AttributeAccessor;

View File

@@ -5,7 +5,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.listener.StepExecutionListenerSupport;
import org.springframework.batch.core.step.handler.StepHandler;
import org.springframework.batch.core.step.tasklet.StepHandler;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.AttributeAccessor;

View File

@@ -2,7 +2,7 @@ package org.springframework.batch.sample.tasklet;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.UnexpectedJobExecutionException;
import org.springframework.batch.core.step.handler.StepHandler;
import org.springframework.batch.core.step.tasklet.StepHandler;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.AttributeAccessor;

View File

@@ -11,11 +11,11 @@
<bean id="jobExecutionContextSample" parent="simpleJob">
<property name="steps">
<list>
<bean id="step1" parent="handlerStep">
<property name="tasklet" ref="sender" />
<bean id="step1" parent="taskletStep">
<property name="stepHandler" ref="sender" />
</bean>
<bean id="step2" parent="handlerStep">
<property name="tasklet" ref="receiver" />
<bean id="step2" parent="taskletStep">
<property name="stepHandler" ref="receiver" />
</bean>
</list>
</property>

View File

@@ -13,19 +13,19 @@
The second step illustrates executing a system command.
</description>
<bean id="handlerJob" parent="simpleJob">
<bean id="taskletJob" parent="simpleJob">
<property name="steps">
<list>
<bean id="deleteFilesInDir" parent="handlerStep">
<property name="tasklet">
<bean id="deleteFilesInDir" parent="taskletStep">
<property name="stepHandler">
<bean class="org.springframework.batch.sample.tasklet.FileDeletingStepHandler">
<property name="resources" value="target/test-outputs/test-dir/*" />
<property name="resources" value="file:target/test-outputs/test-dir/*" />
</bean>
</property>
</bean>
<bean id="executeSystemCommand" parent="handlerStep">
<property name="tasklet">
<bean class="org.springframework.batch.core.step.handler.SystemCommandStepHandler">
<bean id="executeSystemCommand" parent="taskletStep">
<property name="stepHandler">
<bean class="org.springframework.batch.core.step.tasklet.SystemCommandStepHandler">
<property name="command" value="java -version" />
<!-- 5 second timeout for the command to complete -->
<property name="timeout" value="5000" />

View File

@@ -2,17 +2,17 @@
<beans 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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<bean id="simpleJob" class="org.springframework.batch.core.job.SimpleJob" abstract="true">
<property name="jobRepository" ref="jobRepository" />
<property name="restartable" value="true" />
</bean>
<bean id="handlerStep" class="org.springframework.batch.core.step.handler.StepHandlerStep" abstract="true">
<bean id="taskletStep" class="org.springframework.batch.core.step.tasklet.StepHandlerStep" abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="jobRepository" ref="jobRepository" />
<property name="allowStartIfComplete" value="true" />

View File

@@ -17,7 +17,7 @@ import org.springframework.util.Assert;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration()
public class HandlerJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
public class TaskletJobFunctionalTests extends AbstractValidatingBatchLauncherTests {
private Resource directory = new FileSystemResource("target/test-outputs/test-dir");

View File

@@ -0,0 +1,67 @@
/*
* 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.support;
import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.batch.item.validator.ValidationException;
/**
* @author Dave Syer
*
*/
public class ItemTrackingItemWriterTests {
private ItemTrackingItemWriter<String> writer = new ItemTrackingItemWriter<String>();
/**
* Test method for {@link org.springframework.batch.sample.support.ItemTrackingItemWriter#write(java.util.List)}.
* @throws Exception
*/
@Test
public void testWrite() throws Exception {
assertEquals(0, writer.getItems().size());
writer.write(Arrays.asList("a", "b", "c"));
assertEquals(3, writer.getItems().size());
}
@Test
public void testValidationFailure() throws Exception {
writer.setValidationFailure(2);
try {
writer.write(Arrays.asList("a", "b", "c"));
fail("Expected ValidationException");
}
catch (ValidationException e) {
// expected
}
assertEquals(3, writer.getItems().size());
writer.write(Arrays.asList("a", "e", "c"));
assertEquals(6, writer.getItems().size());
try {
writer.write(Arrays.asList("f", "b", "g"));
fail("Expected ValidationException");
}
catch (ValidationException e) {
// expected
}
assertEquals(6, writer.getItems().size());
}
}

View File

@@ -5,6 +5,6 @@
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/handlerJob.xml" />
<import resource="classpath:/jobs/taskletJob.xml" />
</beans>