Search in sources :

Example 16 with FieldGroup

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

the class CsvFieldReaderTest method testWithSimpleDocumentWithoutHeader.

@Test
public void testWithSimpleDocumentWithoutHeader() throws Exception {
    CsvConfig csvConfig = new CsvConfig();
    CsvFieldReader csvFieldReader = new CsvFieldReader(csvConfig);
    csvFieldReader.setDocument(new ByteArrayInputStream("Bob,Smith\nAndrew,Johnson".getBytes()));
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(AtlasInternalSession.Head.class));
    CsvField csvField = new CsvField();
    csvField.setName("1");
    csvField.setColumn(1);
    csvField.setPath("/<>/1");
    when(session.head().getSourceField()).thenReturn(csvField);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    FieldGroup field = (FieldGroup) csvFieldReader.read(session);
    assertEquals(0, audits.getAudit().size());
    assertEquals("Smith", field.getField().get(0).getValue());
    assertEquals("Johnson", field.getField().get(1).getValue());
}
Also used : Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) ByteArrayInputStream(java.io.ByteArrayInputStream) FieldGroup(io.atlasmap.v2.FieldGroup) CsvField(io.atlasmap.csv.v2.CsvField) Test(org.junit.jupiter.api.Test)

Example 17 with FieldGroup

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

the class DefaultAtlasFieldActionsServiceTest method testProcessActionForEachCollectionItem.

@Test
public void testProcessActionForEachCollectionItem() throws Exception {
    DefaultAtlasSession session = mock(DefaultAtlasSession.class);
    FieldGroup fieldGroup = new FieldGroup();
    Field field1 = new SimpleField();
    field1.setPath("/fields<0>");
    field1.setValue("one");
    fieldGroup.getField().add(field1);
    Field field2 = new SimpleField();
    field2.setPath("/fields<1>");
    field2.setValue("two");
    fieldGroup.getField().add(field2);
    Field field4 = new SimpleField();
    field4.setPath("/fields<3>");
    field4.setValue("four");
    fieldGroup.getField().add(field4);
    Action action = new Uppercase();
    fieldGroup.setActions(new ArrayList<Action>());
    fieldGroup.getActions().add(action);
    Field answer = fieldActionsService.processActions(session, fieldGroup);
    assertEquals(FieldGroup.class, answer.getClass());
    FieldGroup answerGroup = (FieldGroup) answer;
    assertEquals(3, answerGroup.getField().size());
    Field f = answerGroup.getField().get(0);
    assertEquals("/fields<0>", f.getPath());
    assertEquals("ONE", f.getValue());
    f = answerGroup.getField().get(1);
    assertEquals("/fields<1>", f.getPath());
    assertEquals("TWO", f.getValue());
    f = answerGroup.getField().get(2);
    assertEquals("/fields<3>", f.getPath());
    assertEquals("FOUR", f.getValue());
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) Action(io.atlasmap.v2.Action) FieldGroup(io.atlasmap.v2.FieldGroup) Uppercase(io.atlasmap.v2.Uppercase) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.jupiter.api.Test)

Example 18 with FieldGroup

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

the class DefaultAtlasExpressionProcessorTest method testCollection.

@Test
public void testCollection() throws Exception {
    FieldGroup source = populateCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "foo");
    String expression = String.format("IF(ISEMPTY(${%s:/testPathfoo<0>}), null, ${%s:/testPathfoo<>})", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
    recreateSession();
    FieldGroup wrapper = new FieldGroup();
    wrapper.getField().add(source);
    wrapper.getField().add(source.getField().get(0));
    session.head().setSourceField(wrapper);
    DefaultAtlasExpressionProcessor.processExpression(session, expression);
    assertFalse(session.hasErrors(), printAudit(session));
    assertEquals(FieldGroup.class, session.head().getSourceField().getClass());
    FieldGroup fieldGroup = (FieldGroup) session.head().getSourceField();
    assertEquals("/testPathfoo<>", fieldGroup.getPath());
    assertEquals(10, fieldGroup.getField().size());
    assertEquals("foo0", fieldGroup.getField().get(0).getValue());
}
Also used : FieldGroup(io.atlasmap.v2.FieldGroup) Test(org.junit.jupiter.api.Test)

Example 19 with FieldGroup

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

the class DefaultAtlasExpressionProcessorTest method testFilter.

@Test
public void testFilter() throws Exception {
    FieldGroup source = populateComplexCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "foo");
    String expression = String.format("FILTER(${%s:/testPathfoo<>}, ${/value} != 'foo1')", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
    recreateSession();
    session.head().setSourceField(source);
    DefaultAtlasExpressionProcessor.processExpression(session, expression);
    assertFalse(session.hasErrors(), printAudit(session));
    assertEquals(FieldGroup.class, session.head().getSourceField().getClass());
    FieldGroup fieldGroup = (FieldGroup) session.head().getSourceField();
    assertEquals("/testPathfoo<>", fieldGroup.getPath());
    assertEquals(9, fieldGroup.getField().size());
    FieldGroup childFieldGroup = (FieldGroup) fieldGroup.getField().get(0);
    assertEquals("/testPathfoo<0>", childFieldGroup.getPath());
    assertEquals(1, childFieldGroup.getField().size());
    assertEquals("foo0", childFieldGroup.getField().get(0).getValue());
    childFieldGroup = (FieldGroup) fieldGroup.getField().get(1);
    assertEquals("/testPathfoo<1>", childFieldGroup.getPath());
    assertEquals(1, childFieldGroup.getField().size());
    assertEquals("foo2", childFieldGroup.getField().get(0).getValue());
}
Also used : FieldGroup(io.atlasmap.v2.FieldGroup) Test(org.junit.jupiter.api.Test)

Example 20 with FieldGroup

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

the class DefaultAtlasExpressionProcessorTest method testComplexCollection.

@Test
public void testComplexCollection() throws Exception {
    populateComplexCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "foo");
    String expression = String.format("IF(ISEMPTY(${%s:/testPathfoo<0>/value}), null, ${%s:/testPathfoo<>/value})", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
    recreateSession();
    FieldGroup wrapper = new FieldGroup();
    wrapper.getField().add((Field) reader.sources.get("/testPathfoo<0>/value"));
    wrapper.getField().add((Field) reader.sources.get("/testPathfoo<>/value"));
    session.head().setSourceField(wrapper);
    DefaultAtlasExpressionProcessor.processExpression(session, expression);
    assertFalse(session.hasErrors(), printAudit(session));
    assertEquals(FieldGroup.class, session.head().getSourceField().getClass());
    FieldGroup fieldGroup = (FieldGroup) session.head().getSourceField();
    assertEquals("/testPathfoo<>/value", fieldGroup.getPath());
    assertEquals(10, fieldGroup.getField().size());
    Field childField = fieldGroup.getField().get(0);
    assertEquals("/testPathfoo<0>/value", childField.getPath());
    assertEquals("foo0", childField.getValue());
    childField = fieldGroup.getField().get(1);
    assertEquals("/testPathfoo<1>/value", childField.getPath());
    assertEquals("foo1", childField.getValue());
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) FieldGroup(io.atlasmap.v2.FieldGroup) 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