Refine search
ParserContext context = new ParserContext(); context.addImport("MVEL", MVEL.class); context.addImport("MvelHelper", MvelHelper.class); exp = MVEL.compileExpression(modifiedRule, context); expressionCache.put(rule, exp); mvelParameters.put(parameter, ruleParameters.get(parameter)); Object test = MVEL.executeExpression(exp, mvelParameters); if (test == null) {
private static boolean executeTestCase(Serializable exp, String val) { final Map multiValueMap = new MultiValueMap(); multiValueMap.put(val, val); final Level2 level2 = new Level2() { @Override public Map getMultiValueSkuAttributes() { return multiValueMap; } }; Level1 level1 = new Level1() { @Override public Level2 getLevel2() { return level2; } }; Map parameters = new HashMap(); parameters.put("level1", level1); return (Boolean) MVEL.executeExpression(exp, parameters); }
ParserContext context = new ParserContext(); Serializable domainExp1 = MVEL.compileExpression("result = false; for (cat : currentItem.product.allParentCategories) {if (cat.name == 't-shirt') {result = true;}}; return result and order.subTotal.amount >= 50", context); Boolean expressionOutcome1 = (Boolean)MVEL.executeExpression(domainExp1, domainVars); assert expressionOutcome1 != null && expressionOutcome1; Serializable domainExp2 = MVEL.compileExpression("($ in currentItem.product.allParentCategories if $.name == 't-shirt') != empty and order.subTotal.amount >= 50", context); Boolean expressionOutcome2 = (Boolean)MVEL.executeExpression(domainExp2, domainVars); assert expressionOutcome2 != null && expressionOutcome2;
public void testMVEL222() throws IOException { String script = "for (int i= 0; i < 10; i++ ){ values[i] = 1.0; }"; Map<String, Object> scriptVars = new HashMap<String, Object>(); double[] values = new double[10]; scriptVars.put("values", values); Serializable expression = MVEL.compileExpression(script); for (int i = 0; i < 6; i++) { scriptVars.put("values", values); MVEL.executeExpression(expression, scriptVars); } }
public void testWhileUsingImports() { Map<String, Object> imports = new HashMap<String, Object>(); imports.put("ArrayList", java.util.ArrayList.class); imports.put("List", java.util.List.class); ParserContext context = new ParserContext(imports, null, "testfile"); ExpressionCompiler compiler = new ExpressionCompiler("List list = new ArrayList(); return (list == empty)", context); assertTrue((Boolean) executeExpression(compiler.compile(), new DefaultLocalVariableResolverFactory())); }
public Object compiledExecute(final String ex) { final Serializable compiled = MVEL.compileExpression( ex ); return MVEL.executeExpression( compiled, new Object(), new HashMap() ); }
public void testLateResolveOfClass() { ParserContext ctx = new ParserContext(); ctx.addImport(Foo.class); ExpressionCompiler compiler = new ExpressionCompiler("System.out.println(new Foo());", ctx); System.out.println(executeExpression(compiler.compile())); }
public void testJIRA103b() { MvelContext mvelContext = new MvelContext(); Map map = new HashMap(); map.put("ctx", mvelContext); Serializable c = compileExpression("ctx.regkeys = 'foo'"); executeExpression(c, map); executeExpression(c, map); }
@Test public void test1() { final ParserContext pc = new ParserContext(); pc.addInput("x", String.class); pc.setStrongTyping(true); final Object o = MVEL.compileExpression("x.startsWith('d')", pc); final Map vars = new HashMap(); vars.put("x", "d"); MVEL.executeExpression(o, vars); System.out.println(o); }
ParserContext context = new ParserContext(); Serializable domainExp1 = MVEL.compileExpression("offer.type.equals(OfferType.FULFILLMENT_GROUP) and (($ in order.fulfillmentGroups if $.type.equals(FulfillmentType.PHYSICAL)) != empty)", context); Boolean expressionOutcome1 = (Boolean)MVEL.executeExpression(domainExp1, domainVars); assert expressionOutcome1 != null && expressionOutcome1;
public Object compiledExecute(String ex) { Serializable compiled = MVEL.compileExpression(ex); Object first = MVEL.executeExpression(compiled, null, map); Object second = MVEL.executeExpression(compiled, null, map); if (first != null && !first.getClass().isArray()) assertEquals(first, second); return second; } }
public void testDynamicImportsInMap() { ParserContext ctx = new ParserContext(); ctx.addPackageImport("org.mvel2.tests.core.res"); ExpressionCompiler compiler = new ExpressionCompiler("[ 'bobba' : new User('Bobba', 'Feta') ]", ctx); Map map = (Map) executeExpression(compiler.compile()); User user = (User) map.get("bobba"); assertEquals("Bobba", user.getFirstName()); }
public void testMath36() { String expression = "b/x*z/a+x-b+x-b/z+y"; Map map = new HashMap(); map.put("a", 10); map.put("b", 20); map.put("c", 30); map.put("x", 40); map.put("y", 50); map.put("z", 60); Serializable s = compileExpression(expression); assertNumEquals(20d / 40d * 60d / 10d + 40d - 20d + 40d - 20d / 60d + 50d, executeExpression(s, map)); }
public void testDeepMethodNameResolution() { String expression = "variables = [ \"symbol\" : \"RHT\" ]; \n" + "drools.getProcessManager().startProcess(\"id\", variables );"; // third pass ParserContext ctx = new ParserContext(); ctx.setStrongTyping(true); ctx.addInput("drools", KnowledgeRuntimeHelper.class); Map vars = new HashMap(); vars.put("drools", new KnowledgeRuntimeHelper()); Serializable expr = MVEL.compileExpression(expression, ctx); executeExpression(expr, vars); }
@Test public void testOfferAppliesToSpecificItems() { DiscreteOrderItemImpl orderItem = new DiscreteOrderItemImpl(); Sku sku = new SkuImpl(); sku.setRetailPrice(new Money("1")); sku.setId(1234L); orderItem.setSku(sku); OfferImpl offer = new OfferImpl(); offer.setType(OfferType.ORDER_ITEM); //Set up MVEL Context ParserContext context = new ParserContext(); //Import OfferType into the MVEL context since it may be used context.addImport("OfferType", OfferType.class); context.addImport("FulfillmentType", FulfillmentType.class); //Compile the MVEL Expression Serializable domainExp1 = MVEL.compileExpression("offer.type == OfferType.ORDER_ITEM and (currentItem.sku.id in [1234, 2345, 5678])", context); //Add variables to a HashMap that should be passed in to execute the expression HashMap<String, Object> domainVars = new HashMap<>(); domainVars.put("currentItem", orderItem); domainVars.put("offer", offer); //Execute the expression Boolean expressionOutcome1 = (Boolean)MVEL.executeExpression(domainExp1, domainVars); assert expressionOutcome1 != null && expressionOutcome1; }
public void testMVEL238() throws IOException { String expr = new String(loadFromFile(new File("src/test/java/org/mvel2/tests/MVEL238.mvel"))); Serializable s = MVEL.compileExpression(expr); System.out.println(MVEL.executeExpression(s, new HashMap())); System.out.println(MVEL.executeExpression(s, new HashMap())); }
public void testDynamicImportsInList() { ParserContext ctx = new ParserContext(); ctx.addPackageImport("org.mvel2.tests.core.res"); ExpressionCompiler compiler = new ExpressionCompiler("[ new User('Bobba', 'Feta') ]", ctx); List list = (List) executeExpression(compiler.compile()); User user = (User) list.get(0); assertEquals("Bobba", user.getFirstName()); }
public void testVirtProperty() { Map<String, Object> testMap = new HashMap<String, Object>(); testMap.put("test", "foo"); Map<String, Object> vars = new HashMap<String, Object>(); vars.put("mp", testMap); assertEquals("bar", executeExpression(compileExpression("mp.test = 'bar'; mp.test"), vars)); }
public void testMinusOperatorWithoutSpace() { String str = "length == $c.length -1"; ParserConfiguration pconf = new ParserConfiguration(); ParserContext pctx = new ParserContext(pconf); ExecutableStatement stmt = (ExecutableStatement) MVEL.compileExpression(str, pctx); Column col1 = new Column("x", 0); Column col2 = new Column("x", 0); Map<String, Object> vars = new HashMap<String, Object>(); vars.put("$c", col2); Boolean result = (Boolean) MVEL.executeExpression(stmt, col1, vars); assertFalse(result); }
private void testMVELUntyped(String text) { String str = IMPORTS + text; ParserContext pctx = new ParserContext(); Map<String, Object> vars = new HashMap<String, Object>(); Object o = MVEL.compileExpression(str, pctx); MVEL.executeExpression(o, vars); }