Search in sources :

Example 36 with DrlParser

use of org.drools.drl.parser.DrlParser in project drools by kiegroup.

the class DRLIncompleteCodeTest method testIncompleteCode7.

@Test
public void testIncompleteCode7() throws DroolsParserException, RecognitionException {
    String input = "package a.b.c imrt 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 37 with DrlParser

use of org.drools.drl.parser.DrlParser in project drools by kiegroup.

the class DRLIncompleteCodeTest method testIncompleteCode8.

@Test
public void testIncompleteCode8() throws DroolsParserException, RecognitionException {
    String input = "package a.b.c import a.1111.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);
    System.out.println(parser.getErrors());
    assertEquals("a.b.c", descr.getNamespace());
    // FIXME: assertEquals(2, descr.getRules().size());
    assertEquals(true, parser.hasErrors());
}
Also used : DrlParser(org.drools.drl.parser.DrlParser) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Example 38 with DrlParser

use of org.drools.drl.parser.DrlParser in project drools by kiegroup.

the class DRLIncompleteCodeTest method testIncompleteCode13.

@Test
public void testIncompleteCode13() throws DroolsParserException, RecognitionException {
    String input = "package com.sample " + "import com.sample.DroolsTest.Message; " + "rule \"Hello World\"" + "  when " + "  then" + "     \\\" " + "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 39 with DrlParser

use of org.drools.drl.parser.DrlParser in project drools by kiegroup.

the class DRLIncompleteCodeTest method testIncompleteCode11.

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

Example 40 with DrlParser

use of org.drools.drl.parser.DrlParser in project drools by kiegroup.

the class DRLDumperTest method testDumpers.

@Test
public void testDumpers() throws Exception {
    final DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
    final Resource resource = new InputStreamResource(getClass().getResourceAsStream("drl/test_Dumpers.drl"));
    final PackageDescr pkg = parser.parse(resource);
    if (parser.hasErrors()) {
        for (final DroolsError error : parser.getErrors()) {
            logger.warn(error.toString());
        }
        fail(parser.getErrors().toString());
    }
    final Resource descrResource = KieServices.Factory.get().getResources().newDescrResource(pkg);
    descrResource.setSourcePath(TestConstants.TEST_RESOURCES_FOLDER + "test_Dumpers.descr");
    KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, descrResource);
    KieSession ksession = kbase.newKieSession();
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    final Cheese brie = new Cheese("brie", 12);
    ksession.insert(brie);
    ksession.fireAllRules();
    assertEquals(3, list.size());
    assertEquals("3 1", list.get(0));
    assertEquals("MAIN", list.get(1));
    assertEquals("1 1", list.get(2));
    // ---------------------------
    final DrlDumper drlDumper = new DrlDumper();
    final String drlResult = drlDumper.dump(pkg);
    System.out.println(drlResult);
    kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drlResult);
    ksession = kbase.newKieSession();
    list = new ArrayList();
    ksession.setGlobal("list", list);
    ksession.insert(brie);
    ksession.fireAllRules();
    assertEquals(3, list.size());
    assertEquals("3 1", list.get(0));
    assertEquals("MAIN", list.get(1));
    assertEquals("1 1", list.get(2));
}
Also used : DroolsError(org.drools.drl.parser.DroolsError) KieBase(org.kie.api.KieBase) InputStreamResource(org.drools.core.io.impl.InputStreamResource) Resource(org.kie.api.io.Resource) ArrayList(java.util.ArrayList) DrlParser(org.drools.drl.parser.DrlParser) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) Cheese(org.drools.mvel.compiler.Cheese) PackageDescr(org.drools.drl.ast.descr.PackageDescr) DrlDumper(org.drools.mvel.DrlDumper) InputStreamResource(org.drools.core.io.impl.InputStreamResource) Test(org.junit.Test)

Aggregations

DrlParser (org.drools.drl.parser.DrlParser)41 PackageDescr (org.drools.drl.ast.descr.PackageDescr)38 Test (org.junit.Test)32 RuleDescr (org.drools.drl.ast.descr.RuleDescr)9 InputStreamReader (java.io.InputStreamReader)8 StringReader (java.io.StringReader)8 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)4 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)4 ParserError (org.drools.drl.parser.ParserError)4 DrlDumper (org.drools.mvel.DrlDumper)4 Reader (java.io.Reader)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)3 PatternDescr (org.drools.drl.ast.descr.PatternDescr)3 Ignore (org.junit.Ignore)3 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)2 InputStreamResource (org.drools.core.io.impl.InputStreamResource)2 AttributeDescr (org.drools.drl.ast.descr.AttributeDescr)2 MVELConsequence (org.drools.mvel.expr.MVELConsequence)2