Search in sources :

Example 6 with ExprConstraintDescr

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

the class RuleParserTest method testPluggableOperators.

@Test
public void testPluggableOperators() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "pluggable_operators.drl");
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals(5, rule.getLhs().getDescrs().size());
    final PatternDescr eventA = (PatternDescr) rule.getLhs().getDescrs().get(0);
    assertEquals("$a", eventA.getIdentifier());
    assertEquals("EventA", eventA.getObjectType());
    final PatternDescr eventB = (PatternDescr) rule.getLhs().getDescrs().get(1);
    assertEquals("$b", eventB.getIdentifier());
    assertEquals("EventB", eventB.getObjectType());
    assertEquals(1, eventB.getConstraint().getDescrs().size());
    assertEquals(1, eventB.getConstraint().getDescrs().size());
    final ExprConstraintDescr fcdB = (ExprConstraintDescr) eventB.getConstraint().getDescrs().get(0);
    assertEquals("this after[1,10] $a || this not after[15,20] $a", fcdB.getExpression());
    final PatternDescr eventC = (PatternDescr) rule.getLhs().getDescrs().get(2);
    assertEquals("$c", eventC.getIdentifier());
    assertEquals("EventC", eventC.getObjectType());
    assertEquals(1, eventC.getConstraint().getDescrs().size());
    final ExprConstraintDescr fcdC = (ExprConstraintDescr) eventC.getConstraint().getDescrs().get(0);
    assertEquals("this finishes $b", fcdC.getExpression());
    final PatternDescr eventD = (PatternDescr) rule.getLhs().getDescrs().get(3);
    assertEquals("$d", eventD.getIdentifier());
    assertEquals("EventD", eventD.getObjectType());
    assertEquals(1, eventD.getConstraint().getDescrs().size());
    final ExprConstraintDescr fcdD = (ExprConstraintDescr) eventD.getConstraint().getDescrs().get(0);
    assertEquals("this not starts $a", fcdD.getExpression());
    final PatternDescr eventE = (PatternDescr) rule.getLhs().getDescrs().get(4);
    assertEquals("$e", eventE.getIdentifier());
    assertEquals("EventE", eventE.getObjectType());
    assertEquals(1, eventE.getConstraint().getDescrs().size());
    ExprConstraintDescr fcdE = (ExprConstraintDescr) eventE.getConstraint().getDescrs().get(0);
    assertEquals("this not before[1, 10] $b || after[1, 10] $c && this after[1, 5] $d", fcdE.getExpression());
}
Also used : 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 7 with ExprConstraintDescr

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

the class RuleParserTest method testEnumeration.

@Test
public void testEnumeration() throws Exception {
    final RuleDescr rule = (RuleDescr) parseResource("rule", "enumeration.drl");
    assertEquals("simple_rule", rule.getName());
    assertEquals(1, rule.getLhs().getDescrs().size());
    final PatternDescr col = (PatternDescr) rule.getLhs().getDescrs().get(0);
    assertEquals("Foo", col.getObjectType());
    assertEquals(1, col.getConstraint().getDescrs().size());
    final ExprConstraintDescr fld = (ExprConstraintDescr) col.getConstraint().getDescrs().get(0);
    assertEquals("bar == Foo.BAR", fld.getExpression());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 8 with ExprConstraintDescr

use of org.drools.compiler.lang.descr.ExprConstraintDescr 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 9 with ExprConstraintDescr

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

the class RuleParserTest method testConstraintOrConnective.

@Test
public void testConstraintOrConnective() throws Exception {
    final String text = "rule X when Person( age < 42 || location==\"atlanta\") then end";
    PatternDescr pattern = (PatternDescr) ((RuleDescr) parse("rule", text)).getLhs().getDescrs().get(0);
    assertEquals(1, pattern.getDescrs().size());
    ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
    assertEquals("age < 42 || location==\"atlanta\"", fcd.getExpression());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 10 with ExprConstraintDescr

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

the class RuleParserTest method testEntryPoint.

@Test
public void testEntryPoint() throws Exception {
    final String text = "rule X when StockTick( symbol==\"ACME\") from entry-point StreamA then end";
    PackageDescr pkg = (PackageDescr) parse("compilationUnit", text);
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    RuleDescr rule = pkg.getRules().get(0);
    PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    assertEquals(1, pattern.getDescrs().size());
    ExprConstraintDescr fcd = (ExprConstraintDescr) pattern.getDescrs().get(0);
    assertEquals("symbol==\"ACME\"", fcd.getExpression());
    assertNotNull(pattern.getSource());
    EntryPointDescr entry = (EntryPointDescr) pattern.getSource();
    assertEquals("StreamA", entry.getEntryId());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) EntryPointDescr(org.drools.compiler.lang.descr.EntryPointDescr) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Aggregations

ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)65 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)57 Test (org.junit.Test)49 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)37 AndDescr (org.drools.compiler.lang.descr.AndDescr)27 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)23 Cheese (org.drools.compiler.Cheese)9 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)9 GlobalDescr (org.drools.compiler.lang.descr.GlobalDescr)5 CompositeObjectSinkAdapterTest (org.drools.core.reteoo.CompositeObjectSinkAdapterTest)5 List (java.util.List)4 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)4 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)4 Element (org.w3c.dom.Element)4 ArrayList (java.util.ArrayList)3 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)3 ConstraintConnectiveDescr (org.drools.compiler.lang.descr.ConstraintConnectiveDescr)3 QueryDescr (org.drools.compiler.lang.descr.QueryDescr)3 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)3 Declaration (org.drools.core.rule.Declaration)3