use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class CoreConfidenceTests method testContextFieldNotFound.
public void testContextFieldNotFound() {
String str = "'stilton'.equals( type );";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("this", Cheese.class);
pctx.setStrictTypeEnforcement(true);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
MVEL.executeExpression(stmt, new Cheese(), new HashMap());
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class CoreConfidenceTests method testInterfaceMethodCallWithSpace.
@SuppressWarnings({ "unchecked" })
public void testInterfaceMethodCallWithSpace() {
Map map = new HashMap();
DefaultKnowledgeHelper helper = new DefaultKnowledgeHelper();
map.put("drools", helper);
Cheese cheese = new Cheese("stilton", 15);
map.put("cheese", cheese);
executeExpression(compileExpression("drools.retract (cheese)"), map);
assertSame(cheese, helper.retracted.get(0));
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class DebuggerTests method testBreakpointsAcrossWith.
public void testBreakpointsAcrossWith() {
String line1 = "System.out.println( \"a1\" );\n";
String line2 = "c = new Cheese();\n";
String line3 = "with ( c ) { type = 'cheddar',\n" + " price = 10 };\n";
String line4 = "System.out.println( \"a1\" );\n";
String expr = line1 + line2 + line3 + line4;
System.out.println(expr);
ParserContext context = new ParserContext();
context.addImport("System", System.class);
context.addImport("Cheese", Cheese.class);
context.setStrictTypeEnforcement(true);
context.setDebugSymbols(true);
context.setSourceFile("mysource");
ExpressionCompiler compiler = new ExpressionCompiler(expr, context);
String s = org.mvel2.debug.DebugTools.decompile(compiler.compile());
System.out.println("output: " + s);
int fromIndex = 0;
int count = 0;
while ((fromIndex = s.indexOf("DEBUG_SYMBOL", fromIndex + 1)) > -1) {
count++;
}
assertEquals(5, count);
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class TypesAndInferenceTests method testDataConverterStrictMode.
public void testDataConverterStrictMode() throws Exception {
OptimizerFactory.setDefaultOptimizer("ASM");
DataConversion.addConversionHandler(Date.class, new MVELDateCoercion());
ParserContext ctx = new ParserContext();
ctx.addImport("Cheese", Cheese.class);
ctx.setStrongTyping(true);
ctx.setStrictTypeEnforcement(true);
Locale.setDefault(Locale.US);
Cheese expectedCheese = new Cheese();
expectedCheese.setUseBy(new SimpleDateFormat("dd-MMM-yyyy").parse("10-Jul-1974"));
ExpressionCompiler compiler = new ExpressionCompiler("c = new Cheese(); c.useBy = '10-Jul-1974'; return c", ctx);
Cheese actualCheese = (Cheese) executeExpression(compiler.compile(), createTestMap());
assertEquals(expectedCheese.getUseBy(), actualCheese.getUseBy());
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class ArraysTests method testMultiDimensionalArrayType.
public void testMultiDimensionalArrayType() {
String str = "$c.cheeses[0][0] = new Cheese('brie', 15)";
ParserConfiguration pconf = new ParserConfiguration();
pconf.addImport(Cheese.class);
ParserContext pctx = new ParserContext(pconf);
pctx.addInput("$c", Column.class);
pctx.setStrongTyping(true);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
Map<String, Object> vars = new HashMap<String, Object>();
Column c = new Column("x", 1);
c.setCheeses(new Cheese[5][5]);
vars.put("$c", c);
MVEL.executeExpression(stmt, null, vars);
assertEquals(new Cheese("brie", 15), c.getCheeses()[0][0]);
}
Aggregations