Search in sources :

Example 41 with Expression

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

the class ExpressionFieldActionTest method testIFIntegerZero.

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

Example 42 with Expression

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

the class ExpressionFieldActionTest method testGT.

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

Example 43 with Expression

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

the class ExpressionFieldActionTest method testSubtract.

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

Example 44 with Expression

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

the class ExpressionFieldActionTest method testNot.

@Test
public void testNot() throws Exception {
    Expression action = new Expression();
    action.setExpression("IF(!ISEMPTY(${0}), 'not empty', 'empty')");
    assertEquals("not empty", ExpressionFieldAction.process(action, Arrays.asList("foo")));
    assertEquals("not empty", ExpressionFieldAction.process(action, Arrays.asList(" ")));
    assertEquals("empty", ExpressionFieldAction.process(action, Arrays.asList("")));
    assertEquals("empty", ExpressionFieldAction.process(action, Arrays.asList((Object) null)));
}
Also used : Expression(io.atlasmap.v2.Expression) Test(org.junit.jupiter.api.Test)

Example 45 with Expression

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

the class ExpressionFieldActionTest method testIF.

/*
     * functions
     */
@Test
public void testIF() throws Exception {
    Expression action = new Expression();
    action.setExpression("IF(${0} == ${1}, 'same', 'not same')");
    assertEquals("same", ExpressionFieldAction.process(action, Arrays.asList(10, 10)));
    assertEquals("not same", ExpressionFieldAction.process(action, Arrays.asList(100, 10)));
}
Also used : Expression(io.atlasmap.v2.Expression) 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