Search in sources :

Example 66 with AndDescr

use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.

the class RuleParserTest method testBoundVariables.

@Test
public void testBoundVariables() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "bindings.drl");
    final RuleDescr ruleDescr = (RuleDescr) pkg.getRules().get(0);
    final AndDescr lhs = ruleDescr.getLhs();
    assertEquals(2, lhs.getDescrs().size());
    final PatternDescr cheese = (PatternDescr) lhs.getDescrs().get(0);
    assertEquals("Cheese", cheese.getObjectType());
    assertEquals(1, cheese.getDescrs().size());
    ExprConstraintDescr fieldBinding = (ExprConstraintDescr) cheese.getDescrs().get(0);
    assertEquals("$type : type == \"stilton\"", fieldBinding.getExpression());
    final PatternDescr person = (PatternDescr) lhs.getDescrs().get(1);
    assertEquals(2, person.getDescrs().size());
    fieldBinding = (ExprConstraintDescr) person.getDescrs().get(0);
    assertEquals("$name : name == \"bob\"", fieldBinding.getExpression());
    ExprConstraintDescr fld = (ExprConstraintDescr) person.getDescrs().get(1);
    assertEquals("likes == $type", fld.getExpression());
}
Also used : 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) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 67 with AndDescr

use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.

the class AndDescrTest method testAddUnboundPatternsEtc.

@Test
public void testAddUnboundPatternsEtc() {
    final AndDescr and = new AndDescr();
    and.addDescr(new NotDescr());
    and.addDescr(new PatternDescr("Foo"));
    and.addDescr(new NotDescr());
    assertEquals(3, and.getDescrs().size());
}
Also used : NotDescr(org.drools.compiler.lang.descr.NotDescr) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) Test(org.junit.Test)

Example 68 with AndDescr

use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.

the class RuleParserTest method testBracketsPrecedence.

/**
 */
@Test
public void testBracketsPrecedence() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "brackets_precedence.drl");
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    final AndDescr rootAnd = (AndDescr) rule.getLhs();
    assertEquals(2, rootAnd.getDescrs().size());
    final OrDescr leftOr = (OrDescr) rootAnd.getDescrs().get(0);
    assertEquals(2, leftOr.getDescrs().size());
    final NotDescr not = (NotDescr) leftOr.getDescrs().get(0);
    final PatternDescr foo1 = (PatternDescr) not.getDescrs().get(0);
    assertEquals("Foo", foo1.getObjectType());
    final PatternDescr foo2 = (PatternDescr) leftOr.getDescrs().get(1);
    assertEquals("Foo", foo2.getObjectType());
    final OrDescr rightOr = (OrDescr) rootAnd.getDescrs().get(1);
    assertEquals(2, rightOr.getDescrs().size());
    final PatternDescr shoes = (PatternDescr) rightOr.getDescrs().get(0);
    assertEquals("Shoes", shoes.getObjectType());
    final PatternDescr butt = (PatternDescr) rightOr.getDescrs().get(1);
    assertEquals("Butt", butt.getObjectType());
}
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) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) OrDescr(org.drools.compiler.lang.descr.OrDescr) Test(org.junit.Test)

Example 69 with AndDescr

use of org.drools.compiler.lang.descr.AndDescr 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());
}
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) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 70 with AndDescr

use of org.drools.compiler.lang.descr.AndDescr in project drools by kiegroup.

the class RuleParserTest method testStringEscapes.

@Test
public void testStringEscapes() throws Exception {
    String source = "package com.sample  rule test  when  Cheese( type matches \"\\..*\\\\.\" )  then  end";
    PackageDescr pkg = (PackageDescr) parse("compilationUnit", source);
    assertEquals("com.sample", pkg.getName());
    RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals("test", rule.getName());
    assertEquals(1, rule.getLhs().getDescrs().size());
    PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    AndDescr constraint = (AndDescr) pattern.getConstraint();
    assertEquals(1, constraint.getDescrs().size());
    assertEquals("type matches \"\\..*\\\\.\"", constraint.getDescrs().get(0).toString());
}
Also used : 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)

Aggregations

AndDescr (org.drools.compiler.lang.descr.AndDescr)79 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)54 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)52 Test (org.junit.Test)52 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)39 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)27 Cheese (org.drools.compiler.Cheese)13 ConditionalElementDescr (org.drools.compiler.lang.descr.ConditionalElementDescr)12 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)12 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)11 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)8 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)8 OrDescr (org.drools.compiler.lang.descr.OrDescr)8 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)7 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)7 NotDescr (org.drools.compiler.lang.descr.NotDescr)6 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)5 List (java.util.List)4 EvalDescr (org.drools.compiler.lang.descr.EvalDescr)4 QueryDescr (org.drools.compiler.lang.descr.QueryDescr)4