From 44d640990d4b6d7792776dcd5ed77caf36805799 Mon Sep 17 00:00:00 2001 From: jpraet Date: Thu, 7 Mar 2013 19:36:31 +0100 Subject: [PATCH] add additional test case that shows a bug in the current StaxEventItemWriter.shouldDeleteIfEmpty: when the writer restarts from a previous execution where the output file was deleted, this fails because FileUtils.setUpOutputFile expects the file to be there on restart --- .../item/xml/StaxEventItemWriterTests.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java index 7a373ee92..2901b5deb 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java @@ -431,6 +431,24 @@ public class StaxEventItemWriterTests { writer.update(executionContext); writer.close(); + writer = createItemWriter(); + writer.setShouldDeleteIfEmpty(true); + writer.open(executionContext); + writer.close(); + String content = getOutputFileContent(); + assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); + } + + /** + * Test that the writer can restart if the previous execution deleted empty file. + */ + @Test + public void testDeleteIfEmptyRestart() throws Exception { + writer.setShouldDeleteIfEmpty(true); + writer.open(executionContext); + writer.update(executionContext); + writer.close(); + assertFalse(resource.getFile().exists()); writer = createItemWriter(); writer.setShouldDeleteIfEmpty(true); writer.open(executionContext);