Search in sources :

Example 31 with DrlParser

use of org.drools.compiler.compiler.DrlParser in project drools by kiegroup.

the class DumperTestHelper method dump.

public static String dump(String filename) throws Exception {
    DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
    final PackageDescr pkgOriginal = parser.parse(new InputStreamReader(DumperTestHelper.class.getResourceAsStream(filename)));
    final DrlDumper dumper = new DrlDumper();
    return dumper.dump(pkgOriginal);
}
Also used : InputStreamReader(java.io.InputStreamReader) DrlParser(org.drools.compiler.compiler.DrlParser) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) DrlDumper(org.drools.compiler.lang.DrlDumper)

Example 32 with DrlParser

use of org.drools.compiler.compiler.DrlParser in project drools by kiegroup.

the class DumperTest method testRoundTripDRLAccumulate.

@Test
public void testRoundTripDRLAccumulate() throws Exception {
    // RHDM-254
    String drl = "package org.test\n" + "\n" + "rule \"last flown date\"\n" + "when\n" + "    $customer : Profile( $ceid : id )\n" + "    accumulate(\n" + "    Flight( status == \"Flown\", $dptDate: departureDate.time ) from $customer.flights,\n" + "        $cnt : count( $dptDate );\n" + "        $cnt > 0 )\n" + "then\n" + "end";
    DrlParser parser = new DrlParser(LanguageLevelOption.DRL6);
    final PackageDescr pkgOriginal = parser.parse(false, drl);
    final DrlDumper dumper = new DrlDumper();
    String out = dumper.dump(pkgOriginal);
    Assertions.assertThat(drl).isEqualToIgnoringWhitespace(out);
}
Also used : DrlParser(org.drools.compiler.compiler.DrlParser) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) DrlDumper(org.drools.compiler.lang.DrlDumper) Test(org.junit.Test)

Example 33 with DrlParser

use of org.drools.compiler.compiler.DrlParser in project drools by kiegroup.

the class FromTest method testFromWithNewConstructor.

@Test
public void testFromWithNewConstructor() throws Exception {
    final DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
    final PackageDescr descr = parser.parse(new InputStreamReader(getClass().getResourceAsStream("test_FromWithNewConstructor.drl")));
    final Collection<KiePackage> pkgs = loadKnowledgePackages(descr);
    SerializationHelper.serializeObject(pkgs);
}
Also used : InputStreamReader(java.io.InputStreamReader) KiePackage(org.kie.api.definition.KiePackage) DrlParser(org.drools.compiler.compiler.DrlParser) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 34 with DrlParser

use of org.drools.compiler.compiler.DrlParser in project drools by kiegroup.

the class DRLIncompleteCodeTest method testIncompleteCode4.

@Test
public void testIncompleteCode4() throws DroolsParserException, RecognitionException {
    String input = "package a.b.c import a.b.c.*" + " rule MyRule when Class ( property == collection ) then end " + " query MyQuery Class ( property == collection ) end ";
    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());
    assertNotNull(descr);
    assertEquals("MyQuery", descr.getRules().get(1).getName());
}
Also used : DrlParser(org.drools.compiler.compiler.DrlParser) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Test(org.junit.Test)

Example 35 with DrlParser

use of org.drools.compiler.compiler.DrlParser in project drools by kiegroup.

the class DRLIncompleteCodeTest method testIncompleteCode9.

@Test
@Ignore
public void testIncompleteCode9() throws DroolsParserException, RecognitionException {
    String input = "package a.b.c import a.b.c.*" + " rule MyRule xxxxx 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);
    assertEquals("a.b.c", descr.getNamespace());
    assertEquals("a.b.c.*", descr.getImports().get(0).getTarget());
    assertEquals(1, descr.getRules().size());
    assertEquals("MyQuery", descr.getRules().get(0).getName());
}
Also used : DrlParser(org.drools.compiler.compiler.DrlParser) PackageDescr(org.drools.compiler.lang.descr.PackageDescr) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

DrlParser (org.drools.compiler.compiler.DrlParser)44 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)43 Test (org.junit.Test)32 InputStreamReader (java.io.InputStreamReader)10 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)9 StringReader (java.io.StringReader)8 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)6 ArrayList (java.util.ArrayList)5 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)5 ParserError (org.drools.compiler.compiler.ParserError)5 DrlDumper (org.drools.compiler.lang.DrlDumper)4 Reader (java.io.Reader)3 List (java.util.List)3 DroolsParserException (org.drools.compiler.compiler.DroolsParserException)3 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)3 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)3 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)3 Ignore (org.junit.Ignore)3 AttributeDescr (org.drools.compiler.lang.descr.AttributeDescr)2 MVELConsequence (org.drools.core.base.mvel.MVELConsequence)2