use of org.drools.compiler.lang.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.compiler.lang.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.compiler.lang.descr.NotDescr in project drools by kiegroup.
the class CEDescrBuilderImpl method not.
/**
* {@inheritDoc}
*/
public CEDescrBuilder<CEDescrBuilder<P, T>, NotDescr> not() {
CEDescrBuilder<CEDescrBuilder<P, T>, NotDescr> not = new CEDescrBuilderImpl<CEDescrBuilder<P, T>, NotDescr>(this, new NotDescr());
((ConditionalElementDescr) descr).addDescr(not.getDescr());
return not;
}
use of org.drools.compiler.lang.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.compiler.lang.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");
}
Aggregations