use of org.drools.compiler.lang.descr.NotDescr in project drools by kiegroup.
the class NotHandler method start.
public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
parser.startElementBuilder(localName, attrs);
final NotDescr notDescr = new NotDescr();
return notDescr;
}
use of org.drools.compiler.lang.descr.NotDescr in project drools by kiegroup.
the class RuleParserTest method testFromWithInlineList.
@Test
public void testFromWithInlineList() throws Exception {
String source = "rule XYZ \n" + " when \n" + " o: Order( ) \n" + " not( Number( ) from [1, 2, 3] ) \n" + " then \n" + " System.err.println(\"Invalid customer id found!\"); \n" + " o.addError(\"Invalid customer id\"); \n" + "end \n";
PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals("XYZ", rule.getName());
PatternDescr number = (PatternDescr) ((NotDescr) rule.getLhs().getDescrs().get(1)).getDescrs().get(0);
assertEquals("[1, 2, 3]", ((FromDescr) number.getSource()).getDataSource().toString());
}
use of org.drools.compiler.lang.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.compiler.lang.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.compiler.lang.descr.NotDescr in project drools by kiegroup.
the class RuleParserTest method testNestedCEs.
@Test
public void testNestedCEs() throws Exception {
final RuleDescr rule = (RuleDescr) parseResource("rule", "nested_conditional_elements.drl");
assertNotNull(rule);
final AndDescr root = rule.getLhs();
final NotDescr not1 = (NotDescr) root.getDescrs().get(0);
final AndDescr and1 = (AndDescr) not1.getDescrs().get(0);
final PatternDescr state = (PatternDescr) and1.getDescrs().get(0);
final NotDescr not2 = (NotDescr) and1.getDescrs().get(1);
final AndDescr and2 = (AndDescr) not2.getDescrs().get(0);
final PatternDescr person = (PatternDescr) and2.getDescrs().get(0);
final PatternDescr cheese = (PatternDescr) and2.getDescrs().get(1);
final PatternDescr person2 = (PatternDescr) root.getDescrs().get(1);
final OrDescr or = (OrDescr) root.getDescrs().get(2);
final PatternDescr cheese2 = (PatternDescr) or.getDescrs().get(0);
final PatternDescr cheese3 = (PatternDescr) or.getDescrs().get(1);
assertEquals(state.getObjectType(), "State");
assertEquals(person.getObjectType(), "Person");
assertEquals(cheese.getObjectType(), "Cheese");
assertEquals(person2.getObjectType(), "Person");
assertEquals(cheese2.getObjectType(), "Cheese");
assertEquals(cheese3.getObjectType(), "Cheese");
}
Aggregations