String sEmptyF1 = "__________"; // all padding chars
String sR2F2 = "|2012-03-19 15:26:43.000000000";
String sEmptyF2 = "|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^";
TransferObject record;
TransferObject root = m_parser.parse(new StringInput(
sR1F1 + sR1F2 + // record 1
sR1F1 + sR2F2 // record 2
), Repository.getMetadata().getMessage(sMessageName));
assertEquals(sMessageName, root.getClassName());
List recordList = (List)root.getValue("record");
assertEquals(2, recordList.size());
record = (TransferObject)recordList.get(0);
assertEquals(sR1F1, record.getValue("field_1"));
assertEquals(Primitive.toTimestamp(new Long(1269012397000L)), record.getValue("field_2"));
record = (TransferObject)recordList.get(1);
assertEquals(sR1F1, record.getValue("field_1"));
assertEquals(Primitive.toTimestamp(new Long(1332170803000L)), record.getValue("field_2"));
//
// Try some failure cases
//
try
{
m_parser.parse(new StringInput(
sR1F1 + sR1F2 + // record 1
sEmptyF1 + sR2F2 + // record 2, fails requiredness on field_1
sEmptyF1 + sEmptyF2 + // record 3
sR1F1 + sR2F2 // record 4
), Repository.getMetadata().getMessage(sMessageName));
}
catch (IntegrationException ex)
{
assertEquals("err.integration.parse.noDataForRequiredPart", ex.getErrorCode());
assertEquals(sMessageName + " record field_1", ex.getErrorArgs()[0]);
assertEquals(2, ((Integer)(ex.getErrorArgs()[1])).intValue()); // record 2 fails
}
try
{
m_parser.parse(new StringInput(
sR1F1 + sR1F2 + // record 1
sR1F1 + sR2F2 + // record 2
sR1F1 + sEmptyF2 + // record 3, fails requiredness on field_2
sR1F1 + sR2F2 // record 4
), Repository.getMetadata().getMessage(sMessageName));