use of org.drools.drl.ast.descr.NotDescr in project drools by kiegroup.
the class XmlPackageReaderTest method testParseExists.
@Test
public void testParseExists() throws Exception {
final XmlPackageReader xmlPackageReader = getXmReader();
xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParseExists.xml")));
final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
assertNotNull(packageDescr);
RuleDescr obj = (RuleDescr) packageDescr.getRules().get(0);
Object existdescr = obj.getLhs().getDescrs().get(0);
assertTrue(existdescr instanceof ExistsDescr);
Object patternDescriptor = ((ExistsDescr) existdescr).getDescrs().get(0);
assertTrue(patternDescriptor instanceof PatternDescr);
assertEquals(((PatternDescr) patternDescriptor).getObjectType(), "Person");
Object notDescr = obj.getLhs().getDescrs().get(1);
assertEquals(notDescr.getClass().getName(), NotDescr.class.getName());
existdescr = ((NotDescr) notDescr).getDescrs().get(0);
patternDescriptor = ((ExistsDescr) existdescr).getDescrs().get(0);
assertTrue(patternDescriptor instanceof PatternDescr);
assertEquals(((PatternDescr) patternDescriptor).getObjectType(), "Cheese");
}
use of org.drools.drl.ast.descr.NotDescr in project drools by kiegroup.
the class RuleParserTest method testRuleOldSyntax1.
@Test
public void testRuleOldSyntax1() throws Exception {
final String source = "rule \"Test\" when ( not $r :LiteralRestriction( operator == Operator.EQUAL ) ) then end";
PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
assertEquals("Test", rule.getName());
assertEquals(1, rule.getLhs().getDescrs().size());
assertEquals(1, ((NotDescr) rule.getLhs().getDescrs().get(0)).getDescrs().size());
NotDescr notDescr = (NotDescr) rule.getLhs().getDescrs().get(0);
PatternDescr patternDescr = (PatternDescr) notDescr.getDescrs().get(0);
assertEquals("$r", patternDescr.getIdentifier());
assertEquals(1, patternDescr.getDescrs().size());
ExprConstraintDescr fieldConstraintDescr = (ExprConstraintDescr) patternDescr.getDescrs().get(0);
assertEquals("operator == Operator.EQUAL", fieldConstraintDescr.getExpression());
}
use of org.drools.drl.ast.descr.NotDescr in project drools by kiegroup.
the class KnowledgeBuilderTest method testNot.
@Test
public void testNot() throws Exception {
KnowledgeBuilderImpl builder = new KnowledgeBuilderImpl();
// Make sure we can't accessa variable bound inside the not node
RuleImpl rule = createRule(new NotDescr(), builder, "update(stilton);");
assertTrue(builder.hasErrors());
builder = new KnowledgeBuilderImpl();
rule = createRule(new NotDescr(), builder, "");
assertEquals(0, builder.getErrors().getErrors().length);
final GroupElement lhs = rule.getLhs();
assertLength(1, lhs.getChildren());
final GroupElement not = (GroupElement) lhs.getChildren().get(0);
assertLength(1, not.getChildren());
final Pattern pattern = (Pattern) not.getChildren().get(0);
}
use of org.drools.drl.ast.descr.NotDescr in project drools by kiegroup.
the class RuleParserTest method testRuleParseLhs3.
@Test
public void testRuleParseLhs3() throws Exception {
final String text = "rule X when (or\nnot Person()\n(and Cheese()\nMeat()\nWine())) then end";
AndDescr pattern = ((RuleDescr) parse("rule", text)).getLhs();
assertEquals(1, pattern.getDescrs().size());
OrDescr or = (OrDescr) pattern.getDescrs().get(0);
assertEquals(2, or.getDescrs().size());
NotDescr not = (NotDescr) or.getDescrs().get(0);
AndDescr and = (AndDescr) or.getDescrs().get(1);
assertEquals(1, not.getDescrs().size());
PatternDescr person = (PatternDescr) not.getDescrs().get(0);
assertEquals("Person", person.getObjectType());
assertEquals(3, and.getDescrs().size());
PatternDescr cheese = (PatternDescr) and.getDescrs().get(0);
assertEquals("Cheese", cheese.getObjectType());
PatternDescr meat = (PatternDescr) and.getDescrs().get(1);
assertEquals("Meat", meat.getObjectType());
PatternDescr wine = (PatternDescr) and.getDescrs().get(2);
assertEquals("Wine", wine.getObjectType());
}
use of org.drools.drl.ast.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