Search in sources :

Example 1 with NotDescr

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;
}
Also used : NotDescr(org.drools.compiler.lang.descr.NotDescr)

Example 2 with 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());
}
Also used : NotDescr(org.drools.compiler.lang.descr.NotDescr) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) FromDescr(org.drools.compiler.lang.descr.FromDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 3 with NotDescr

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());
}
Also used : NotDescr(org.drools.compiler.lang.descr.NotDescr) ExistsDescr(org.drools.compiler.lang.descr.ExistsDescr) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 4 with NotDescr

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());
}
Also used : NotDescr(org.drools.compiler.lang.descr.NotDescr) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 5 with NotDescr

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");
}
Also used : NotDescr(org.drools.compiler.lang.descr.NotDescr) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) OrDescr(org.drools.compiler.lang.descr.OrDescr) Test(org.junit.Test)

Aggregations

NotDescr (org.drools.compiler.lang.descr.NotDescr)16 Test (org.junit.Test)12 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)11 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)10 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)7 AndDescr (org.drools.compiler.lang.descr.AndDescr)6 OrDescr (org.drools.compiler.lang.descr.OrDescr)4 ExistsDescr (org.drools.compiler.lang.descr.ExistsDescr)3 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)3 ConditionalElementDescr (org.drools.compiler.lang.descr.ConditionalElementDescr)2 FromDescr (org.drools.compiler.lang.descr.FromDescr)2 InputStreamReader (java.io.InputStreamReader)1 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)1 CEDescrBuilder (org.drools.compiler.lang.api.CEDescrBuilder)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)1 GroupElement (org.drools.core.rule.GroupElement)1 Pattern (org.drools.core.rule.Pattern)1 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)1 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)1