Search in sources :

Example 81 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class TestCompiledMoneyExpression method setup.

@Before
public void setup() {
    FunctionInterface giveLongFunction = new GiveLongTestFunction();
    FunctionDefinition fd = new FunctionDefinition(giveLongFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToLong", fd);
    FunctionInterface giveMoneyFunction = new GiveMoneyTestFunction();
    fd = new FunctionDefinition(giveMoneyFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToMoney", fd);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) GiveMoneyTestFunction(com.dexels.navajo.expression.compiled.GiveMoneyTestFunction) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) GiveLongTestFunction(com.dexels.navajo.expression.compiled.GiveLongTestFunction) Before(org.junit.Before)

Example 82 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class TestCompiledStringExpression method testSubtractStringAndLong.

@Test(expected = TMLExpressionException.class)
public void testSubtractStringAndLong() {
    FunctionInterface giveLongFunction = new GiveLongTestFunction();
    FunctionDefinition fd = new FunctionDefinition(giveLongFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToLong", fd);
    Expression.evaluate("'bla' - ToLong(10)", null, null, null);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) GiveLongTestFunction(com.dexels.navajo.expression.compiled.GiveLongTestFunction) Test(org.junit.Test)

Example 83 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class TestCompiledLongExpression method testMultiplyWithLongs.

@Test
public void testMultiplyWithLongs() {
    FunctionInterface helperFunction = new GiveLongTestFunction();
    FunctionDefinition fd = new FunctionDefinition(helperFunction.getClass().getName(), "description", "input", "result");
    FunctionFactoryFactory.getInstance().addExplicitFunctionDefinition("ToLong", fd);
    Operand result;
    result = Expression.evaluate("ToLong(3) * ToLong(1)", null, null, null);
    Assert.assertEquals(3L, (long) result.value);
    result = Expression.evaluate("3 * ToLong(1)", null, null, null);
    Assert.assertEquals(3L, (long) result.value);
    result = Expression.evaluate("ToLong(3) * 1", null, null, null);
    Assert.assertEquals(3L, (long) result.value);
    result = Expression.evaluate("3.0 * ToLong(1)", null, null, null);
    Assert.assertEquals(3L, (double) result.value, 0.000001);
    result = Expression.evaluate("ToLong(3) * 1.0", null, null, null);
    Assert.assertEquals(3L, (double) result.value, 0.000001);
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Operand(com.dexels.navajo.document.Operand) FunctionDefinition(com.dexels.navajo.expression.api.FunctionDefinition) GiveLongTestFunction(com.dexels.navajo.expression.compiled.GiveLongTestFunction) Test(org.junit.Test)

Example 84 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class StandardFunctionsTest method testDateSubtract.

@Test
public void testDateSubtract() {
    FunctionInterface fi = fff.getInstance(cl, "DateSubtract");
    fi.reset();
    fi.insertDateOperand(new Date());
    fi.insertDateOperand(new Date());
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals(Date.class, o.getClass());
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Date(java.util.Date) Test(org.junit.Test)

Example 85 with FunctionInterface

use of com.dexels.navajo.expression.api.FunctionInterface in project navajo by Dexels.

the class StandardFunctionsTest method testGetDescription.

@Test
public void testGetDescription() {
    FunctionInterface fi = fff.getInstance(cl, "GetDescription");
    fi.reset();
    fi.setInMessage(createTestNavajo());
    Navajo doc = createTestNavajo();
    fi.insertPropertyOperand(doc.getProperty("/Single/Selectie"));
    Object o = fi.evaluateWithTypeChecking();
    assertNotNull(o);
    assertEquals("", o.toString());
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Navajo(com.dexels.navajo.document.Navajo) Test(org.junit.Test)

Aggregations

FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)161 Test (org.junit.Test)153 Navajo (com.dexels.navajo.document.Navajo)26 FunctionDefinition (com.dexels.navajo.expression.api.FunctionDefinition)20 ArrayList (java.util.ArrayList)16 Date (java.util.Date)16 Operand (com.dexels.navajo.document.Operand)10 GiveLongTestFunction (com.dexels.navajo.expression.compiled.GiveLongTestFunction)10 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)7 CapString (com.dexels.navajo.functions.CapString)7 StringReader (java.io.StringReader)5 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)4 AddTestFunction (com.dexels.navajo.expression.compiled.AddTestFunction)4 Binary (com.dexels.navajo.document.types.Binary)3 CheckInteger (com.dexels.navajo.functions.CheckInteger)3 SimpleDateFormat (java.text.SimpleDateFormat)3 List (java.util.List)3 Message (com.dexels.navajo.document.Message)2 Property (com.dexels.navajo.document.Property)2 ClockTime (com.dexels.navajo.document.types.ClockTime)2