Search in sources :

Example 11 with TargetOrderArray

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());
}
Also used : Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) JavaField(io.atlasmap.java.v2.JavaField) FieldGroup(io.atlasmap.v2.FieldGroup) TargetContact(io.atlasmap.java.test.TargetContact) TargetOrder(io.atlasmap.java.test.TargetOrder) TargetTestClass(io.atlasmap.java.test.TargetTestClass) TargetOrderArray(io.atlasmap.java.test.TargetOrderArray) Test(org.junit.jupiter.api.Test)

Aggregations

TargetOrder (io.atlasmap.java.test.TargetOrder)11 TargetOrderArray (io.atlasmap.java.test.TargetOrderArray)11 TargetAddress (io.atlasmap.java.test.TargetAddress)8 TargetContact (io.atlasmap.java.test.TargetContact)5 TargetTestClass (io.atlasmap.java.test.TargetTestClass)5 TestListOrders (io.atlasmap.java.test.TestListOrders)4 Test (org.junit.Test)4 AtlasException (io.atlasmap.api.AtlasException)3 BaseOrder (io.atlasmap.java.test.BaseOrder)3 Test (org.junit.jupiter.api.Test)3 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)2 JavaField (io.atlasmap.java.v2.JavaField)2 Field (io.atlasmap.v2.Field)2 StateEnumClassLong (io.atlasmap.java.test.StateEnumClassLong)1 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)1 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)1 Audits (io.atlasmap.v2.Audits)1 FieldGroup (io.atlasmap.v2.FieldGroup)1 LookupTable (io.atlasmap.v2.LookupTable)1 Before (org.junit.Before)1