Search in sources :

Example 76 with Expression

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

the class ExpressionFieldActionTest method testDivide.

@Test
public void testDivide() throws Exception {
    Expression action = new Expression();
    action.setExpression("${0} / ${1}");
    assertEquals(10.0, ExpressionFieldAction.process(action, Arrays.asList(100, 10)));
}
Also used : Expression(io.atlasmap.v2.Expression) Test(org.junit.jupiter.api.Test)

Example 77 with Expression

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

the class ExpressionFieldActionTest method testOr.

@Test
public void testOr() throws Exception {
    Expression action = new Expression();
    action.setExpression("IF(${0} == ${1} || ${0} == ${2}, 'some of them are same', 'all different')");
    assertEquals("some of them are same", ExpressionFieldAction.process(action, Arrays.asList("foo", "foo", "fo")));
    assertEquals("some of them are same", ExpressionFieldAction.process(action, Arrays.asList(1, 1, 2)));
    assertEquals("all different", ExpressionFieldAction.process(action, Arrays.asList("foo", "foo0", "fo")));
    assertEquals("all different", ExpressionFieldAction.process(action, Arrays.asList(1, 3, 2)));
}
Also used : Expression(io.atlasmap.v2.Expression) Test(org.junit.jupiter.api.Test)

Example 78 with Expression

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

the class ExpressionFieldActionTest method testConcatenateActionWithMissingArguments.

@Test
public void testConcatenateActionWithMissingArguments() throws Exception {
    Expression action = new Expression();
    action.setExpression("CONCATENATE(${0}, ${1})");
    try {
        ExpressionFieldAction.process(action, Arrays.asList(",", true));
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(IllegalArgumentException.class, e.getClass());
        assertEquals("The transformation 'CONCATENATE' expects more arguments", e.getMessage());
    }
}
Also used : Expression(io.atlasmap.v2.Expression) Test(org.junit.jupiter.api.Test)

Example 79 with Expression

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

the class ExpressionFieldActionTest method testConcatenateActionWithDelimiter.

@Test
public void testConcatenateActionWithDelimiter() throws Exception {
    Expression action = new Expression();
    action.setExpression("CONCATENATE(${0}, ${1}, ${2}, ${3}, ${4})");
    assertEquals("a,b,c", ExpressionFieldAction.process(action, Arrays.asList(",", true, "a", "b", "c")));
}
Also used : Expression(io.atlasmap.v2.Expression) Test(org.junit.jupiter.api.Test)

Example 80 with Expression

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

the class DefaultAtlasFieldActionService method processManyToOne.

private Field processManyToOne(Action action, ActionProcessor processor, FieldType sourceType, Field field) throws AtlasException {
    ActionDetail detail = processor.getActionDetail();
    List<Object> values = new LinkedList<>();
    if (action instanceof Expression) {
        // preserve top level list of parameters and arguments
        this.extractNestedListValuesForExpressionAction(field, values);
        convertCollectionValues(values, detail.getSourceType());
        Object out = processor.process(action, values);
        return packExpressionActionOutcomeIntoField(out, field);
    }
    if (field instanceof FieldGroup) {
        extractFlatListValuesFromFieldGroup((FieldGroup) field, values);
    } else {
        Object value = field.getValue();
        if (value != null && getConversionService().isAssignableFieldType(detail.getSourceType(), sourceType)) {
            value = getConversionService().convertType(value, sourceType, detail.getSourceType());
        }
        values.add(value);
    }
    convertCollectionValues(values, detail.getSourceType());
    Object out = processor.process(action, values);
    field = AtlasModelFactory.cloneFieldToSimpleField(field);
    if (out != null) {
        field.setFieldType(getConversionService().fieldTypeFromClass(out.getClass()));
        field.setValue(out);
    }
    return field;
}
Also used : ActionDetail(io.atlasmap.v2.ActionDetail) Expression(io.atlasmap.v2.Expression) FieldGroup(io.atlasmap.v2.FieldGroup) LinkedList(java.util.LinkedList)

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