Search in sources :

Example 11 with FromDescr

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

the class RuleParserTest method testComplexChainedAcessor.

@Test
public void testComplexChainedAcessor() throws Exception {
    final RuleDescr rule = (RuleDescr) parseResource("rule", "test_ComplexChainedCallWithFrom.drl");
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final FromDescr from = (FromDescr) pattern.getSource();
    final MVELExprDescr accessor = (MVELExprDescr) from.getDataSource();
    assertEquals("doIt1( foo,bar,42,\"hello\",[ a : \"b\"], [a, \"b\", 42] ).doIt2(bar, [a, \"b\", 42]).field[\"key\"]", accessor.getExpression());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) FromDescr(org.drools.compiler.lang.descr.FromDescr) MVELExprDescr(org.drools.compiler.lang.descr.MVELExprDescr) Test(org.junit.Test)

Example 12 with FromDescr

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

the class RuleParserTest method testSimpleFunctionCallWithFrom.

@Test
public void testSimpleFunctionCallWithFrom() throws Exception {
    final RuleDescr rule = (RuleDescr) parseResource("rule", "test_SimpleFunctionCallWithFrom.drl");
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final FromDescr from = (FromDescr) pattern.getSource();
    final MVELExprDescr func = (MVELExprDescr) from.getDataSource();
    assertEquals("doIt( foo,bar,42,\"hello\",[ a : \"b\", \"something\" : 42, \"a\" : foo, x : [x:y]],\"end\", [a, \"b\", 42] )", func.getExpression());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) FromDescr(org.drools.compiler.lang.descr.FromDescr) MVELExprDescr(org.drools.compiler.lang.descr.MVELExprDescr) Test(org.junit.Test)

Example 13 with FromDescr

use of org.drools.compiler.lang.descr.FromDescr 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)

Example 14 with FromDescr

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

the class RuleParserTest method testSimpleAccessorAndArgWithFrom.

@Test
public void testSimpleAccessorAndArgWithFrom() throws Exception {
    final RuleDescr rule = (RuleDescr) parseResource("rule", "test_SimpleAccessorArgWithFrom.drl");
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final FromDescr from = (FromDescr) pattern.getSource();
    final MVELExprDescr accessor = (MVELExprDescr) from.getDataSource();
    assertEquals("something.doIt[\"key\"]", accessor.getExpression());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) FromDescr(org.drools.compiler.lang.descr.FromDescr) MVELExprDescr(org.drools.compiler.lang.descr.MVELExprDescr) Test(org.junit.Test)

Example 15 with FromDescr

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

the class RuleParserTest method testSimpleAccessorWithFrom.

@Test
public void testSimpleAccessorWithFrom() throws Exception {
    final RuleDescr rule = (RuleDescr) parseResource("rule", "test_SimpleAccessorWithFrom.drl");
    assertFalse(parser.getErrors().toString(), parser.hasErrors());
    final PatternDescr pattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final FromDescr from = (FromDescr) pattern.getSource();
    final MVELExprDescr accessor = (MVELExprDescr) from.getDataSource();
    assertEquals("something.doIt", accessor.getExpression());
}
Also used : PatternDescr(org.drools.compiler.lang.descr.PatternDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr) FromDescr(org.drools.compiler.lang.descr.FromDescr) MVELExprDescr(org.drools.compiler.lang.descr.MVELExprDescr) Test(org.junit.Test)

Aggregations

FromDescr (org.drools.compiler.lang.descr.FromDescr)15 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)11 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)11 Test (org.junit.Test)11 MVELExprDescr (org.drools.compiler.lang.descr.MVELExprDescr)7 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)6 NotDescr (org.drools.compiler.lang.descr.NotDescr)2 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AnalysisResult (org.drools.compiler.compiler.AnalysisResult)1 BoundIdentifiers (org.drools.compiler.compiler.BoundIdentifiers)1 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)1 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)1 AccumulateDescr (org.drools.compiler.lang.descr.AccumulateDescr)1 BaseDescr (org.drools.compiler.lang.descr.BaseDescr)1 CollectDescr (org.drools.compiler.lang.descr.CollectDescr)1 EntryPointDescr (org.drools.compiler.lang.descr.EntryPointDescr)1 ForallDescr (org.drools.compiler.lang.descr.ForallDescr)1 MVELDataProvider (org.drools.core.base.dataproviders.MVELDataProvider)1