Search in sources :

Example 51 with ConstraintConnectiveDescr

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

the class MVELDumperTest method testDumpBindings2.

@Test
public void testDumpBindings2() throws Exception {
    String input = "( $a : a > $b : b[10].prop || 10 != 20 ) && $x : someMethod(10) == 20";
    String expected = "( a > b[10].prop || 10 != 20 ) && someMethod(10) == 20";
    ConstraintConnectiveDescr descr = parse(input);
    MVELDumperContext ctx = new MVELDumperContext();
    String result = dumper.dump(descr, ctx);
    assertEquals(expected, result);
    assertEquals(3, ctx.getBindings().size());
    BindingDescr bind = ctx.getBindings().get(0);
    assertEquals("$a", bind.getVariable());
    assertEquals("a", bind.getExpression());
    bind = ctx.getBindings().get(1);
    assertEquals("$b", bind.getVariable());
    assertEquals("b[10].prop", bind.getExpression());
    bind = ctx.getBindings().get(2);
    assertEquals("$x", bind.getVariable());
    assertEquals("someMethod(10)", 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 52 with ConstraintConnectiveDescr

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

the class MVELDumperTest 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.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 53 with ConstraintConnectiveDescr

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

the class MVELDumperTest method testProcessInlineCast.

@Test
public void testProcessInlineCast() throws Exception {
    String expr = "field1#Class.field2";
    String expectedInstanceof = "field1 instanceof Class";
    String expectedcasted = "((Class)field1).field2";
    AtomicExprDescr atomicExpr = new AtomicExprDescr(expr);
    ConstraintConnectiveDescr ccd = new ConstraintConnectiveDescr();
    ccd.addDescr(atomicExpr);
    String[] instanceofAndCastedExpr = dumper.processImplicitConstraints(expr, atomicExpr, ccd, ccd.getDescrs().indexOf(atomicExpr), null);
    assertEquals(2, ccd.getDescrs().size());
    assertEquals(expectedInstanceof, ccd.getDescrs().get(0).toString());
    assertEquals(expectedcasted, atomicExpr.getRewrittenExpression());
    expr = "field1#Class1.field2#Class2.field3";
    String expectedInstanceof1 = "field1 instanceof Class1";
    String expectedInstanceof2 = "((Class1)field1).field2 instanceof Class2";
    expectedcasted = "((Class2)((Class1)field1).field2).field3";
    atomicExpr = new AtomicExprDescr(expr);
    ccd = new ConstraintConnectiveDescr();
    instanceofAndCastedExpr = dumper.processImplicitConstraints(expr, atomicExpr, ccd, ccd.getDescrs().indexOf(atomicExpr), null);
    assertEquals(expectedInstanceof1, ccd.getDescrs().get(0).toString());
    assertEquals(expectedInstanceof2, ccd.getDescrs().get(1).toString());
    assertEquals(expectedcasted, instanceofAndCastedExpr[1]);
    assertEquals(expectedcasted, atomicExpr.getRewrittenExpression());
}
Also used : AtomicExprDescr(org.drools.compiler.lang.descr.AtomicExprDescr) ConstraintConnectiveDescr(org.drools.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 54 with ConstraintConnectiveDescr

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

the class MVELDumperTest method testDumpMatches.

@Test
public void testDumpMatches() 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.compiler.lang.descr.ConstraintConnectiveDescr) Test(org.junit.Test)

Example 55 with ConstraintConnectiveDescr

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

the class MVELDumperTest method testDumpBindings3.

@Test
public void testDumpBindings3() throws Exception {
    String input = "( $a : a > $b : b[10].prop || 10 != 20 ) && $x : someMethod(10)";
    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.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