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());
}
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());
}
}
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);
}
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);
}
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);
}
Aggregations