use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class CoreConfidenceTests method testIncrementAndAssignWithInputs.
public void testIncrementAndAssignWithInputs() {
ExpressionCompiler compiler = new ExpressionCompiler("total += cheese");
compiler.compile();
assertTrue(compiler.getParserContextState().getInputs().containsKey("total"));
assertTrue(compiler.getParserContextState().getInputs().containsKey("cheese"));
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class TypesAndInferenceTests method testEgressType.
public void testEgressType() {
ParserContext context = new ParserContext();
context.addInput("$cheese", Cheese.class);
ExpressionCompiler compiler = new ExpressionCompiler("( $cheese )", context);
assertEquals(Cheese.class, compiler.compile().getKnownEgressType());
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class TypesAndInferenceTests method testStrictTypingCompilationWithVarInsideConstructor.
public void testStrictTypingCompilationWithVarInsideConstructor() {
ParserContext ctx = new ParserContext();
ctx.addInput("$likes", String.class);
ctx.addInput("results", List.class);
ctx.addImport(Cheese.class);
ctx.setStrongTyping(true);
Serializable expr = null;
try {
expr = MVEL.compileExpression("Cheese c = new Cheese( $likes, 15 );\nresults.add( c ); ", ctx);
} catch (CompileException e) {
e.printStackTrace();
fail("This should not fail:\n" + e.getMessage());
}
List results = new ArrayList();
Map vars = new HashMap();
vars.put("$likes", "stilton");
vars.put("results", results);
executeExpression(expr, vars);
assertEquals(new Cheese("stilton", 15), results.get(0));
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mvel.
the class TypesAndInferenceTests method testGetCorrectInputs.
public void testGetCorrectInputs() {
String str = "total = total + $cheese.price";
ParserConfiguration pconf = new ParserConfiguration();
ParserContext pctx = new ParserContext(pconf);
pctx.setStrongTyping(true);
pctx.addInput("total", int.class);
pctx.addInput("$cheese", Cheese.class);
ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx);
assertTrue("Should not contain" + pctx.getVariables(), pctx.getVariables().isEmpty());
}
use of org.mvel2.tests.core.res.Cheese in project drools by kiegroup.
the class AccumulateTemplateTest method testMethodGeneration.
@Test
public void testMethodGeneration() {
final String className = "accumulate0";
final String[] declarationTypes = new String[] { "String", "int" };
final Declaration[] declarations = new Declaration[] { new Declaration("name", null, null), new Declaration("age", null, null) };
final Declaration[] inner = new Declaration[] { new Declaration("cheese", new PatternExtractor(new ClassObjectType(Cheese.class)), null), new Declaration("price", store.getReader(Cheese.class, "price"), null) };
final String[] globals = new String[] { "aGlobal", "anotherGlobal" };
final List globalTypes = Arrays.asList(new String[] { "String", "String" });
final Map map = new HashMap();
map.put("className", StringUtils.ucFirst(className));
map.put("instanceName", className);
map.put("package", "org.drools");
map.put("ruleClassName", "Rule0");
map.put("invokerClassName", "Rule0" + StringUtils.ucFirst(className) + "Invoker");
map.put("declarations", declarations);
map.put("declarationTypes", declarationTypes);
map.put("globals", globals);
map.put("globalTypes", globalTypes);
map.put("innerDeclarations", inner);
map.put("attributes", new String[] { "x" });
map.put("attributesTypes", new String[] { "int" });
map.put("initCode", "x = 0;");
map.put("actionCode", "x += 1;");
map.put("reverseCode", "x -= 1;");
map.put("resultCode", "x + 10");
map.put("supportsReverse", "true");
map.put("resultType", Integer.class);
map.put("hashCode", new Integer(10));
TemplateRegistry registry = getRuleTemplateRegistry();
Object method = TemplateRuntime.execute(registry.getNamedTemplate("accumulateInnerClass"), null, new MapVariableResolverFactory(map), registry);
// System.out.println( method );
}
Aggregations