use of org.drools.drl.ast.descr.ConstraintConnectiveDescr in project drools by kiegroup.
the class DescrDumperTest method testDumpBindings.
@Test
public void testDumpBindings() throws Exception {
String input = "$x : property > value";
String expected = "property > value";
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("property", bind.getExpression());
}
use of org.drools.drl.ast.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());
}
use of org.drools.drl.ast.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());
}
use of org.drools.drl.ast.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());
}
use of org.drools.drl.ast.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());
}
Aggregations