Search in sources :

Example 6 with ConstraintConnectiveDescr

use of org.drools.compiler.lang.descr.ConstraintConnectiveDescr in project drools by kiegroup.

the class DRLExprParserTest method testDoubleBinding.

@Test
public void testDoubleBinding() throws Exception {
    String source = "$x : x.m( 1, a ) && $y : y[z].foo";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(2, result.getDescrs().size());
    BindingDescr bind = (BindingDescr) result.getDescrs().get(0);
    assertEquals("$x", bind.getVariable());
    assertEquals("x.m( 1, a )", bind.getExpression());
    bind = (BindingDescr) result.getDescrs().get(1);
    assertEquals("$y", bind.getVariable());
    assertEquals("y[z].foo", bind.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 7 with ConstraintConnectiveDescr

use of org.drools.compiler.lang.descr.ConstraintConnectiveDescr in project drools by kiegroup.

the class MVELDumperTest method testDumpContains.

@Test
public void testDumpContains() throws Exception {
    String input = "list contains \"b\"";
    String expected = "list contains \"b\"";
    ConstraintConnectiveDescr descr = parse(input);
    String result = dumper.dump(descr);
    assertEquals(expected, result);
}
Also used : ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 8 with ConstraintConnectiveDescr

use of org.drools.compiler.lang.descr.ConstraintConnectiveDescr in project drools by kiegroup.

the class MVELDumperTest method testDumpBindingsComplexOp.

@Test
public void testDumpBindingsComplexOp() throws Exception {
    String input = "$x : age in (10, 20, $someVal)";
    String expected = "( age == 10 || age == 20 || age == $someVal )";
    ConstraintConnectiveDescr descr = parse(input);
    MVELDumperContext ctx = new MVELDumperContext();
    String result = dumper.dump(descr, ctx);
    assertEquals(expected, result);
    assertEquals(1, ctx.getBindings().size());
    BindingDescr bind = ctx.getBindings().get(0);
    assertEquals("$x", bind.getVariable());
    assertEquals("age", bind.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) MVELDumperContext(org.drools.compiler.lang.MVELDumper.MVELDumperContext) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 9 with ConstraintConnectiveDescr

use of org.drools.compiler.lang.descr.ConstraintConnectiveDescr in project drools by kiegroup.

the class MVELDumperTest method parse.

public ConstraintConnectiveDescr parse(final String constraint) {
    DrlExprParser parser = new DrlExprParser(LanguageLevelOption.DRL6);
    ConstraintConnectiveDescr result = parser.parse(constraint);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    return result;
}
Also used : ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) DrlExprParser(org.drools.compiler.compiler.DrlExprParser)

Example 10 with ConstraintConnectiveDescr

use of org.drools.compiler.lang.descr.ConstraintConnectiveDescr in project drools by kiegroup.

the class MVELDumperTest method testDumpBindingsComplexOp2.

@Test
public void testDumpBindingsComplexOp2() throws Exception {
    String input = "$x : age not in (10, 20, $someVal)";
    String expected = "age != 10 && age != 20 && age != $someVal";
    ConstraintConnectiveDescr descr = parse(input);
    MVELDumperContext ctx = new MVELDumperContext();
    String result = dumper.dump(descr, ctx);
    assertEquals(expected, result);
    assertEquals(1, ctx.getBindings().size());
    BindingDescr bind = ctx.getBindings().get(0);
    assertEquals("$x", bind.getVariable());
    assertEquals("age", bind.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) MVELDumperContext(org.drools.compiler.lang.MVELDumper.MVELDumperContext) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Aggregations

ConstraintConnectiveDescr (org.drools.compiler.lang.descr.ConstraintConnectiveDescr)60 Test (org.junit.Test)29 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)23 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)17 AnnotatedBaseDescr (org.drools.compiler.lang.descr.AnnotatedBaseDescr)16 AtomicExprDescr (org.drools.compiler.lang.descr.AtomicExprDescr)15 RelationalExprDescr (org.drools.compiler.lang.descr.RelationalExprDescr)12 AnnotationDescr (org.drools.compiler.lang.descr.AnnotationDescr)8 DrlExprParser (org.drools.compiler.compiler.DrlExprParser)6 MVELDumperContext (org.drools.compiler.lang.MVELDumper.MVELDumperContext)5 PredicateConstraint (org.drools.core.rule.PredicateConstraint)4 EvaluatorConstraint (org.drools.core.rule.constraint.EvaluatorConstraint)4 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)4 NegConstraint (org.drools.core.rule.constraint.NegConstraint)4 XpathConstraint (org.drools.core.rule.constraint.XpathConstraint)4 Constraint (org.drools.core.spi.Constraint)4 ArrayList (java.util.ArrayList)3 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)3 DroolsParserException (org.drools.compiler.compiler.DroolsParserException)3 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)3