use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testInstanceofWithPackageImport.
public void testInstanceofWithPackageImport() {
ParserConfiguration conf = new ParserConfiguration();
conf.addPackageImport("org.mvel2.tests.core");
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("value", Object.class);
Map vars = new HashMap() {
{
put("value", new CoreConfidenceTests());
}
};
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof CoreConfidenceTests", pctx), vars));
assertEquals(true, MVEL.executeExpression(MVEL.compileExpression("value instanceof " + CoreConfidenceTests.class.getCanonicalName(), pctx), vars));
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testUnaryNegative.
public void testUnaryNegative() {
ParserConfiguration conf = new ParserConfiguration();
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("value", int.class);
Map vars = new HashMap() {
{
put("value", 42);
}
};
assertEquals(-42, MVEL.executeExpression(MVEL.compileExpression("-value", pctx), vars));
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testMapAccessWithNestedProperty.
public void testMapAccessWithNestedProperty() {
String str = "map[key] == \"one\"";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("this", POJO.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
POJO ctx = new POJO();
ctx.getMap().put("1", "one");
Boolean result = (Boolean) MVEL.executeExpression(stmt, ctx);
assertTrue(result);
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testNestedEnumFromJar.
public void testNestedEnumFromJar() throws ClassNotFoundException, SecurityException, NoSuchFieldException {
String expr = "EventRequest.Status.ACTIVE";
// creating a classloader for the jar
URL resource = getClass().getResource("/eventing-example.jar");
assertNotNull(resource);
URLClassLoader loader = new URLClassLoader(new URL[] { resource }, getClass().getClassLoader());
// loading the class to prove it works
Class<?> er = loader.loadClass("org.drools.examples.eventing.EventRequest");
assertNotNull(er);
assertEquals("org.drools.examples.eventing.EventRequest", er.getCanonicalName());
// getting the value of the enum to prove it works:
Class<?> st = er.getDeclaredClasses()[0];
assertNotNull(st);
Field active = st.getField("ACTIVE");
assertNotNull(active);
// now, trying with MVEL
ParserConfiguration pconf = new ParserConfiguration();
pconf.setClassLoader(loader);
pconf.addImport(er);
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
Serializable compiled = MVEL.compileExpression(expr, pctx);
Object result = MVEL.executeExpression(compiled);
assertNotNull(result);
}
use of org.mule.mvel2.ParserConfiguration in project mvel by mvel.
the class CoreConfidenceTests method testStaticMethodInvocation.
public void testStaticMethodInvocation() {
ParserConfiguration conf = new ParserConfiguration();
conf.addImport(ARef.class);
conf.addImport(BRef.class);
ParserContext pctx = new ParserContext(conf);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
pctx.addInput("value", String.class);
Map vars = new HashMap() {
{
put("value", "1234");
}
};
assertEquals(0, MVEL.executeExpression(MVEL.compileExpression("ARef.getSize(value)", pctx), vars));
assertEquals(4, MVEL.executeExpression(MVEL.compileExpression("BRef.getSize(value)", pctx), vars));
}
Aggregations