use of org.drools.drl.ast.descr.NotDescr in project drools by kiegroup.
the class KiePMMLDescrLhsFactoryTest method declareConstraintNotIn.
@Test
public void declareConstraintNotIn() {
List<Object> values = Arrays.asList("3", "8.5");
String patternType = "INPUT2";
KiePMMLDescrLhsFactory.factory(lhsBuilder).declareConstraintNotIn(patternType, values);
final List<BaseDescr> descrs = lhsBuilder.getDescr().getDescrs();
assertNotNull(descrs);
assertEquals(1, descrs.size());
assertTrue(descrs.get(0) instanceof NotDescr);
NotDescr notDescr = (NotDescr) descrs.get(0);
assertEquals(1, notDescr.getDescrs().size());
assertTrue(notDescr.getDescrs().get(0) instanceof PatternDescr);
PatternDescr patternDescr = (PatternDescr) notDescr.getDescrs().get(0);
assertEquals(patternType, patternDescr.getObjectType());
assertNull(patternDescr.getIdentifier());
assertTrue(patternDescr.getConstraint() instanceof AndDescr);
AndDescr andDescr = (AndDescr) patternDescr.getConstraint();
assertEquals(1, andDescr.getDescrs().size());
assertTrue(andDescr.getDescrs().get(0) instanceof ExprConstraintDescr);
ExprConstraintDescr exprConstraintDescr = (ExprConstraintDescr) andDescr.getDescrs().get(0);
assertFalse(exprConstraintDescr.isNegated());
assertEquals(ExprConstraintDescr.Type.NAMED, exprConstraintDescr.getType());
String expected = "value in (3, 8.5)";
assertEquals(expected, exprConstraintDescr.getExpression());
}
use of org.drools.drl.ast.descr.NotDescr in project drools by kiegroup.
the class NotHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
final NotDescr notDescr = (NotDescr) parser.getCurrent();
if ((notDescr.getDescrs().size() != 1) && (notDescr.getDescrs().get(0).getClass() != PatternDescr.class)) {
throw new SAXParseException("<not> can only have a single <pattern...> as a child element", parser.getLocator());
}
final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parser.getParent();
parentDescr.addDescr(notDescr);
return null;
}
use of org.drools.drl.ast.descr.NotDescr in project drools by kiegroup.
the class RuleParserTest method testNotWithConstraint.
@Test
public void testNotWithConstraint() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "not_with_constraint.drl");
assertEquals(1, pkg.getRules().size());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals(2, rule.getLhs().getDescrs().size());
PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
final ExprConstraintDescr fieldBinding = (ExprConstraintDescr) pattern.getDescrs().get(0);
assertEquals("$likes:like", fieldBinding.getExpression());
final NotDescr not = (NotDescr) rule.getLhs().getDescrs().get(1);
pattern = (PatternDescr) not.getDescrs().get(0);
final ExprConstraintDescr fld = (ExprConstraintDescr) pattern.getConstraint().getDescrs().get(0);
assertEquals("type == $likes", fld.getExpression());
}
use of org.drools.drl.ast.descr.NotDescr in project drools by kiegroup.
the class RuleParserTest method testNotExistWithBrackets.
@Test
public void testNotExistWithBrackets() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "not_exist_with_brackets.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertNotNull(rule);
assertEquals("simple_rule", rule.getName());
final AndDescr lhs = rule.getLhs();
assertEquals(2, lhs.getDescrs().size());
final NotDescr not = (NotDescr) lhs.getDescrs().get(0);
assertEquals(1, not.getDescrs().size());
final PatternDescr pattern = (PatternDescr) not.getDescrs().get(0);
assertEquals("Cheese", pattern.getObjectType());
final ExistsDescr ex = (ExistsDescr) lhs.getDescrs().get(1);
assertEquals(1, ex.getDescrs().size());
final PatternDescr exPattern = (PatternDescr) ex.getDescrs().get(0);
assertEquals("Foo", exPattern.getObjectType());
}
use of org.drools.drl.ast.descr.NotDescr in project drools by kiegroup.
the class RuleParserTest method testNotNode.
@Test
public void testNotNode() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "rule_not.drl");
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertNotNull(rule);
assertEquals("simple_rule", rule.getName());
final AndDescr lhs = rule.getLhs();
assertEquals(1, lhs.getDescrs().size());
final NotDescr not = (NotDescr) lhs.getDescrs().get(0);
assertEquals(1, not.getDescrs().size());
final PatternDescr pattern = (PatternDescr) not.getDescrs().get(0);
assertEquals("Cheese", pattern.getObjectType());
assertEquals(1, pattern.getConstraint().getDescrs().size());
final AndDescr and = (AndDescr) pattern.getConstraint();
final ExprConstraintDescr fld = (ExprConstraintDescr) and.getDescrs().get(0);
assertEquals("type == \"stilton\"", fld.getExpression());
}
Aggregations