Search in sources :

Example 21 with ExprConstraintDescr

use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testBasicBinding.

// @Test public void testExpanderUnExpandableErrorLines() throws Exception {
// 
// //stubb expander
// final ExpanderResolver res = new ExpanderResolver() {
// public Expander get(String name,
// String config) {
// return new Expander() {
// public String expand(String scope,
// String pattern) {
// if ( pattern.startsWith( "Good" ) ) {
// return pattern;
// } else {
// throw new IllegalArgumentException( "whoops" );
// }
// 
// }
// };
// }
// };
// 
// final DRLParser parser = parseResource( "expander_line_errors.dslr" );
// parser.setExpanderResolver( res );
// parser.compilationUnit();
// assertTrue( parser.hasErrors() );
// 
// final List messages = parser.getErrorMessages();
// assertEquals( messages.size(),
// parser.getErrors().size() );
// 
// assertEquals( 4,
// parser.getErrors().size() );
// assertEquals( ExpanderException.class,
// parser.getErrors().get( 0 ).getClass() );
// assertEquals( 8,
// ((RecognitionException) parser.getErrors().get( 0 )).line );
// assertEquals( 10,
// ((RecognitionException) parser.getErrors().get( 1 )).line );
// assertEquals( 12,
// ((RecognitionException) parser.getErrors().get( 2 )).line );
// assertEquals( 13,
// ((RecognitionException) parser.getErrors().get( 3 )).line );
// 
// final PackageDescr pack = parser.getPackageDescr();
// assertNotNull( pack );
// 
// final ExpanderException ex = (ExpanderException) parser.getErrors().get(
// 0 );
// assertTrue( ex.getMessage().indexOf( "whoops" ) > -1 );
// 
// }
@Test
public void testBasicBinding() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "basic_binding.drl");
    final RuleDescr ruleDescr = (RuleDescr) pkg.getRules().get(0);
    final AndDescr lhs = ruleDescr.getLhs();
    assertEquals(1, lhs.getDescrs().size());
    final PatternDescr cheese = (PatternDescr) lhs.getDescrs().get(0);
    assertEquals("Cheese", cheese.getObjectType());
    assertEquals(1, cheese.getConstraint().getDescrs().size());
    final ExprConstraintDescr fieldBinding = (ExprConstraintDescr) cheese.getDescrs().get(0);
    assertEquals("$type:type", fieldBinding.getExpression());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) AndDescr(org.drools.drl.ast.descr.AndDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 22 with ExprConstraintDescr

use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testEntryPoint2.

@Test
public void testEntryPoint2() 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.drl.ast.descr.PatternDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) EntryPointDescr(org.drools.drl.ast.descr.EntryPointDescr) PackageDescr(org.drools.drl.ast.descr.PackageDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 23 with ExprConstraintDescr

use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testRestrictions.

@Test
public void testRestrictions() throws Exception {
    final String text = "rule X when Foo( bar > 1 || == 1 ) then end\n";
    AndDescr descrs = (AndDescr) ((RuleDescr) parse("rule", text)).getLhs();
    assertEquals(1, descrs.getDescrs().size());
    PatternDescr pat = (PatternDescr) descrs.getDescrs().get(0);
    ExprConstraintDescr fieldConstr = (ExprConstraintDescr) pat.getConstraint().getDescrs().get(0);
    assertEquals("bar > 1 || == 1", fieldConstr.getExpression());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) AndDescr(org.drools.drl.ast.descr.AndDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 24 with ExprConstraintDescr

use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testMemberof.

@Test
public void testMemberof() throws Exception {
    final String text = "rule X when Country( $cities : city )\nPerson( city memberOf $cities )\n then end";
    AndDescr descrs = ((RuleDescr) parse("rule", text)).getLhs();
    assertEquals(2, descrs.getDescrs().size());
    PatternDescr pat = (PatternDescr) descrs.getDescrs().get(1);
    ExprConstraintDescr fieldConstr = (ExprConstraintDescr) pat.getConstraint().getDescrs().get(0);
    assertEquals("city memberOf $cities", fieldConstr.getExpression());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) AndDescr(org.drools.drl.ast.descr.AndDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Example 25 with ExprConstraintDescr

use of org.drools.drl.ast.descr.ExprConstraintDescr in project drools by kiegroup.

the class RuleParserTest method testNotMemberof.

@Test
public void testNotMemberof() throws Exception {
    final String text = "rule X when Country( $cities : city )\nPerson( city not memberOf $cities ) then end\n";
    AndDescr descrs = ((RuleDescr) parse("rule", text)).getLhs();
    assertEquals(2, descrs.getDescrs().size());
    PatternDescr pat = (PatternDescr) descrs.getDescrs().get(1);
    ExprConstraintDescr fieldConstr = (ExprConstraintDescr) pat.getConstraint().getDescrs().get(0);
    assertEquals("city not memberOf $cities", fieldConstr.getExpression());
}
Also used : PatternDescr(org.drools.drl.ast.descr.PatternDescr) AndDescr(org.drools.drl.ast.descr.AndDescr) RuleDescr(org.drools.drl.ast.descr.RuleDescr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) Test(org.junit.Test)

Aggregations

ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)75 PatternDescr (org.drools.drl.ast.descr.PatternDescr)65 Test (org.junit.Test)56 RuleDescr (org.drools.drl.ast.descr.RuleDescr)37 AndDescr (org.drools.drl.ast.descr.AndDescr)34 PackageDescr (org.drools.drl.ast.descr.PackageDescr)23 BaseDescr (org.drools.drl.ast.descr.BaseDescr)11 BindingDescr (org.drools.drl.ast.descr.BindingDescr)10 Cheese (org.drools.mvel.compiler.Cheese)9 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)8 GlobalDescr (org.drools.drl.ast.descr.GlobalDescr)5 NotDescr (org.drools.drl.ast.descr.NotDescr)5 Declaration (org.drools.core.rule.Declaration)4 KiePMMLFieldOperatorValue (org.kie.pmml.models.drools.ast.KiePMMLFieldOperatorValue)4 KiePMMLOperatorValue (org.kie.pmml.models.drools.tuples.KiePMMLOperatorValue)4 Element (org.w3c.dom.Element)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)3 PredicateConstraint (org.drools.core.rule.PredicateConstraint)3