Search in sources :

Example 41 with FieldGroup

use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.

the class JsonFieldReaderTest method testReadParentCollectionEmptyItem.

@Test
public void testReadParentCollectionEmptyItem() throws Exception {
    final String document = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("complex-repeated-result-empty-item.json").toURI())));
    reader.setDocument(document);
    FieldGroup address = new FieldGroup();
    address.setFieldType(FieldType.COMPLEX);
    address.setDocId("json");
    address.setPath("/orders[]/address");
    JsonField addressLine1 = AtlasJsonModelFactory.createJsonField();
    addressLine1.setFieldType(FieldType.STRING);
    addressLine1.setDocId("json");
    addressLine1.setPath("/orders[]/address/addressLine1");
    address.getField().add(addressLine1);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(address);
    Field readField = reader.read(session);
    assertNotNull(readField);
    assertEquals(FieldGroup.class, readField.getClass());
    FieldGroup readGroup = FieldGroup.class.cast(readField);
    assertEquals(2, readGroup.getField().size());
    FieldGroup readAddress = (FieldGroup) readGroup.getField().get(0);
    assertEquals("/orders[0]/address", readAddress.getPath());
    assertEquals(1, readAddress.getField().size());
    Field readAddressLine = (Field) readAddress.getField().get(0);
    assertEquals("/orders[0]/address/addressLine1", readAddressLine.getPath());
    assertEquals("123 Main St (1)", readAddressLine.getValue());
    readAddress = (FieldGroup) readGroup.getField().get(1);
    assertEquals("/orders[2]/address", readAddress.getPath());
    assertEquals(1, readAddress.getField().size());
    readAddressLine = (Field) readAddress.getField().get(0);
    assertEquals("/orders[2]/address/addressLine1", readAddressLine.getPath());
    assertEquals("123 Main St (3)", readAddressLine.getValue());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) Test(org.junit.jupiter.api.Test)

Example 42 with FieldGroup

use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.

the class JsonFieldReaderTest method testReadParentCollection.

@Test
public void testReadParentCollection() throws Exception {
    final String document = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("complex-repeated-result.json").toURI())));
    reader.setDocument(document);
    FieldGroup address = new FieldGroup();
    address.setFieldType(FieldType.COMPLEX);
    address.setDocId("json");
    address.setPath("/orders[]/address");
    JsonField addressLine1 = AtlasJsonModelFactory.createJsonField();
    addressLine1.setFieldType(FieldType.STRING);
    addressLine1.setDocId("json");
    addressLine1.setPath("/orders[]/address/addressLine1");
    address.getField().add(addressLine1);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(address);
    Field readField = reader.read(session);
    assertNotNull(readField);
    assertEquals(FieldGroup.class, readField.getClass());
    FieldGroup readGroup = FieldGroup.class.cast(readField);
    assertEquals(5, readGroup.getField().size());
    for (int i = 0; i < 5; i++) {
        FieldGroup readAddress = (FieldGroup) readGroup.getField().get(i);
        assertEquals("/orders[" + i + "]/address", readAddress.getPath());
        assertEquals(1, readAddress.getField().size());
        Field readAddressLine = (Field) readAddress.getField().get(0);
        assertEquals("/orders[" + i + "]/address/addressLine1", readAddressLine.getPath());
        assertEquals("123 Main St (" + (i + 1) + ")", readAddressLine.getValue());
    }
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) Test(org.junit.jupiter.api.Test)

Example 43 with FieldGroup

use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.

the class KafkaConnectFieldReaderTest method testReadRootComplex.

@Test
public void testReadRootComplex() throws Exception {
    reader.setDocument(createTestDoc(1).get(0));
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    FieldGroup field = createRootField();
    when(session.head().getSourceField()).thenReturn(field);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    FieldGroup answer = (FieldGroup) reader.read(session);
    assertEquals(4, answer.getField().size());
    assertRoot(answer, "", 0);
    Field f0 = createF0Field(new AtlasPath("/"));
    when(session.head().getSourceField()).thenReturn(f0);
    assertf0(reader.read(session), "");
    Field fl0 = createFl0Field(new AtlasPath("/"));
    when(session.head().getSourceField()).thenReturn(fl0);
    assertfl0((FieldGroup) reader.read(session), "", 0);
    Field fc0 = createFc0Field(new AtlasPath("/"));
    when(session.head().getSourceField()).thenReturn(fc0);
    assertfc0((FieldGroup) reader.read(session), "");
    Field fcl0 = createFcl0Field(new AtlasPath("/"));
    when(session.head().getSourceField()).thenReturn(fcl0);
    assertfcl0((FieldGroup) reader.read(session), "", 0);
}
Also used : KafkaConnectField(io.atlasmap.kafkaconnect.v2.KafkaConnectField) Field(io.atlasmap.v2.Field) Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) AtlasPath(io.atlasmap.core.AtlasPath) Test(org.junit.jupiter.api.Test)

Example 44 with FieldGroup

use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.

the class KafkaConnectFieldReaderTest method testReadIndexedCollectionRootComplex.

