use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testInvokeVarargConstructor.
public void testInvokeVarargConstructor() {
ParserConfiguration conf = new ParserConfiguration();
conf.addImport(Thingy.class);
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("name", String.class);
Map vars = new HashMap() {
{
put("name", "test");
}
};
Thingy result = (Thingy) MVEL.executeExpression(MVEL.compileExpression("new Thingy(name)", pctx), vars);
assertEquals("test", result.getName());
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testPrimitiveSubtyping.
public void testPrimitiveSubtyping() {
ParserConfiguration conf = new ParserConfiguration();
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
BigDecimal result = (BigDecimal) MVEL.executeExpression(MVEL.compileExpression("java.math.BigDecimal.valueOf(100)", pctx), new HashMap());
assertEquals("100", result.toString());
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testMethodReturningPrimitiveTypeAnalysis.
public void testMethodReturningPrimitiveTypeAnalysis() {
String str = "value";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", MyObj.class);
pctx.setStrongTyping(true);
Class<?> returnType = MVEL.analyze(str, pctx);
assertEquals(long.class, returnType);
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testWithInsideBlock.
public void testWithInsideBlock() {
String str = "Foo f = new Foo(); with(f) { setBoolTest( true ) }; f.isBoolTest()";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", Bar.class);
pctx.addImport(Foo.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Bar ctx = new Bar();
Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx, new HashMap());
assertTrue(result);
}
use of org.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testInstanceofOnInnerClass.
public void testInstanceofOnInnerClass() {
ParserConfiguration conf = new ParserConfiguration();
conf.addImport(ARef.class);
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("value", Object.class);
Map vars = new HashMap() {
{
put("value", new ARef());
}
};
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof ARef", pctx), vars));
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof " + ARef.class.getCanonicalName(), pctx), vars));
}
Aggregations