Search in sources :

Example 96 with Serializable

use of java.io.Serializable in project mvel by mikebrock.

the class PropertyHandlerTests method testListPropertyHandler4.

public void testListPropertyHandler4() {
    MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
    OptimizerFactory.setDefaultOptimizer("ASM");
    final String[] res = new String[1];
    GlobalListenerFactory.registerGetListener(new Listener() {

        public void onEvent(Object context, String contextName, VariableResolverFactory variableFactory, Object value) {
            System.out.println("Listener Fired:" + contextName);
            res[0] = contextName;
        }
    });
    Serializable s = MVEL.compileSetExpression("list[0]");
    Base b;
    MVEL.executeSetExpression(s, new Base(), "hey you");
    res[0] = null;
    MVEL.executeSetExpression(s, b = new Base(), "hey you");
    assertEquals("set", b.list.get(0));
    assertEquals("list", res[0]);
}
Also used : Serializable(java.io.Serializable) Base(org.mvel2.tests.core.res.Base)

Example 97 with Serializable

use of java.io.Serializable in project mvel by mikebrock.

the class PropertyHandlerTests method testNullPropertyHandler.

public void testNullPropertyHandler() {
    MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
    OptimizerFactory.setDefaultOptimizer("ASM");
    PropertyHandlerFactory.setNullPropertyHandler(new PropertyHandler() {

        public Object getProperty(String name, Object contextObj, VariableResolverFactory variableFactory) {
            return "NULL";
        }

        public Object setProperty(String name, Object contextObj, VariableResolverFactory variableFactory, Object value) {
            return "NULL";
        }
    });
    Foo foo = new Foo();
    Bar bar = foo.getBar();
    foo.setBar(null);
    Map map = new HashMap();
    map.put("foo", foo);
    Serializable s = MVEL.compileExpression("foo.bar");
    assertEquals("NULL", MVEL.executeExpression(s, map));
    assertEquals("NULL", MVEL.executeExpression(s, map));
    foo.setBar(bar);
    assertEquals(bar, MVEL.executeExpression(s, map));
}
Also used : Bar(org.mvel2.tests.core.res.Bar) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Foo(org.mvel2.tests.core.res.Foo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 98 with Serializable

use of java.io.Serializable in project mvel by mikebrock.

the class TypesAndInferenceTests method testMVEL235.

public void testMVEL235() {
    StringBuffer buffer = new StringBuffer();
    buffer.append("if(var1.equals(var2)) {");
    buffer.append("return true;");
    buffer.append("}");
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("var1", MyInterface2.class);
    ctx.addInput("var2", MyInterface2.class);
    try {
        Serializable compiled = (Serializable) MVEL.compileExpression(buffer.toString(), ctx);
        System.out.println(compiled);
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Serializable(java.io.Serializable)

Example 99 with Serializable

use of java.io.Serializable in project mvel by mikebrock.

the class TypesAndInferenceTests method testMultiTypeVarDeclr3.

public void testMultiTypeVarDeclr3() {
    String ex = "int a = 52 * 3, b = 8, c = 16;";
    ParserContext ctx = new ParserContext();
    ExpressionCompiler compiler = new ExpressionCompiler(ex);
    Serializable s = compiler.compile(ctx);
    assertNotNull(ctx.getVariables());
    assertEquals(3, ctx.getVariables().entrySet().size());
    for (Map.Entry<String, Class> entry : ctx.getVariables().entrySet()) {
        assertEquals(Integer.class, entry.getValue());
    }
    Map vars = new HashMap();
    executeExpression(s, vars);
    assertEquals(52 * 3, vars.get("a"));
    assertEquals(8, vars.get("b"));
    assertEquals(16, vars.get("c"));
}
Also used : Serializable(java.io.Serializable) ExpressionCompiler(org.mvel2.compiler.ExpressionCompiler)

Example 100 with Serializable

use of java.io.Serializable in project mvel by mikebrock.

the class TypesAndInferenceTests method testListCoercion.

public void testListCoercion() {
    ParserContext ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("bar", Bar.class);
    Serializable s = compileSetExpression("bar.testList[0]", ctx);
    Foo foo = new Foo();
    foo.getBar().getTestList().add(new Integer(-1));
    executeSetExpression(s, foo, "12");
    assertEquals(12, foo.getBar().getTestList().get(0).intValue());
    foo = new Foo();
    foo.getBar().getTestList().add(new Integer(-1));
    executeSetExpression(s, foo, "13");
    assertEquals(13, foo.getBar().getTestList().get(0).intValue());
    OptimizerFactory.setDefaultOptimizer("ASM");
    ctx = new ParserContext();
    ctx.setStrongTyping(true);
    ctx.addInput("bar", Bar.class);
    s = compileSetExpression("bar.testList[0]", ctx);
    foo = new Foo();
    foo.getBar().getTestList().add(new Integer(-1));
    executeSetExpression(s, foo, "12");
    assertEquals(12, foo.getBar().getTestList().get(0).intValue());
    executeSetExpression(s, foo, "13");
    assertEquals(13, foo.getBar().getTestList().get(0).intValue());
}
Also used : Serializable(java.io.Serializable)

Aggregations

Serializable (java.io.Serializable)1052 Test (org.junit.Test)267 HashMap (java.util.HashMap)226 ArrayList (java.util.ArrayList)181 Map (java.util.Map)116 Metacard (ddf.catalog.data.Metacard)89 List (java.util.List)80 IOException (java.io.IOException)70 HashSet (java.util.HashSet)68 Session (org.hibernate.Session)62 Set (java.util.Set)46 Date (java.util.Date)40 Task (org.apache.hadoop.hive.ql.exec.Task)40 ByteArrayInputStream (java.io.ByteArrayInputStream)38 LinkedHashMap (java.util.LinkedHashMap)36 EntityPersister (org.hibernate.persister.entity.EntityPersister)34 ObjectInputStream (java.io.ObjectInputStream)33 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)31 Iterator (java.util.Iterator)31 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)28