IN PROGRESS - BATCH-763: Create callback for header and footer writing in xml and flat files
added footers to flatfile and stax writers
This commit is contained in:
@@ -203,11 +203,13 @@ public class FlatFileItemWriterTests {
|
||||
@Test
|
||||
public void testRestart() throws Exception {
|
||||
|
||||
writer.setFooterLines(new String[] { "footer" });
|
||||
|
||||
writer.open(executionContext);
|
||||
// write some lines
|
||||
writer.write(Arrays.asList(new String[] { "testLine1", "testLine2", "testLine3" }));
|
||||
// write more lines
|
||||
writer.write(Arrays.asList(new String[] {"testLine4", "testLine5"}));
|
||||
writer.write(Arrays.asList(new String[] { "testLine4", "testLine5" }));
|
||||
// get restart data
|
||||
writer.update(executionContext);
|
||||
// close template
|
||||
@@ -216,7 +218,7 @@ public class FlatFileItemWriterTests {
|
||||
// init with correct data
|
||||
writer.open(executionContext);
|
||||
// write more lines
|
||||
writer.write(Arrays.asList(new String[] {"testLine6","testLine7","testLine8"}));
|
||||
writer.write(Arrays.asList(new String[] { "testLine6", "testLine7", "testLine8" }));
|
||||
// get statistics
|
||||
writer.update(executionContext);
|
||||
// close template
|
||||
@@ -226,6 +228,8 @@ public class FlatFileItemWriterTests {
|
||||
for (int i = 1; i <= 8; i++) {
|
||||
assertEquals("testLine" + i, readLine());
|
||||
}
|
||||
|
||||
assertEquals("footer", readLine());
|
||||
|
||||
// 3 lines were written to the file after restart
|
||||
assertEquals(3, executionContext.getLong(ClassUtils.getShortName(FlatFileItemWriter.class) + ".written"));
|
||||
@@ -303,6 +307,17 @@ public class FlatFileItemWriterTests {
|
||||
assertEquals(TEST_STRING, lineFromFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteFooter() throws Exception {
|
||||
writer.setFooterLines(new String[] { "a", "b" });
|
||||
writer.open(executionContext);
|
||||
writer.write(Collections.singletonList(TEST_STRING));
|
||||
writer.close(executionContext);
|
||||
assertEquals(TEST_STRING, readLine());
|
||||
assertEquals("a", readLine());
|
||||
assertEquals("b", readLine());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteHeader() throws Exception {
|
||||
writer.setHeaderLines(new String[] { "a", "b" });
|
||||
|
||||
@@ -95,8 +95,9 @@ public class StaxEventItemWriterTests {
|
||||
// check the output is concatenation of 'before restart' and 'after
|
||||
// restart' writes.
|
||||
String outputFile = outputFileContent();
|
||||
|
||||
System.out.println(outputFile);
|
||||
assertEquals(2, StringUtils.countOccurrencesOf(outputFile, TEST_STRING));
|
||||
assertTrue(outputFile.contains("<root>" + TEST_STRING + TEST_STRING + "</root>"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +107,12 @@ public class StaxEventItemWriterTests {
|
||||
public void testWriteWithHeader() throws Exception {
|
||||
final Object header1 = new Object();
|
||||
final Object header2 = new Object();
|
||||
writer.setHeaderItems(new ArrayList<Object>() {{add(header1); add(header2); }});
|
||||
writer.setHeaderItems(new ArrayList<Object>() {
|
||||
{
|
||||
add(header1);
|
||||
add(header2);
|
||||
}
|
||||
});
|
||||
writer.open(executionContext);
|
||||
writer.write(items);
|
||||
String content = outputFileContent();
|
||||
|
||||
Reference in New Issue
Block a user