Search in sources :

Example 86 with FieldGroup

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

the class DefaultAtlasFieldActionsServiceTest method testProcessOldExpressionActionConcatenateCollection.

@Test
public void testProcessOldExpressionActionConcatenateCollection() throws Exception {
    DefaultAtlasSession session = mock(DefaultAtlasSession.class);
    Field delimiter = new SimpleField();
    delimiter.setPath("/delim");
    delimiter.setValue("-");
    FieldGroup list = new FieldGroup();
    list.setPath("/fields<>");
    list.setCollectionType(CollectionType.LIST);
    Field field1 = new SimpleField();
    field1.setPath("/fields<0>");
    field1.setValue("one");
    list.getField().add(field1);
    Field field2 = new SimpleField();
    field2.setPath("/fields<1>");
    field2.setValue("two");
    list.getField().add(field2);
    Field field3 = new SimpleField();
    field3.setPath("/fields<2>");
    field3.setValue("three");
    list.getField().add(field3);
    FieldGroup fieldGroup = new FieldGroup();
    fieldGroup.getField().add(delimiter);
    fieldGroup.getField().add(list);
    Expression action = new Expression();
    action.setExpression("concatenate(${0}, true, capitalize(${1}))");
    fieldGroup.setActions(new ArrayList<Action>());
    fieldGroup.getActions().add(action);
    Field answer = fieldActionsService.processActions(session, fieldGroup);
    assertEquals("$ATLASMAP", answer.getPath());
    assertEquals("One-Two-Three", answer.getValue());
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) Action(io.atlasmap.v2.Action) FieldGroup(io.atlasmap.v2.FieldGroup) Expression(io.atlasmap.v2.Expression) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.jupiter.api.Test)

Example 87 with FieldGroup

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

the class DefaultAtlasExpressionProcessorTest method testSelect.

@Test
public void testSelect() throws Exception {
    FieldGroup source = populateComplexCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "foo");
    String expression = String.format("SELECT(${%s:/testPathfoo<>}, ${/value})", 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<>/value", fieldGroup.getPath());
    assertEquals(10, fieldGroup.getField().size());
    Field child = fieldGroup.getField().get(0);
    assertEquals("/testPathfoo<0>/value", child.getPath());
    assertEquals("foo0", child.getValue());
    child = fieldGroup.getField().get(1);
    assertEquals("/testPathfoo<1>/value", child.getPath());
    assertEquals("foo1", child.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)

Example 88 with FieldGroup

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

the class DefaultAtlasExpressionProcessorTest method testFilterSelect.

@Test
public void testFilterSelect() throws Exception {
    FieldGroup source = populateComplexCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "foo");
    String expression = String.format("SELECT(FILTER(${%s:/testPathfoo<>}, ${/value} != 'foo1'), ${/value})", 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<>/value", fieldGroup.getPath());
    assertEquals(9, fieldGroup.getField().size());
    Field child = fieldGroup.getField().get(0);
    assertEquals("/testPathfoo<0>/value", child.getPath());
    assertEquals("foo0", child.getValue());
    child = fieldGroup.getField().get(1);
    assertEquals("/testPathfoo<1>/value", child.getPath());
    assertEquals("foo2", child.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)

Example 89 with FieldGroup

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

the class DefaultAtlasExpressionProcessorTest method testRepeatCount.

@Test
public void testRepeatCount() throws Exception {
    Field source = populateSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, FieldType.STRING, "foo");
    populateComplexCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "count");
    String expression = String.format("REPEAT(COUNT(${%s:/testPathcount<>/value}), ${%s:/testPathfoo})", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
    recreateSession();
    FieldGroup wrapper = new FieldGroup();
    wrapper.getField().add((Field) reader.sources.get("/testPathcount<>/value"));
    wrapper.getField().add(source);
    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());
    Field child = fieldGroup.getField().get(0);
    assertEquals("/testPathfoo<0>", child.getPath());
    assertNull(child.getIndex());
    assertEquals("foo", child.getValue());
    child = fieldGroup.getField().get(1);
    assertEquals("/testPathfoo<1>", child.getPath());
    assertNull(child.getIndex());
    assertEquals("foo", child.getValue());
    child = fieldGroup.getField().get(9);
    assertEquals("/testPathfoo<9>", child.getPath());
    assertNull(child.getIndex());
    assertEquals("foo", child.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)

Example 90 with FieldGroup

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

the class DefaultAtlasPreviewContextTest method testProcessPreviewSplitCollection.

@Test
public void testProcessPreviewSplitCollection() throws AtlasException {
    Mapping m = new Mapping();
    Field source = new SimpleField();
    source.setFieldType(FieldType.STRING);
    source.setPath("/source");
    source.setValue("one two three four");
    source.setActions(new ArrayList<>());
    Split action = new Split();
    action.setDelimiter(" ");
    source.getActions().add(action);
    m.getInputField().add(source);
    Field target = new SimpleField();
    target.setCollectionType(CollectionType.LIST);
    target.setFieldType(FieldType.STRING);
    target.setPath("/results<>");
    m.getOutputField().add(target);
    Audits audits = previewContext.processPreview(m);
    assertEquals(0, audits.getAudit().size(), printAudit(audits));
    target = m.getOutputField().get(0);
    assertEquals(FieldGroup.class, target.getClass());
    FieldGroup targetGroup = (FieldGroup) target;
    Field one = targetGroup.getField().get(0);
    Field two = targetGroup.getField().get(1);
    Field three = targetGroup.getField().get(2);
    Field four = targetGroup.getField().get(3);
    assertEquals("/results<0>", one.getPath());
    assertEquals("one", one.getValue());
    assertEquals("/results<1>", two.getPath());
    assertEquals("two", two.getValue());
    assertEquals("/results<2>", three.getPath());
    assertEquals("three", three.getValue());
    assertEquals("/results<3>", four.getPath());
    assertEquals("four", four.getValue());
    target = new SimpleField();
    target.setCollectionType(CollectionType.NONE);
    target.setPath("/collection<>/result");
    target.setFieldType(FieldType.STRING);
    target.setIndex(0);
    m.getOutputField().clear();
    m.getOutputField().add(target);
    audits = previewContext.processPreview(m);
    assertEquals(0, audits.getAudit().size(), printAudit(audits));
    target = m.getOutputField().get(0);
    assertEquals(FieldGroup.class, target.getClass());
    targetGroup = (FieldGroup) target;
    one = targetGroup.getField().get(0);
    two = targetGroup.getField().get(1);
    three = targetGroup.getField().get(2);
    four = targetGroup.getField().get(3);
    assertEquals("/collection<0>/result", one.getPath());
    assertEquals("one", one.getValue());
    assertEquals("/collection<1>/result", two.getPath());
    assertEquals("two", two.getValue());
    assertEquals("/collection<2>/result", three.getPath());
    assertEquals("three", three.getValue());
    assertEquals("/collection<3>/result", four.getPath());
    assertEquals("four", four.getValue());
}
Also used : SimpleField(io.atlasmap.v2.SimpleField) ConstantField(io.atlasmap.v2.ConstantField) Field(io.atlasmap.v2.Field) Audits(io.atlasmap.v2.Audits) FieldGroup(io.atlasmap.v2.FieldGroup) Mapping(io.atlasmap.v2.Mapping) SimpleField(io.atlasmap.v2.SimpleField) Split(io.atlasmap.v2.Split) 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