Purge ItemProcessor
This commit is contained in:
@@ -25,8 +25,7 @@ import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.file.FlatFileItemWriter;
|
||||
import org.springframework.batch.io.file.transform.Converter;
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
@@ -103,8 +102,9 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteString() throws IOException {
|
||||
public void testWriteString() throws Exception {
|
||||
inputSource.write(TEST_STRING);
|
||||
inputSource.close();
|
||||
String lineFromFile = readLine();
|
||||
@@ -114,8 +114,9 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteCollection() throws IOException {
|
||||
public void testWriteCollection() throws Exception {
|
||||
inputSource.write(Collections.singleton(TEST_STRING));
|
||||
inputSource.close();
|
||||
String lineFromFile = readLine();
|
||||
@@ -124,10 +125,11 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteWithConverter() throws IOException {
|
||||
inputSource.setConverter(new Converter() {
|
||||
public Object convert(Object input) {
|
||||
public void testWriteWithConverter() throws Exception {
|
||||
inputSource.setTransformer(new ItemTransformer() {
|
||||
public Object transform(Object input) {
|
||||
return "FOO:" + input;
|
||||
}
|
||||
});
|
||||
@@ -141,10 +143,11 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteWithConverterAndInfiniteLoop() throws IOException {
|
||||
inputSource.setConverter(new Converter() {
|
||||
public Object convert(Object input) {
|
||||
public void testWriteWithConverterAndInfiniteLoop() throws Exception {
|
||||
inputSource.setTransformer(new ItemTransformer() {
|
||||
public Object transform(Object input) {
|
||||
return "FOO:" + input;
|
||||
}
|
||||
});
|
||||
@@ -158,10 +161,11 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteWithConverterAndInfiniteLoopInCollection() throws IOException {
|
||||
inputSource.setConverter(new Converter() {
|
||||
public Object convert(Object input) {
|
||||
public void testWriteWithConverterAndInfiniteLoopInCollection() throws Exception {
|
||||
inputSource.setTransformer(new ItemTransformer() {
|
||||
public Object transform(Object input) {
|
||||
return "FOO:" + input;
|
||||
}
|
||||
});
|
||||
@@ -176,12 +180,13 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteWithConverterAndInfiniteLoopInConvertedCollection() throws IOException {
|
||||
inputSource.setConverter(new Converter() {
|
||||
public void testWriteWithConverterAndInfiniteLoopInConvertedCollection() throws Exception {
|
||||
inputSource.setTransformer(new ItemTransformer() {
|
||||
boolean converted = false;
|
||||
|
||||
public Object convert(Object input) {
|
||||
public Object transform(Object input) {
|
||||
if (converted) {
|
||||
return input;
|
||||
}
|
||||
@@ -205,10 +210,11 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteWithConverterAndString() throws IOException {
|
||||
inputSource.setConverter(new Converter() {
|
||||
public Object convert(Object input) {
|
||||
public void testWriteWithConverterAndString() throws Exception {
|
||||
inputSource.setTransformer(new ItemTransformer() {
|
||||
public Object transform(Object input) {
|
||||
return "FOO:" + input;
|
||||
}
|
||||
});
|
||||
@@ -221,10 +227,11 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteWithConverterAndCollectionOfString() throws IOException {
|
||||
inputSource.setConverter(new Converter() {
|
||||
public Object convert(Object input) {
|
||||
public void testWriteWithConverterAndCollectionOfString() throws Exception {
|
||||
inputSource.setTransformer(new ItemTransformer() {
|
||||
public Object transform(Object input) {
|
||||
return "FOO:" + input;
|
||||
}
|
||||
});
|
||||
@@ -237,8 +244,9 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteArray() throws IOException {
|
||||
public void testWriteArray() throws Exception {
|
||||
inputSource.write(new String[] { TEST_STRING, TEST_STRING });
|
||||
inputSource.close();
|
||||
String lineFromFile = readLine();
|
||||
@@ -249,8 +257,9 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Regular usage of <code>write(String[], LineDescriptor)</code> method
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testWriteRecord() throws IOException {
|
||||
public void testWriteRecord() throws Exception {
|
||||
String args = "1";
|
||||
|
||||
// AggregatorStub ignores the LineDescriptor, so we pass null
|
||||
@@ -287,7 +296,7 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
assertEquals("testLine1", lineFromFile);
|
||||
}
|
||||
|
||||
public void testRestart() throws IOException {
|
||||
public void testRestart() throws Exception {
|
||||
|
||||
// write some lines
|
||||
inputSource.write("testLine1");
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.writer.CompositeItemTransformer;
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
|
||||
/**
|
||||
* Tests for {@link CompositeItemTransformer}.
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -8,9 +8,8 @@ import java.util.Properties;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.processor.CompositeItemWriter;
|
||||
import org.springframework.batch.item.writer.CompositeItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
@@ -21,7 +20,7 @@ import org.springframework.batch.statistics.StatisticsProvider;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class CompositeItemProcessorTests extends TestCase {
|
||||
public class CompositeItemWriterTests extends TestCase {
|
||||
|
||||
// object under test
|
||||
private CompositeItemWriter itemProcessor = new CompositeItemWriter();
|
||||
@@ -64,11 +63,11 @@ public class CompositeItemProcessorTests extends TestCase {
|
||||
*/
|
||||
public void testRestart() {
|
||||
//this mock with undefined behavior makes sure not-Restartable processor is ignored
|
||||
MockControl p1c = MockControl.createStrictControl(ItemProcessor.class);
|
||||
final ItemProcessor p1 = (ItemProcessor) p1c.getMock();
|
||||
MockControl p1c = MockControl.createStrictControl(ItemWriter.class);
|
||||
final ItemWriter p1 = (ItemWriter) p1c.getMock();
|
||||
|
||||
final ItemProcessor p2 = new ItemProcessorStub();
|
||||
final ItemProcessor p3 = new ItemProcessorStub();
|
||||
final ItemWriter p2 = new ItemWriterStub();
|
||||
final ItemWriter p3 = new ItemWriterStub();
|
||||
List itemProcessors = new ArrayList(){{
|
||||
add(p1);
|
||||
add(p2);
|
||||
@@ -80,10 +79,10 @@ public class CompositeItemProcessorTests extends TestCase {
|
||||
itemProcessor.restoreFrom(rd);
|
||||
|
||||
for (Iterator iterator = itemProcessors.iterator(); iterator.hasNext();) {
|
||||
ItemProcessor processor = (ItemProcessor) iterator.next();
|
||||
if (processor instanceof ItemProcessorStub) {
|
||||
ItemWriter processor = (ItemWriter) iterator.next();
|
||||
if (processor instanceof ItemWriterStub) {
|
||||
assertTrue("Injected processors are restarted",
|
||||
((ItemProcessorStub)processor).restarted);
|
||||
((ItemWriterStub)processor).restarted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +92,7 @@ public class CompositeItemProcessorTests extends TestCase {
|
||||
* Stub for testing restart. Checks the restart data received is the same that was returned by
|
||||
* <code>getRestartData()</code>
|
||||
*/
|
||||
private static class ItemProcessorStub implements ItemProcessor, Restartable, StatisticsProvider {
|
||||
private static class ItemWriterStub implements ItemWriter, Restartable, StatisticsProvider {
|
||||
|
||||
private static final String RESTART_KEY = "restartData";
|
||||
private static final String STATS_KEY = "stats";
|
||||
@@ -117,7 +116,7 @@ public class CompositeItemProcessorTests extends TestCase {
|
||||
restarted = true;
|
||||
}
|
||||
|
||||
public void process(Object data) throws Exception {
|
||||
public void write(Object data) throws Exception {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.io.sample.domain.FooService;
|
||||
import org.springframework.batch.item.writer.ItemWriterAdapter;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
* Tests for {@link ItemProcessorAdapter}.
|
||||
* Tests for {@link ItemWriterAdapter}.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class ItemProcessorAdapterIntegrationTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
public class ItemWriterAdapterIntegrationTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
private ItemProcessorAdapter processor;
|
||||
private ItemWriterAdapter processor;
|
||||
|
||||
private FooService fooService;
|
||||
|
||||
@@ -29,7 +30,7 @@ public class ItemProcessorAdapterIntegrationTests extends AbstractDependencyInje
|
||||
public void testProcess() throws Exception {
|
||||
Foo foo;
|
||||
while ((foo = fooService.generateFoo()) != null) {
|
||||
processor.process(foo);
|
||||
processor.write(foo);
|
||||
}
|
||||
|
||||
List input = fooService.getGeneratedFoos();
|
||||
@@ -44,7 +45,7 @@ public class ItemProcessorAdapterIntegrationTests extends AbstractDependencyInje
|
||||
}
|
||||
|
||||
//setter for auto-injection
|
||||
public void setProcessor(ItemProcessorAdapter processor) {
|
||||
public void setProcessor(ItemWriterAdapter processor) {
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -23,6 +23,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.writer.DelegatingItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
@@ -1,9 +1,10 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.io.sample.domain.FooService;
|
||||
import org.springframework.batch.item.writer.PropertyExtractingDelegatingItemWriter;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
|
||||
/**
|
||||
@@ -1,9 +1,11 @@
|
||||
package org.springframework.batch.item.processor;
|
||||
package org.springframework.batch.item.writer;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
import org.springframework.batch.item.writer.ItemTransformerItemWriterr;
|
||||
|
||||
/**
|
||||
* Tests for {@link ItemTransformerItemWriterr}.
|
||||
Reference in New Issue
Block a user