m_parser.initializeMessageTable(table);
TransferObject root, record;
List recordList;
root = m_parser.parse(new StringInput(
"\nfirst,second,third,fourth\n" +
";This is a comment\n" +
"a,b,c,d\n" +
";So is this\n" +
"a2,b2,c2,d2\n"
), table);
recordList = (List)root.getValue("Data4H");
assertEquals(2, recordList.size());
record = (TransferObject)recordList.get(0);
assertEquals("a", record.getValue("first"));
assertEquals("b", record.getValue("second"));
assertEquals("c", record.getValue("third"));
assertEquals("d", record.getValue("fourth"));
record = (TransferObject)recordList.get(1);
assertEquals("a2", record.getValue("first"));
assertEquals("b2", record.getValue("second"));
assertEquals("c2", record.getValue("third"));
assertEquals("d2", record.getValue("fourth"));
//Test re-ordered header
root = m_parser.parse(new StringInput(
"fourth,second,third,first\n" +
"d,b,c,a\n" +
"d2,b2,c2,a2\n"
), table);
recordList = (List)root.getValue("Data4H");
assertEquals(2, recordList.size());
record = (TransferObject)recordList.get(0);
assertEquals("a", record.getValue("first"));
assertEquals("b", record.getValue("second"));
assertEquals("c", record.getValue("third"));
assertEquals("d", record.getValue("fourth"));
record = (TransferObject)recordList.get(1);
assertEquals("a2", record.getValue("first"));
assertEquals("b2", record.getValue("second"));
assertEquals("c2", record.getValue("third"));
assertEquals("d2", record.getValue("fourth"));
//Test re-ordered, short header
root = m_parser.parse(new StringInput(
"second,third,first\n" +
"b,c,a\n" +
"b2,c2,a2\n"
), table);
recordList = (List)root.getValue("Data4H");
assertEquals(2, recordList.size());
record = (TransferObject)recordList.get(0);
assertEquals("a", record.getValue("first"));
assertEquals("b", record.getValue("second"));
assertEquals("c", record.getValue("third"));
assertFalse(record.hasValue("fourth"));
record = (TransferObject)recordList.get(1);
assertEquals("a2", record.getValue("first"));
assertEquals("b2", record.getValue("second"));
assertEquals("c2", record.getValue("third"));
assertFalse(record.hasValue("fourth"));
root = m_parser.parse(new StringInput(
"\n\nfirst,second,third\n" +
"\n\na,b,c\n" +
"a2,b2,c2\n"
), table);
recordList = (List)root.getValue("Data4H");
assertEquals(2, recordList.size());
record = (TransferObject)recordList.get(0);
assertEquals("a", record.getValue("first"));
assertEquals("b", record.getValue("second"));
assertEquals("c", record.getValue("third"));
record = (TransferObject)recordList.get(1);
assertEquals("a2", record.getValue("first"));
assertEquals("b2", record.getValue("second"));
assertEquals("c2", record.getValue("third"));
root = m_parser.parse(new StringInput(
"\n\n\na,b\n" +
"a2,b2,c2\n"
), table);
recordList = (List)root.getValue("Data1R1O");
assertEquals(2, recordList.size());
record = (TransferObject)recordList.get(0);
assertEquals("a", record.getValue("first"));
assertEquals("b", record.getValue("second"));
assertFalse(record.hasValue("third"));
record = (TransferObject)recordList.get(1);
assertEquals("a2", record.getValue("first"));
assertEquals("b2", record.getValue("second"));
assertFalse(record.hasValue("third"));
root = m_parser.parse(new StringInput(
"\n\n\n\na,b,c,d,e\n" +
"a2,b2,c2,d2,e2\n"
), table);
recordList = (List)root.getValue("Data5R");
assertEquals(2, recordList.size());
record = (TransferObject)recordList.get(0);
assertEquals("a", record.getValue("first"));
assertEquals("b", record.getValue("second"));
assertEquals("c", record.getValue("third"));
assertEquals("d", record.getValue("fourth"));
assertEquals("e", record.getValue("fifth"));
record = (TransferObject)recordList.get(1);
assertEquals("a2", record.getValue("first"));
assertEquals("b2", record.getValue("second"));
assertEquals("c2", record.getValue("third"));
assertEquals("d2", record.getValue("fourth"));
assertEquals("e2", record.getValue("fifth"));
try
{
root = m_parser.parse(new StringInput(
"a,b,c,d,e,f\n" +
"a2,b2,c2,d2,e2,f2\n"
), table);
fail();
}