Search in sources :

Example 6 with ConstraintConnectiveDescr

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

the class DescrDumperTest method testDumpWithDateAttr.

@Test
@Ignore
public void testDumpWithDateAttr() throws Exception {
    String input = "son.birthDate == \"01-jan-2000\"";
    String expected = "son.birthDate == org.drools.util.DateUtils.parseDate( \"01-jan-2000\" )";
    ConstraintConnectiveDescr descr = parse(input);
    String result = dumper.dump(descr);
    assertEquals(expected, result);
}
Also used : ConstraintConnectiveDescr(org.drools.drl.ast.descr.ConstraintConnectiveDescr) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with ConstraintConnectiveDescr

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

the class DescrDumperTest method testProcessNullSafeDereferencing.

@Test
public void testProcessNullSafeDereferencing() throws Exception {
    String expr = "field1!.field2";
    String expectedNullCheck = "field1 != null";
    String expectedExpr = "field1.field2";
    AtomicExprDescr atomicExpr = new AtomicExprDescr(expr);
    ConstraintConnectiveDescr ccd = new ConstraintConnectiveDescr();
    String[] nullCheckAndExpr = dumper.processImplicitConstraints(expr, atomicExpr, ccd, ccd.getDescrs().indexOf(atomicExpr), null);
    assertEquals(expectedNullCheck, ccd.getDescrs().get(0).toString());
    assertEquals(expectedExpr, nullCheckAndExpr[1]);
    assertEquals(expectedExpr, atomicExpr.getRewrittenExpression());
    expr = "field1!.field2!.field3";
    String expectedNullCheck1 = "field1 != null";
    String expectedNullCheck2 = "field1.field2 != null";
    expectedExpr = "field1.field2.field3";
    atomicExpr = new AtomicExprDescr(expr);
    ccd = new ConstraintConnectiveDescr();
    nullCheckAndExpr = dumper.processImplicitConstraints(expr, atomicExpr, ccd, ccd.getDescrs().indexOf(atomicExpr), null);
    assertEquals(expectedNullCheck1, ccd.getDescrs().get(0).toString());
    assertEquals(expectedNullCheck2, ccd.getDescrs().get(1).toString());
    assertEquals(expectedExpr, nullCheckAndExpr[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 8 with ConstraintConnectiveDescr

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

the class DescrDumperTest method testDumpExcludes2.

@Test
public void testDumpExcludes2() throws Exception {
    String input = "list not excludes \"b\"";
    String expected = "list contains \"b\"";
    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 9 with ConstraintConnectiveDescr

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

the class DescrDumperTest method testDumpBindingsWithRestriction.

@Test
public void testDumpBindingsWithRestriction() throws Exception {
    String input = "$x : age > 10 && < 20 || > 30";
    String expected = "( age > 10 && age < 20 || age > 30 )";
    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 10 with ConstraintConnectiveDescr

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

the class DescrDumperTest method testDumpMatches2.

@Test
public void testDumpMatches2() throws Exception {
    String input = "type.toString matches 'something\\swith\\tsingle escapes'";
    String expected = "type.toString ~= \"something\\swith\\tsingle escapes\"";
    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