use of org.mvel2.tests.core.res.Cheese in project mvel by mikebrock.
the class CoreConfidenceTests method testStringConcatenation2.
public void testStringConcatenation2() {
String ex = "services.log( $cheese + \" some string \" );";
ParserContext ctx = new ParserContext();
ctx.setStrongTyping(true);
ctx.addInput("$cheese", Cheese.class);
ctx.addInput("services", Services.class);
try {
ExpressionCompiler compiler = new ExpressionCompiler(ex);
compiler.compile(ctx);
} catch (Throwable e) {
e.printStackTrace();
fail("Should not raise exception: " + e.getMessage());
}
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mikebrock.
the class CoreConfidenceTests method testInlineConstructor.
public void testInlineConstructor() {
String str = "cheese = new Cheese().{ type = $c.type };";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("$c", Cheese.class);
pctx.addImport(Cheese.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Cheese $c = new Cheese();
$c.setType("stilton");
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("$c", $c);
Cheese cheese = (Cheese) MVEL.executeExpression(stmt, vars);
assertEquals("stilton", cheese.getType());
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class CoreConfidenceTests method testInlineConstructor.
public void testInlineConstructor() {
String str = "cheese = new Cheese().{ type = $c.type };";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("$c", Cheese.class);
pctx.addImport(Cheese.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Cheese $c = new Cheese();
$c.setType("stilton");
Map<String, Object> vars = new HashMap<String, Object>();
vars.put("$c", $c);
Cheese cheese = (Cheese) MVEL.executeExpression(stmt, vars);
assertEquals("stilton", cheese.getType());
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class CoreConfidenceTests method testDynamicImportsOnNestedExpressions.
public void testDynamicImportsOnNestedExpressions() {
ParserContext ctx = new ParserContext();
ctx.addPackageImport("org.mvel2.tests.core.res");
ExpressionCompiler compiler = new ExpressionCompiler("new Cheesery(\"bobbo\", new Cheese(\"cheddar\", 15))", ctx);
Cheesery p1 = new Cheesery("bobbo", new Cheese("cheddar", 15));
Cheesery p2 = (Cheesery) executeExpression(compiler.compile(), new DefaultLocalVariableResolverFactory());
assertEquals(p1, p2);
}
use of org.mvel2.tests.core.res.Cheese 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);
}
Aggregations