@Test
public void testReadIndexedCollectionRootComplex() throws Exception {
    reader.setDocument(createTestDoc(3));
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    FieldGroup field = createIndexedCollectionRootField(1);
    when(session.head().getSourceField()).thenReturn(field);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    FieldGroup answer = (FieldGroup) reader.read(session);
    assertEquals(4, answer.getField().size());
    assertRoot(answer, "/<" + 1 + ">", 1);
    Field f0 = createF0Field(new AtlasPath("/<1>"));
    when(session.head().getSourceField()).thenReturn(f0);
    assertf0(reader.read(session), "/<1>");
    Field fl0 = createFl0Field(new AtlasPath("/<1>"));
    when(session.head().getSourceField()).thenReturn(fl0);
    assertfl0((FieldGroup) reader.read(session), "/<1>", 1);
    Field fc0 = createFc0Field(new AtlasPath("/<1>"));
    when(session.head().getSourceField()).thenReturn(fc0);
    assertfc0((FieldGroup) reader.read(session), "/<1>");
    Field fcl0 = createFcl0Field(new AtlasPath("/<1>"));
    when(session.head().getSourceField()).thenReturn(fcl0);
    assertfcl0((FieldGroup) reader.read(session), "/<1>", 1);
}
Also used : KafkaConnectField(io.atlasmap.kafkaconnect.v2.KafkaConnectField) Field(io.atlasmap.v2.Field) Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) AtlasPath(io.atlasmap.core.AtlasPath) Test(org.junit.jupiter.api.Test)

Example 45 with FieldGroup

use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.

the class KafkaConnectFieldReaderTest method testReadCollectionRootComplex.

@Test
public void testReadCollectionRootComplex() throws Exception {
    reader.setDocument(createTestDoc(3));
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    FieldGroup field = createCollectionRootField();
    when(session.head().getSourceField()).thenReturn(field);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    FieldGroup answer = (FieldGroup) reader.read(session);
    assertEquals(3, answer.getField().size());
    for (int i = 0; i < answer.getField().size(); i++) {
        assertRoot((FieldGroup) answer.getField().get(i), "/<" + i + ">", i);
    }
    Field f0 = createF0Field(new AtlasPath("/<>"));
    when(session.head().getSourceField()).thenReturn(f0);
    FieldGroup f0answer = (FieldGroup) reader.read(session);
    assertEquals(3, f0answer.getField().size());
    for (int i = 0; i < f0answer.getField().size(); i++) {
        Field f = f0answer.getField().get(i);
        assertf0(f, "/<" + i + ">");
    }
    Field fl0 = createFl0Field(new AtlasPath("/<>"));
    when(session.head().getSourceField()).thenReturn(fl0);
    FieldGroup fl0answer = (FieldGroup) reader.read(session);
    assertEquals(9, fl0answer.getField().size());
    assertfl0(Arrays.asList(fl0answer.getField().get(0), fl0answer.getField().get(1), fl0answer.getField().get(2)), "/<0>", 0);
    assertfl0(Arrays.asList(fl0answer.getField().get(3), fl0answer.getField().get(4), fl0answer.getField().get(5)), "/<1>", 1);
    assertfl0(Arrays.asList(fl0answer.getField().get(6), fl0answer.getField().get(7), fl0answer.getField().get(8)), "/<2>", 2);
    Field fc0 = createFc0Field(new AtlasPath("/<>"));
    when(session.head().getSourceField()).thenReturn(fc0);
    FieldGroup fc0answer = (FieldGroup) reader.read(session);
    assertEquals(3, fc0answer.getField().size());
    for (int i = 0; i < fc0answer.getField().size(); i++) {
        FieldGroup f = (FieldGroup) fc0answer.getField().get(i);
        assertfc0(f, "/<" + i + ">");
    }
    Field fcl0 = createFcl0Field(new AtlasPath("/<>"));
    when(session.head().getSourceField()).thenReturn(fcl0);
    FieldGroup fcl0answer = (FieldGroup) reader.read(session);
    assertEquals(9, fcl0answer.getField().size());
    assertfcl0(Arrays.asList(fcl0answer.getField().get(0), fcl0answer.getField().get(1), fcl0answer.getField().get(2)), "/<0>", 0);
    assertfcl0(Arrays.asList(fcl0answer.getField().get(3), fcl0answer.getField().get(4), fcl0answer.getField().get(5)), "/<1>", 1);
    assertfcl0(Arrays.asList(fcl0answer.getField().get(6), fcl0answer.getField().get(7), fcl0answer.getField().get(8)), "/<2>", 2);
}
Also used : KafkaConnectField(io.atlasmap.kafkaconnect.v2.KafkaConnectField) Field(io.atlasmap.v2.Field) Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) AtlasPath(io.atlasmap.core.AtlasPath) Test(org.junit.jupiter.api.Test)

Aggregations

FieldGroup (io.atlasmap.v2.FieldGroup)110 Field (io.atlasmap.v2.Field)89 Test (org.junit.jupiter.api.Test)48 SimpleField (io.atlasmap.v2.SimpleField)32 AtlasPath (io.atlasmap.core.AtlasPath)28 ArrayList (java.util.ArrayList)24 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)17 CsvField (io.atlasmap.csv.v2.CsvField)16 AtlasException (io.atlasmap.api.AtlasException)15 Audits (io.atlasmap.v2.Audits)14 KafkaConnectField (io.atlasmap.kafkaconnect.v2.KafkaConnectField)13 ConstantField (io.atlasmap.v2.ConstantField)13 Head (io.atlasmap.spi.AtlasInternalSession.Head)12 JsonField (io.atlasmap.json.v2.JsonField)11 Mapping (io.atlasmap.v2.Mapping)11 PropertyField (io.atlasmap.v2.PropertyField)11 JavaField (io.atlasmap.java.v2.JavaField)10 XmlField (io.atlasmap.xml.v2.XmlField)9 SegmentContext (io.atlasmap.core.AtlasPath.SegmentContext)8 LinkedList (java.util.LinkedList)8