Fix JsonFileItemWriter for multiple write's

Resolves BATCH-2749
This commit is contained in:
Evgenii Strepetov
2018-09-05 17:55:06 -07:00
committed by Michael Minella
parent c8a0a7d407
commit 7a3248cabf
4 changed files with 37 additions and 3 deletions

View File

@@ -59,6 +59,8 @@ public abstract class JsonFileItemWriterFunctionalTests {
private ExecutionContext executionContext;
private Trade trade1 = new Trade("123", 5, new BigDecimal("10.5"), "foo");
private Trade trade2 = new Trade("456", 10, new BigDecimal("20.5"), "bar");
private Trade trade3 = new Trade("789", 15, new BigDecimal("30.5"), "foobar");
private Trade trade4 = new Trade("987", 20, new BigDecimal("40.5"), "barfoo");
protected abstract JsonObjectMarshaller<Trade> getJsonObjectMarshaller();
protected abstract JsonObjectMarshaller<Trade> getJsonObjectMarshallerWithPrettyPrint();
@@ -93,6 +95,20 @@ public abstract class JsonFileItemWriterFunctionalTests {
this.resource.getFile());
}
@Test
public void testJsonWritingWithMultipleWrite() throws Exception {
// when
this.writer.open(this.executionContext);
this.writer.write(this.items);
this.writer.write(Arrays.asList(trade3, trade4));
this.writer.close();
// then
assertFileEquals(
new File(EXPECTED_FILE_DIRECTORY + "expected-trades-with-multiple-writes.json"),
this.resource.getFile());
}
@Test
public void testJsonWritingWithPrettyPrinting() throws Exception {
// given

View File

@@ -0,0 +1,6 @@
[
{"isin":"123","quantity":5,"price":10.5,"customer":"foo"},
{"isin":"456","quantity":10,"price":20.5,"customer":"bar"},
{"isin":"789","quantity":15,"price":30.5,"customer":"foobar"},
{"isin":"987","quantity":20,"price":40.5,"customer":"barfoo"}
]

View File

@@ -10,5 +10,17 @@
"quantity": 2,
"price": 1.4,
"customer": "bar"
},
{
"isin": "789",
"quantity": 3,
"price": 1.6,
"customer": "foobar"
},
{
"isin": "100",
"quantity": 4,
"price": 1.8,
"customer": "barfoo"
}
]