Search in sources :

Example 6 with ForallDescr

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

the class RuleParserTest method testForallWithFrom.

@Test
public void testForallWithFrom() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "forallwithfrom.drl");
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals(1, rule.getLhs().getDescrs().size());
    final ForallDescr forall = (ForallDescr) rule.getLhs().getDescrs().get(0);
    assertEquals(2, forall.getDescrs().size());
    final PatternDescr pattern = forall.getBasePattern();
    assertEquals("Person", pattern.getObjectType());
    assertEquals("$village", ((FromDescr) pattern.getSource()).getDataSource().toString());
    final List<BaseDescr> remaining = forall.getRemainingPatterns();
    assertEquals(1, remaining.size());
    final PatternDescr cheese = (PatternDescr) remaining.get(0);
    assertEquals("Cheese", cheese.getObjectType());
    assertEquals("$cheesery", ((FromDescr) cheese.getSource()).getDataSource().toString());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) FromDescr(org.drools.compiler.lang.descr.FromDescr) BaseDescr(org.drools.compiler.lang.descr.BaseDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) ForallDescr(org.drools.compiler.lang.descr.ForallDescr) Test(org.junit.Test)

Aggregations

ForallDescr (org.drools.compiler.lang.descr.ForallDescr)6 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)4 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)3 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)3 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)3 Test (org.junit.Test)3 InputStreamReader (java.io.InputStreamReader)1 List (java.util.List)1 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)1 ConditionalElementDescr (org.drools.compiler.lang.descr.ConditionalElementDescr)1 FromDescr (org.drools.compiler.lang.descr.FromDescr)1 Forall (org.drools.core.rule.Forall)1 Pattern (org.drools.core.rule.Pattern)1 Element (org.w3c.dom.Element)1