use of io.atlasmap.java.test.TargetOrderArray in project atlasmap by atlasmap.
the class JavaFieldReaderTest method testReadParentCollectionsChildren.
@Test
public void testReadParentCollectionsChildren() throws Exception {
TargetTestClass source = new TargetTestClass();
TargetOrderArray orderArray = new TargetOrderArray();
source.setOrderArray(orderArray);
TargetOrder[] orders = new TargetOrder[5];
orderArray.setOrders(orders);
for (int i = 0; i < 5; i++) {
TargetOrder order = new TargetOrder();
TargetContact c = new TargetContact();
c.setFirstName("f" + i);
c.setLastName("l" + i);
c.setPhoneNumber("p" + i);
c.setZipCode("z" + i);
order.setContact(c);
orders[i] = order;
}
reader.setDocument(source);
FieldGroup contactGroup = new FieldGroup();
contactGroup.setDocId("TargetTestClass");
contactGroup.setPath("/orderArray/orders[]/contact");
contactGroup.setFieldType(FieldType.COMPLEX);
Field firstNameField = new JavaField();
firstNameField.setDocId("TargetTestClass");
firstNameField.setPath("/orderArray/orders[]/contact/firstName");
firstNameField.setFieldType(FieldType.STRING);
contactGroup.getField().add(firstNameField);
fieldGroup = (FieldGroup) read(contactGroup);
assertEquals(0, audits.size());
assertEquals("/orderArray/orders[]/contact", fieldGroup.getPath());
assertEquals(FieldType.COMPLEX, fieldGroup.getFieldType());
assertNull(fieldGroup.getCollectionType());
assertEquals(5, fieldGroup.getField().size());
Field contact0 = fieldGroup.getField().get(0);
assertEquals(FieldGroup.class, contact0.getClass());
FieldGroup contact0Group = (FieldGroup) contact0;
assertEquals(1, contact0Group.getField().size());
assertEquals("/orderArray/orders[0]/contact", contact0Group.getPath());
assertEquals(FieldType.COMPLEX, contact0Group.getFieldType());
assertNull(contact0Group.getCollectionType());
Field firstName0 = contact0Group.getField().get(0);
assertEquals("/orderArray/orders[0]/contact/firstName", firstName0.getPath());
assertEquals(FieldType.STRING, firstName0.getFieldType());
assertNull(firstName0.getCollectionType());
assertEquals("f0", firstName0.getValue());
contactGroup.setPath("/orderArray/orders[1]/contact");
firstNameField.setPath("/orderArray/orders[1]/contact/firstName");
fieldGroup = (FieldGroup) read(contactGroup);
assertEquals(0, audits.size());
assertEquals(1, fieldGroup.getField().size());
assertEquals("/orderArray/orders[1]/contact", fieldGroup.getPath());
assertEquals(FieldType.COMPLEX, fieldGroup.getFieldType());
Field firstName1 = fieldGroup.getField().get(0);
assertEquals("/orderArray/orders[1]/contact/firstName", firstName1.getPath());
assertEquals(FieldType.STRING, firstName1.getFieldType());
assertEquals("f1", firstName1.getValue());
}
Aggregations