use of org.mvel2.tests.core.res.Cheese in project drools by kiegroup.
the class AccumulateTemplateTest method testInvokerGenerationSinglePattern.
@Test
public void testInvokerGenerationSinglePattern() {
final String className = "accumulate0";
final String[] declarationTypes = new String[] { "String", "int" };
final Declaration[] declarations = new Declaration[] { new Declaration("name", store.getReader(Person.class, "name"), null), new Declaration("age", store.getReader(Person.class, "age"), 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 Attribute[] { new Attribute("int", "x") });
map.put("initCode", "x = 0;");
map.put("actionCode", "x += 1;");
map.put("reverseCode", "");
map.put("resultCode", "x + 10");
map.put("supportsReverse", "false");
map.put("resultType", Integer.class);
map.put("hashCode", new Integer(10));
map.put("isMultiPattern", Boolean.FALSE);
TemplateRegistry registry = getInvokerTemplateRegistry();
Object method = TemplateRuntime.execute(registry.getNamedTemplate("accumulateInvoker"), null, new MapVariableResolverFactory(map), registry);
// System.out.println( method );
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mikebrock.
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))");
Cheesery p1 = new Cheesery("bobbo", new Cheese("cheddar", 15));
Cheesery p2 = (Cheesery) executeExpression(compiler.compile(ctx), new DefaultLocalVariableResolverFactory());
assertEquals(p1, p2);
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mikebrock.
the class TypesAndInferenceTests method testEgressType.
public void testEgressType() {
ExpressionCompiler compiler = new ExpressionCompiler("( $cheese )");
ParserContext context = new ParserContext();
context.addInput("$cheese", Cheese.class);
assertEquals(Cheese.class, compiler.compile(context).getKnownEgressType());
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mikebrock.
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");
Cheese actualCheese = (Cheese) executeExpression(compiler.compile(ctx), createTestMap());
assertEquals(expectedCheese.getUseBy(), actualCheese.getUseBy());
}
use of org.mvel2.tests.core.res.Cheese in project mvel by mikebrock.
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());
}
Aggregations