Package org.apache.expreval.expr

Examples of org.apache.expreval.expr.ExpressionTree


    }

    @Test
    public void booleanParamExpressions() throws HBqlException {

        ExpressionTree tree;

        tree = parseExpr(":test");
        tree.setParameter(":test", Boolean.TRUE);
        assertExpressionEvalTrue(tree);
        tree.setParameter(":test", Boolean.FALSE);
        assertExpressionEvalFalse(tree);

        tree = parseExpr(":test AND :test");
        tree.setParameter(":test", Boolean.TRUE);
        assertExpressionEvalTrue(tree);
        tree.setParameter(":test", Boolean.FALSE);
        assertExpressionEvalFalse(tree);

        tree = parseExpr(":test1 OR :test2");
        tree.setParameter(":test1", Boolean.TRUE);
        tree.setParameter(":test2", Boolean.FALSE);
        assertExpressionEvalTrue(tree);
        tree.setParameter(":test1", Boolean.FALSE);
        assertExpressionEvalFalse(tree);

        tree = parseExpr(":test1");
        assertHasException(tree, InvalidTypeException.class);

        tree = parseExpr(":b1 == :b2");
        tree.setParameter("b1", Boolean.TRUE);
        tree.setParameter("b2", Boolean.TRUE);
        assertExpressionEvalTrue(tree);
        tree.setParameter("b2", Boolean.FALSE);
        assertExpressionEvalFalse(tree);

        tree = parseExpr(":b1 != :b2");
        tree.setParameter("b1", Boolean.TRUE);
        tree.setParameter("b2", Boolean.FALSE);
        assertExpressionEvalTrue(tree);
        tree.setParameter("b2", Boolean.TRUE);
        assertExpressionEvalFalse(tree);

        tree = parseExpr("((((:b1 OR :b1 OR :b1))))" + " OR " + "((((:b1 OR :b1 OR :b1))))");
        tree.setParameter("b1", Boolean.FALSE);
        assertExpressionEvalFalse(tree);

        tree = parseExpr(":b1 OR ((:b1) or :b1) OR :b2");
        tree.setParameter("b1", Boolean.TRUE);
        tree.setParameter("b2", Boolean.FALSE);
        assertExpressionEvalTrue(tree);
    }
View Full Code Here


    }

    @Test
    public void numericParamExpressions() throws HBqlException {

        ExpressionTree tree;

        tree = parseExpr(":val1 < :val2");
        tree.setParameter("val1", 4);
        tree.setParameter("val2", 5);
        assertExpressionEvalTrue(tree);
        tree.setParameter(":val2", 3);
        assertExpressionEvalFalse(tree);
    }
View Full Code Here

        assertEvalTrue("NOW() BETWEEN MINDATE() AND MAXDATE()");
    }

    @Test
    public void dateParamCompares() throws HBqlException {
        ExpressionTree tree;

        tree = parseExpr("NOW() - DAY(1) = :d1");
        tree.setParameter("d1", new Date());
        assertExpressionEvalFalse(tree);

        tree = parseExpr("NOW() - DAY(1) < :d1");
        tree.setParameter("d1", new Date());
        assertExpressionEvalTrue(tree);
    }
View Full Code Here

    }

    @Test
    public void stringParamCompares() throws HBqlException {

        ExpressionTree tree;

        tree = parseExpr("'aaa' = 'a'+:s1");
        tree.setParameter("s1", "aa");
        assertExpressionEvalTrue(tree);

        tree = parseExpr("'aaa' = 'a'+:s1");
        tree.setParameter("s1", 1);
        assertHasException(tree, InvalidTypeException.class);
    }
View Full Code Here

    }

    @Test
    public void nullParamCompares() throws HBqlException {

        ExpressionTree tree;

        tree = parseExpr(":a IS NULL");
        tree.setParameter("a", null);
        assertExpressionEvalTrue(tree);
        tree.setParameter("a", "val");
        assertExpressionEvalFalse(tree);

        tree = parseExpr(":a IS NOT NULL");
        tree.setParameter("a", "vall");
        assertExpressionEvalTrue(tree);
        tree.setParameter("a", 3);
        assertExpressionEvalTrue(tree);
        tree.setParameter("a", new Date());
        assertExpressionEvalTrue(tree);
        tree.setParameter("a", Boolean.TRUE);
        assertExpressionEvalTrue(tree);
        tree.setParameter("a", (Boolean)null);
        assertExpressionEvalFalse(tree);
        tree.setParameter("a", null);
        assertExpressionEvalFalse(tree);
    }
