Search in sources :

Example 1 with ClassImportResolverFactory

use of org.mvel2.integration.impl.ClassImportResolverFactory in project mvel by mvel.

the class CoreConfidenceTests method testCheeseConstructor.

// public void testClassImportViaFactory() {
// MapVariableResolverFactory mvf = new MapVariableResolverFactory(createTestMap());
// ClassImportResolverFactory classes = new ClassImportResolverFactory();
// classes.addClass(HashMap.class);
// 
// ResolverTools.appendFactory(mvf, classes);
// 
// assertTrue(executeExpression(compileExpression("HashMap map = new HashMap()",
// classes.getImportedClasses()),
// mvf) instanceof HashMap);
// }
// 
// public void testSataticClassImportViaFactory() {
// MapVariableResolverFactory mvf = new MapVariableResolverFactory(createTestMap());
// ClassImportResolverFactory classes = new ClassImportResolverFactory();
// classes.addClass(Person.class);
// 
// ResolverTools.appendFactory(mvf,
// classes);
// 
// assertEquals("tom",
// executeExpression(compileExpression("p = new Person('tom'); return p.name;",
// classes.getImportedClasses()),
// mvf));
// }
public void testCheeseConstructor() {
    MapVariableResolverFactory mvf = new MapVariableResolverFactory(createTestMap());
    ClassImportResolverFactory classes = new ClassImportResolverFactory(null, null, false);
    classes.addClass(Cheese.class);
    ResolverTools.appendFactory(mvf, classes);
    assertTrue(executeExpression(compileExpression("cheese = new Cheese(\"cheddar\", 15);", classes.getImportedClasses()), mvf) instanceof Cheese);
}
Also used : MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) Cheese(org.mvel2.tests.core.res.Cheese) ClassImportResolverFactory(org.mvel2.integration.impl.ClassImportResolverFactory)

Example 2 with ClassImportResolverFactory

use of org.mvel2.integration.impl.ClassImportResolverFactory in project mvel by mvel.

the class WithTests method testSataticClassImportViaFactoryAndWithModification.

public void testSataticClassImportViaFactoryAndWithModification() {
    OptimizerFactory.setDefaultOptimizer("ASM");
    MapVariableResolverFactory mvf = new MapVariableResolverFactory(createTestMap());
    ClassImportResolverFactory classes = new ClassImportResolverFactory(null, null, false);
    classes.addClass(Person.class);
    ResolverTools.appendFactory(mvf, classes);
    assertEquals(21, executeExpression(compileExpression("p = new Person('tom'); p.age = 20; " + "with( p ) { age = p.age + 1 }; return p.age;", classes.getImportedClasses()), mvf));
}
Also used : MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) ClassImportResolverFactory(org.mvel2.integration.impl.ClassImportResolverFactory)

Example 3 with ClassImportResolverFactory

use of org.mvel2.integration.impl.ClassImportResolverFactory in project mvel by mikebrock.

the class CoreConfidenceTests method testCheeseConstructor.

// public void testClassImportViaFactory() {
// MapVariableResolverFactory mvf = new MapVariableResolverFactory(createTestMap());
// ClassImportResolverFactory classes = new ClassImportResolverFactory();
// classes.addClass(HashMap.class);
// 
// ResolverTools.appendFactory(mvf, classes);
// 
// assertTrue(executeExpression(compileExpression("HashMap map = new HashMap()",
// classes.getImportedClasses()),
// mvf) instanceof HashMap);
// }
// 
// public void testSataticClassImportViaFactory() {
// MapVariableResolverFactory mvf = new MapVariableResolverFactory(createTestMap());
// ClassImportResolverFactory classes = new ClassImportResolverFactory();
// classes.addClass(Person.class);
// 
// ResolverTools.appendFactory(mvf,
// classes);
// 
// assertEquals("tom",
// executeExpression(compileExpression("p = new Person('tom'); return p.name;",
// classes.getImportedClasses()),
// mvf));
// }
public void testCheeseConstructor() {
    MapVariableResolverFactory mvf = new MapVariableResolverFactory(createTestMap());
    ClassImportResolverFactory classes = new ClassImportResolverFactory();
    classes.addClass(Cheese.class);
    ResolverTools.appendFactory(mvf, classes);
    assertTrue(executeExpression(compileExpression("cheese = new Cheese(\"cheddar\", 15);", classes.getImportedClasses()), mvf) instanceof Cheese);
}
Also used : MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) ClassImportResolverFactory(org.mvel2.integration.impl.ClassImportResolverFactory)

Example 4 with ClassImportResolverFactory

use of org.mvel2.integration.impl.ClassImportResolverFactory in project mvel by mikebrock.

the class WithTests method testSataticClassImportViaFactoryAndWithModification.

public void testSataticClassImportViaFactoryAndWithModification() {
    OptimizerFactory.setDefaultOptimizer("ASM");
    MapVariableResolverFactory mvf = new MapVariableResolverFactory(createTestMap());
    ClassImportResolverFactory classes = new ClassImportResolverFactory();
    classes.addClass(Person.class);
    ResolverTools.appendFactory(mvf, classes);
    assertEquals(21, executeExpression(compileExpression("p = new Person('tom'); p.age = 20; " + "with( p ) { age = p.age + 1 }; return p.age;", classes.getImportedClasses()), mvf));
}
Also used : MapVariableResolverFactory(org.mvel2.integration.impl.MapVariableResolverFactory) ClassImportResolverFactory(org.mvel2.integration.impl.ClassImportResolverFactory)

Aggregations

ClassImportResolverFactory (org.mvel2.integration.impl.ClassImportResolverFactory)4 MapVariableResolverFactory (org.mvel2.integration.impl.MapVariableResolverFactory)4 Cheese (org.mvel2.tests.core.res.Cheese)1