Search in sources :

Example 41 with ConstraintConnectiveDescr

use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.

the class DescrDumperTest method testProcessImplicitConstraints.

@Test
public void testProcessImplicitConstraints() throws Exception {
    String expr = "field1#Class!.field2";
    String expectedConstraints = "field1 instanceof Class";
    String expectedExpr = "((Class)field1).field2";
    AtomicExprDescr atomicExpr = new AtomicExprDescr(expr);
    ConstraintConnectiveDescr ccd = new ConstraintConnectiveDescr();
    String[] constraintsAndExpr = dumper.processImplicitConstraints(expr, atomicExpr, ccd, ccd.getDescrs().indexOf(atomicExpr), null);
    assertEquals(expectedConstraints, ccd.getDescrs().get(0).toString());
    assertEquals(expectedExpr, constraintsAndExpr[1]);
    assertEquals(expectedExpr, atomicExpr.getRewrittenExpression());
    expr = "field1!.field2#Class.field3";
    String expectedConstraints1 = "field1 != null";
    String expectedConstraints2 = "field1.field2 instanceof Class";
    expectedExpr = "((Class)field1.field2).field3";
    atomicExpr = new AtomicExprDescr(expr);
    ccd = new ConstraintConnectiveDescr();
    constraintsAndExpr = dumper.processImplicitConstraints(expr, atomicExpr, ccd, ccd.getDescrs().indexOf(atomicExpr), null);
    assertEquals(expectedConstraints1, ccd.getDescrs().get(0).toString());
    assertEquals(expectedConstraints2, ccd.getDescrs().get(1).toString());
    assertEquals(expectedExpr, constraintsAndExpr[1]);
    assertEquals(expectedExpr, atomicExpr.getRewrittenExpression());
    expr = "field1#Class.field2!.field3";
    expectedConstraints1 = "field1 instanceof Class";
    expectedConstraints2 = "((Class)field1).field2 != null";
    expectedExpr = "((Class)field1).field2.field3";
    atomicExpr = new AtomicExprDescr(expr);
    ccd = new ConstraintConnectiveDescr();
    constraintsAndExpr = dumper.processImplicitConstraints(expr, atomicExpr, ccd, ccd.getDescrs().indexOf(atomicExpr), null);
    assertEquals(expectedConstraints1, ccd.getDescrs().get(0).toString());
    assertEquals(expectedConstraints2, ccd.getDescrs().get(1).toString());
    assertEquals(expectedExpr, constraintsAndExpr[1]);
    assertEquals(expectedExpr, atomicExpr.getRewrittenExpression());
}
Also used : AtomicExprDescr(org.drools.drl.ast.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 42 with ConstraintConnectiveDescr

use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.

the class DescrDumperTest method testDumpMatches3.

@Test
public void testDumpMatches3() throws Exception {
    String input = "this[\"content\"] matches \"hello ;=\"";
    String expected = "this[\"content\"] ~= \"hello ;=\"";
    ConstraintConnectiveDescr descr = parse(input);
    String result = dumper.dump(descr);
    assertEquals(expected, result);
}
Also used : ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 43 with ConstraintConnectiveDescr

use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.

the class DescrDumperTest 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);
    DumperContext ctx = new DumperContext();
    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.drl.ast.descr.BindingDescr) ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) DumperContext(org.drools.compiler.lang.DumperContext) Test(org.junit.Test)

Example 44 with ConstraintConnectiveDescr

use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.

the class DescrDumperTest method testDumpComplex.

@Test
public void testDumpComplex() throws Exception {
    String input = "a ( > 60 && < 70 ) || ( > 50 && < 55 ) && a3 == \"black\" || a == 40 && a3 == \"pink\" || a == 12 && a3 == \"yellow\" || a3 == \"blue\"";
    String expected = "( ( a > 60 && a < 70 || a > 50 && a < 55 ) && a3 == \"black\" || a == 40 && a3 == \"pink\" || a == 12 && a3 == \"yellow\" || a3 == \"blue\" )";
    ConstraintConnectiveDescr descr = parse(input);
    String result = dumper.dump(descr);
    assertEquals(expected, result);
}
Also used : ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 45 with ConstraintConnectiveDescr

use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.

the class DescrDumperTest method testDumpBindings4.

@Test
public void testDumpBindings4() throws Exception {
    String input = "( $a : a > $b : b[10].prop || $x : someMethod(10) ) && 10 != 20";
    String expected = "( a > b[10].prop ) && 10 != 20";
    ConstraintConnectiveDescr descr = parse(input);
    String result = dumper.dump(descr);
    assertEquals(expected, result);
}
Also used : ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Aggregations

ConstraintConnectiveDescr (org.drools.drl.ast.descr.ConstraintConnectiveDescr)60 Test (org.junit.Test)29 BaseDescr (org.drools.drl.ast.descr.BaseDescr)23 BindingDescr (org.drools.drl.ast.descr.BindingDescr)17 AtomicExprDescr (org.drools.drl.ast.descr.AtomicExprDescr)15 RelationalExprDescr (org.drools.drl.ast.descr.RelationalExprDescr)12 AnnotationDescr (org.drools.drl.ast.descr.AnnotationDescr)8 DumperContext (org.drools.compiler.lang.DumperContext)7 DrlExprParser (org.drools.drl.parser.DrlExprParser)6 PredicateConstraint (org.drools.core.rule.PredicateConstraint)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 Declaration (org.drools.core.rule.Declaration)3 ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)3 DroolsParserException (org.drools.drl.parser.DroolsParserException)3 ClassObjectType (org.drools.core.base.ClassObjectType)2 QueryArgument (org.drools.core.rule.QueryArgument)2