View Full Code Here

    }

    @Test
    public void numericParamCalculations() throws HBqlException {

        ExpressionTree tree;

        tree = parseExpr(":a = :b");
        tree.setParameter("a", 8);
        tree.setParameter("b", 8);
        assertExpressionEvalTrue(tree);

        tree = parseExpr("(-1*:a) = :b");
        tree.setParameter("a", 8);
        tree.setParameter("b", -8);
        assertExpressionEvalTrue(tree);

        tree = parseExpr("(-1*-1*:a) = :b");
        tree.setParameter("a", 8);
        tree.setParameter("b", 8);
        assertExpressionEvalTrue(tree);

        tree = parseExpr("(:a + :a + :a + :a - :a) = :b");
        tree.setParameter("a", 5);
        tree.setParameter("b", 15);
        assertExpressionEvalTrue(tree);

        tree = parseExpr("(:a % :b) = :c");
        tree.setParameter("a", 40);
        tree.setParameter("b", 6);
        tree.setParameter("c", 4);
        assertExpressionEvalTrue(tree);
    }
View Full Code Here

    @Test
    public void booleanParamFunctions() throws HBqlException {

        HConnection connection = HConnectionManager.newConnection();
        ExpressionTree tree;

        tree = parseExpr(":a CONTAINS :b");
        tree.setParameter("a", "abc");
        tree.setParameter("b", "b");
        assertExpressionEvalTrue(tree);

        tree.setParameter("b", "z");
        assertExpressionEvalFalse(tree);

        final ObjectAllTypes obj = new ObjectAllTypes("aaabbb", 3, "aaab");

        tree = parseReflectionExpr(obj, "keyval CONTAINS :a");
        tree.setParameter("a", "ab");
        assertExpressionEvalTrue(obj, tree);
        tree.setParameter("a", "ba");
        assertEvalFalse(obj, tree);

        tree = parseExpr(":a IN (:b, :c)");
        tree.setParameter("a", "a");
        tree.setParameter("b", "b");
        tree.setParameter("c", "a");
        assertExpressionEvalTrue(tree);

        tree = parseExpr(":a IN (:b)");
        tree.setParameter("a", "a");
        tree.setParameter("b", Arrays.asList("a", "b", "c"));
        assertExpressionEvalTrue(tree);

        // Test for list where scalar is required
        tree.setParameter("a", Arrays.asList("a", "b", "c"));
        assertHasException(tree, InvalidTypeException.class);
    }
View Full Code Here

    }

    @Test
    public void stringParamFunctions() throws HBqlException {

        ExpressionTree tree;

        tree = parseExpr(":a between :b AND :c");
        tree.setParameter("a", "bbb");
        tree.setParameter("b", "aaa");
        tree.setParameter("c", "ccc");
        assertExpressionEvalTrue(tree);
    }
View Full Code Here

    }

    @Test
    public void intervalParamExpressions() throws HBqlException {

        ExpressionTree tree;

        tree = parseExpr("NOW() < NOW()+MINUTE(:a)");
        tree.setParameter("a", 1);
        assertExpressionEvalTrue(tree);

        tree = parseExpr("NOW()+YEAR(:a) = NOW()+WEEK(:b)+DAY(:c)");
        tree.setParameter("a", 2);
        tree.setParameter("b", 52);
        tree.setParameter("c", 364);
        assertExpressionEvalTrue(tree);
    }
View Full Code Here

        }
        org.junit.Assert.assertTrue(eclazz != null && eclazz.equals(clazz));
    }

    public void assertHasException(final String str, final Class<? extends Exception> clazz) throws HBqlException {
        final ExpressionTree tree = parseDescWhereExpr(str, null);
        assertExpressionHasException(null, tree, clazz);
    }
View Full Code Here

TOP

Related Classes of org.apache.expreval.expr.ExpressionTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.