Search in sources :

Example 96 with PackageDescr

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

the class DRLIncompleteCodeTest method testIncompleteCode2.

@Test
public void testIncompleteCode2() throws DroolsParserException, RecognitionException {
    String input = "rule MyRule when Class ( property memberOf collection ";
    DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
    PackageDescr descr = parser.parse(true, input);
    assertNotNull(descr);
    assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, getLastIntegerValue(parser.getEditorSentences().get(0).getContent()));
}
Also used : DrlParser(org.drools.drl.parser.DrlParser) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Example 97 with PackageDescr

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

the class DRLIncompleteCodeTest method testIncompleteCode5.

@Test
public void testIncompleteCode5() throws DroolsParserException, RecognitionException {
    String input = "package a.b.c import a.b.c.*" + " rule MyRule when Class ( property memberOf collection ) then end " + " query MyQuery Class ( property memberOf collection ) end ";
    DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
    PackageDescr descr = parser.parse(true, input);
    assertNotNull(descr);
}
Also used : DrlParser(org.drools.drl.parser.DrlParser) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Example 98 with PackageDescr

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

the class DRLIncompleteCodeTest method testIncompleteCode6.

@Test
public void testIncompleteCode6() throws DroolsParserException, RecognitionException {
    String input = "packe 1111.111 import a.b.c.*" + " rule MyRule when Class ( property memberOf collection ) then end " + " query MyQuery Class ( property memberOf collection ) end ";
    DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
    PackageDescr descr = parser.parse(true, input);
    assertNotNull(descr);
}
Also used : DrlParser(org.drools.drl.parser.DrlParser) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Example 99 with PackageDescr

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

the class RuleParserTest method testAccumulateMultiPattern.

@Test
public void testAccumulateMultiPattern() throws Exception {
    final PackageDescr pkg = (PackageDescr) parseResource("compilationUnit", "accumulate_multi_pattern.drl");
    assertEquals(1, pkg.getRules().size());
    final RuleDescr rule = (RuleDescr) pkg.getRules().get(0);
    assertEquals(1, rule.getLhs().getDescrs().size());
    final PatternDescr outPattern = (PatternDescr) rule.getLhs().getDescrs().get(0);
    final AccumulateDescr accum = (AccumulateDescr) outPattern.getSource();
    assertEqualsIgnoreWhitespace("$counter", outPattern.getIdentifier());
    assertEqualsIgnoreWhitespace("int x = 0 ;", accum.getInitCode());
    assertEqualsIgnoreWhitespace("x++;", accum.getActionCode());
    assertEqualsIgnoreWhitespace("new Integer(x)", accum.getResultCode());
    final AndDescr and = (AndDescr) accum.getInput();
    assertEquals(2, and.getDescrs().size());
    final PatternDescr person = (PatternDescr) and.getDescrs().get(0);
    final PatternDescr cheese = (PatternDescr) and.getDescrs().get(1);
    assertEquals("Person", person.getObjectType());
    assertEquals("Cheese", cheese.getObjectType());
}
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) AccumulateDescr(org.drools.drl.ast.descr.AccumulateDescr) Test(org.junit.Test)

Example 100 with PackageDescr

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

the class DRLIncompleteCodeTest method testIncompleteCode1.

@Test
@Ignore
public void testIncompleteCode1() throws DroolsParserException, RecognitionException {
    String input = "package a.b.c import a.b.c.* rule MyRule when Class ( property memberOf collexction ";
    DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
    PackageDescr descr = parser.parse(true, input);
    System.out.println(parser.getErrors());
    assertNotNull(descr);
    assertEquals("a.b.c", descr.getNamespace());
    assertEquals("a.b.c.*", descr.getImports().get(0).getTarget());
    assertEquals(Location.LOCATION_LHS_INSIDE_CONDITION_END, getLastIntegerValue(parser.getEditorSentences().get(2).getContent()));
}
Also used : DrlParser(org.drools.drl.parser.DrlParser) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

PackageDescr (org.drools.drl.ast.descr.PackageDescr)262 Test (org.junit.Test)210 RuleDescr (org.drools.drl.ast.descr.RuleDescr)104 PatternDescr (org.drools.drl.ast.descr.PatternDescr)85 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)52 AndDescr (org.drools.drl.ast.descr.AndDescr)39 DrlParser (org.drools.drl.parser.DrlParser)39 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)25 InputStreamReader (java.io.InputStreamReader)23 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)23 ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)23 KieSession (org.kie.api.runtime.KieSession)19 List (java.util.List)18 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)18 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)17 GlobalDescr (org.drools.drl.ast.descr.GlobalDescr)17 KiePackage (org.kie.api.definition.KiePackage)17 DrlDumper (org.drools.mvel.DrlDumper)16 Cheese (org.drools.mvel.compiler.Cheese)16 AccumulateDescr (org.drools.drl.ast.descr.AccumulateDescr)15