Search in sources :

Example 1 with ConstraintConnectiveDescr

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

the class DRLExprParserTest method testBinding.

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

Example 2 with ConstraintConnectiveDescr

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

the class DRLExprParserTest method testBindingConstraint.

@Test
public void testBindingConstraint() throws Exception {
    String source = "$x : property > value";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(1, result.getDescrs().size());
    RelationalExprDescr rel = (RelationalExprDescr) result.getDescrs().get(0);
    assertEquals(">", rel.getOperator());
    BindingDescr bind = (BindingDescr) rel.getLeft();
    assertEquals("$x", bind.getVariable());
    assertEquals("property", bind.getExpression());
    AtomicExprDescr right = (AtomicExprDescr) rel.getRight();
    assertEquals("value", right.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr) Test(org.junit.Test)

Example 3 with ConstraintConnectiveDescr

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

the class DRLExprParserTest method testBindingWithRestrictions.

@Test
public void testBindingWithRestrictions() throws Exception {
    String source = "$x : property > value && < 20";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(2, result.getDescrs().size());
    RelationalExprDescr rel = (RelationalExprDescr) result.getDescrs().get(0);
    assertEquals(">", rel.getOperator());
    BindingDescr bind = (BindingDescr) rel.getLeft();
    assertEquals("$x", bind.getVariable());
    assertEquals("property", bind.getExpression());
    AtomicExprDescr right = (AtomicExprDescr) rel.getRight();
    assertEquals("value", right.getExpression());
    rel = (RelationalExprDescr) result.getDescrs().get(1);
    assertEquals("<", rel.getOperator());
    AtomicExprDescr left = (AtomicExprDescr) rel.getLeft();
    assertEquals("property", left.getExpression());
    right = (AtomicExprDescr) rel.getRight();
    assertEquals("20", right.getExpression());
}
Also used : BindingDescr(org.drools.compiler.lang.descr.BindingDescr) AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr) Test(org.junit.Test)

Example 4 with ConstraintConnectiveDescr

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

the class DRLExprParserTest method testNestedExpression.

@Test(timeout = 10000L)
public void testNestedExpression() throws Exception {
    // DROOLS-982
    String source = "(((((((((((((((((((((((((((((((((((((((((((((((((( a > b ))))))))))))))))))))))))))))))))))))))))))))))))))";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(1, result.getDescrs().size());
    RelationalExprDescr expr = (RelationalExprDescr) result.getDescrs().get(0);
    assertEquals(">", expr.getOperator());
    AtomicExprDescr left = (AtomicExprDescr) expr.getLeft();
    AtomicExprDescr right = (AtomicExprDescr) expr.getRight();
    assertEquals("a", left.getExpression());
    assertEquals("b", right.getExpression());
}
Also used : AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr) Test(org.junit.Test)

Example 5 with ConstraintConnectiveDescr

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

the class DRLExprParserTest method testAndConnective.

@Test
public void testAndConnective() throws Exception {
    String source = "a > b && 10 != 20";
    ConstraintConnectiveDescr result = parser.parse(source);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(ConnectiveType.AND, result.getConnective());
    assertEquals(2, result.getDescrs().size());
    RelationalExprDescr expr = (RelationalExprDescr) result.getDescrs().get(0);
    assertEquals(">", expr.getOperator());
    AtomicExprDescr left = (AtomicExprDescr) expr.getLeft();
    AtomicExprDescr right = (AtomicExprDescr) expr.getRight();
    assertEquals("a", left.getExpression());
    assertEquals("b", right.getExpression());
    expr = (RelationalExprDescr) result.getDescrs().get(1);
    assertEquals("!=", expr.getOperator());
    left = (AtomicExprDescr) expr.getLeft();
    right = (AtomicExprDescr) expr.getRight();
    assertEquals("10", left.getExpression());
    assertEquals("20", right.getExpression());
}
Also used : AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) RelationalExprDescr(org.drools.compiler.lang.descr.RelationalExprDescr) 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