Skip to content

Align XML and Java based configuration #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected void registerStepListenerAsSkipListener() {
@Override
protected Tasklet createTasklet() {
Assert.state(getReader() != null, "ItemReader must be provided");
Assert.state(getProcessor() != null || getWriter() != null, "ItemWriter or ItemProcessor must be provided");
Assert.state(getWriter() != null, "ItemWriter must be provided");
addSpecialExceptions();
registerSkipListeners();
ChunkProvider<I> chunkProvider = createChunkProvider();
Expand Down Expand Up @@ -772,6 +772,6 @@ public boolean equals(Object obj) {
}
return chunkListener.equals(obj);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2014 the original author or authors.
* Copyright 2006-2017 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.
Expand Down Expand Up @@ -156,7 +156,7 @@ private void checkAndAddItemListener(StepListener stepListener) {
@Override
protected Tasklet createTasklet() {
Assert.state(reader != null, "ItemReader must be provided");
Assert.state(processor != null || writer != null, "ItemWriter or ItemProcessor must be provided");
Assert.state(writer != null, "ItemWriter must be provided");
RepeatOperations repeatOperations = createChunkOperations();
SimpleChunkProvider<I> chunkProvider = new SimpleChunkProvider<>(getReader(), repeatOperations);
SimpleChunkProcessor<I, O> chunkProcessor = new SimpleChunkProcessor<>(getProcessor(), getWriter());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2014 the original author or authors.
* Copyright 2008-2017 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.
Expand Down Expand Up @@ -372,30 +372,6 @@ public void testProcessFilter() throws Exception {
.getName()));
}

@Test
public void testNullWriter() throws Exception {

factory.setItemWriter(null);
Step step = factory.getObject();

step.execute(stepExecution);

assertEquals(0, stepExecution.getSkipCount());
assertEquals(0, stepExecution.getReadSkipCount());
assertEquals(5, stepExecution.getReadCount());
// Write count is incremented even if nothing happens
assertEquals(5, stepExecution.getWriteCount());
assertEquals(0, stepExecution.getFilterCount());
assertEquals(0, stepExecution.getRollbackCount());

// writer skips "4"
assertTrue(reader.getRead().contains("4"));

assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
assertStepExecutionsAreEqual(stepExecution, repository.getLastStepExecution(jobExecution.getJobInstance(), step
.getName()));
}

/**
* Check items causing errors are skipped as expected.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2013 the original author or authors.
* Copyright 2006-2017 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.
Expand Down Expand Up @@ -27,6 +27,7 @@
import java.util.List;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ChunkListener;
Expand Down Expand Up @@ -475,32 +476,6 @@ public void onWriteError(Exception exception, List<? extends String> items) {

}

@Test
public void testNullWriter() throws Exception {

SimpleStepFactoryBean<String, String> factory = getStepFactory(new String[] { "foo", "bar", "spam" });
factory.setItemWriter(null);
factory.setItemProcessor(new ItemProcessor<String, String>() {
@Override
public String process(String item) throws Exception {
written.add(item);
return null;
}
});

Step step = factory.getObject();

job.setSteps(Collections.singletonList(step));

JobExecution jobExecution = repository.createJobExecution(job.getName(), new JobParameters());

job.execute(jobExecution);

assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
assertEquals("[foo, bar, spam]", written.toString());

}

private SimpleStepFactoryBean<String, String> getStepFactory(String... args) throws Exception {
SimpleStepFactoryBean<String, String> factory = new SimpleStepFactoryBean<String, String>();

Expand Down