Search in sources :

Example 61 with Expression

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

the class DefaultAtlasFieldActionsServiceTest method testProcessOldExpressionActionWithRoot.

@Test
public void testProcessOldExpressionActionWithRoot() throws Exception {
    DefaultAtlasSession session = mock(DefaultAtlasSession.class);
    FieldGroup root = new FieldGroup();
    FieldGroup fieldGroup = new FieldGroup();
    root.getField().add(fieldGroup);
    fieldGroup.setPath("/fields<>");
    fieldGroup.setCollectionType(CollectionType.LIST);
    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 field3 = new SimpleField();
    field3.setPath("/fields<3>");
    field3.setValue("four");
    fieldGroup.getField().add(field3);
    Expression action = new Expression();
    action.setExpression("capitalize(${0})");
    root.setActions(new ArrayList<Action>());
    root.getActions().add(action);
    Field answer = fieldActionsService.processActions(session, root);
    assertEquals(FieldGroup.class, answer.getClass());
    FieldGroup answerGroup = (FieldGroup) answer;
    assertEquals(3, answerGroup.getField().size());
    Field f = answerGroup.getField().get(0);
    assertEquals("/$ATLASMAP<0>", f.getPath());
    assertEquals("One", f.getValue());
    f = answerGroup.getField().get(1);
    assertEquals("/$ATLASMAP<1>", f.getPath());
    assertEquals("Two", f.getValue());
    f = answerGroup.getField().get(2);
    assertEquals("/$ATLASMAP<2>", 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) Expression(io.atlasmap.v2.Expression) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.jupiter.api.Test)

Example 62 with Expression

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

the class DefaultAtlasFieldActionsServiceTest method testProcessOldExpressionActionConcatenateTwoCollections.

@Test
public void testProcessOldExpressionActionConcatenateTwoCollections() 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 list2 = new FieldGroup();
    list2.setPath("/fields2<>");
    list2.setCollectionType(CollectionType.LIST);
    Field field21 = new SimpleField();
    field21.setPath("/fields2<0>");
    field21.setValue("one");
    list2.getField().add(field21);
    Field field22 = new SimpleField();
    field22.setPath("/fields2<1>");
    field22.setValue("two");
    list2.getField().add(field22);
    Field field23 = new SimpleField();
    field23.setPath("/fields2<2>");
    field23.setValue("three");
    list2.getField().add(field23);
    FieldGroup fieldGroup = new FieldGroup();
    fieldGroup.getField().add(delimiter);
    fieldGroup.getField().add(list);
    fieldGroup.getField().add(list2);
    Expression action = new Expression();
    action.setExpression("concatenate(${0}, true, ${1}, ${2})");
    fieldGroup.setActions(new ArrayList<Action>());
    fieldGroup.getActions().add(action);
    Field answer = fieldActionsService.processActions(session, fieldGroup);
    assertEquals("$ATLASMAP", answer.getPath());
    assertEquals("one-two-three-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 63 with Expression

use of io.atlasmap.v2.Expression 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 64 with Expression

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

the class DefaultAtlasExpressionProcessorTest method testSingle.

@Test
public void testSingle() throws AtlasException {
    Field source = populateSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, FieldType.STRING, "foo");
    String expression = String.format("${%s:/testPathfoo}", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
    recreateSession();
    session.head().setSourceField(source);
    DefaultAtlasExpressionProcessor.processExpression(session, expression);
    assertFalse(session.hasErrors(), printAudit(session));
    assertEquals("foo", session.head().getSourceField().getValue());
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.jupiter.api.Test)

Example 65 with Expression

use of io.atlasmap.v2.Expression 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)

Aggregations

Test (org.junit.jupiter.api.Test)34 Expression (org.apache.commons.jexl2.Expression)28 Expression (io.atlasmap.v2.Expression)26 JexlContext (org.apache.commons.jexl2.JexlContext)25 JexlEngine (org.apache.commons.jexl2.JexlEngine)22 Field (io.atlasmap.v2.Field)21 FieldGroup (io.atlasmap.v2.FieldGroup)20 MapContext (org.apache.commons.jexl2.MapContext)20 SimpleField (io.atlasmap.v2.SimpleField)16 Test (org.testng.annotations.Test)13 PropertyField (io.atlasmap.v2.PropertyField)9 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)7 Expression (org.eclipse.xtext.resource.bug385636.Expression)7 Expression (org.kie.workbench.common.dmn.api.definition.v1_1.Expression)7 Expression (io.atlasmap.expression.Expression)6 ArrayList (java.util.ArrayList)6 List (java.util.List)5 ParseException (io.atlasmap.expression.parser.ParseException)4 Action (io.atlasmap.v2.Action)4 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)4