Search in sources :

Example 1 with DrlDumper

use of org.drools.mvel.DrlDumper in project drools by kiegroup.

the class DumperTest method testAccumulateWithoutConstraint.

@Test
public void testAccumulateWithoutConstraint() throws Exception {
    // DROOLS-5872
    String expectedDrl = "package example \n" + "\n" + "import java.math.BigDecimal\n" + "\n" + "rule \"Test Rule\"\n" + "when\n" + "    accumulate(     \n" + "    $target : example.RuleTest.Fact(  )  ,\n" + "        $cnt : count(  ) \n" + "         ) \n" + "then\n" + "System.out.println($cnt);\n" + "\n" + "end";
    PackageDescr packageDescr = DescrFactory.newPackage().name("example").newImport().target("java.math.BigDecimal").end().newRule().name("Test Rule").lhs().accumulate().source().pattern().type("example.RuleTest.Fact").id("$target", false).end().end().function("count", "$cnt", false).end().end().rhs("System.out.println($cnt);").end().end().getDescr();
    String drl = new DrlDumper().dump(packageDescr);
    Assertions.assertThat(drl).isEqualToIgnoringWhitespace(expectedDrl);
}
Also used : PackageDescr(org.drools.drl.ast.descr.PackageDescr) DrlDumper(org.drools.mvel.DrlDumper) Test(org.junit.Test)

Example 2 with DrlDumper

use of org.drools.mvel.DrlDumper in project drools by kiegroup.

the class XmlPackageReaderTest method testParseCollect.

@Test
public void testParseCollect() throws Exception {
    final XmlPackageReader xmlPackageReader = getXmReader();
    xmlPackageReader.read(new InputStreamReader(getClass().getResourceAsStream("test_ParseCollect.xml")));
    final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
    String expected = StringUtils.readFileAsString(new InputStreamReader(getClass().getResourceAsStream("test_ParseCollect.drl")));
    String expectedWithoutHeader = removeLicenseHeader(expected);
    String actual = new DrlDumper().dump(packageDescr);
    Assertions.assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual);
}
Also used : InputStreamReader(java.io.InputStreamReader) PackageDescr(org.drools.drl.ast.descr.PackageDescr) DrlDumper(org.drools.mvel.DrlDumper) XmlPackageReader(org.drools.compiler.compiler.xml.XmlPackageReader) Test(org.junit.Test)

Example 3 with DrlDumper

use of org.drools.mvel.DrlDumper in project drools by kiegroup.

the class DescrBuilderTest method testDumperTimer.

@Test
public void testDumperTimer() {
    PackageDescr pkg = DescrFactory.newPackage().name("org.test").newRule().name("org.test").attribute("timer").value("cron:0/5 * * * * ?").end().lhs().end().rhs("").end().end().getDescr();
    String drl = new DrlDumper().dump(pkg);
    assertTrue(drl.contains("timer (cron:0/5 * * * * ?)"));
}
Also used : PackageDescr(org.drools.drl.ast.descr.PackageDescr) DrlDumper(org.drools.mvel.DrlDumper) Test(org.junit.Test)

Example 4 with DrlDumper

use of org.drools.mvel.DrlDumper in project drools by kiegroup.

the class DescrBuilderTest method testDumperPositional.

@Test
public void testDumperPositional() {
    PackageDescr pkg = DescrFactory.newPackage().name("org.test").newRule().name("org.test").lhs().pattern().type("Integer").constraint("this > 10", true).constraint("this > 11", true).constraint("this > 12", false).constraint("this > 13", false).end().end().rhs("").end().end().getDescr();
    String drl = new DrlDumper().dump(pkg);
    assertTrue(drl.contains("Integer( this > 10, this > 11; this > 12, this > 13 )"));
}
Also used : PackageDescr(org.drools.drl.ast.descr.PackageDescr) DrlDumper(org.drools.mvel.DrlDumper) Test(org.junit.Test)

Example 5 with DrlDumper

use of org.drools.mvel.DrlDumper in project drools by kiegroup.

the class DescrBuilderTest method testDumperDuration.

@Test
public void testDumperDuration() {
    PackageDescr pkg = DescrFactory.newPackage().name("org.test").newRule().name("org.test").attribute("duration").value("int: 0 3600000; repeat-limit = 6").end().lhs().end().rhs("").end().end().getDescr();
    String drl = new DrlDumper().dump(pkg);
    assertTrue(drl.contains("duration (int: 0 3600000; repeat-limit = 6)"));
}
Also used : PackageDescr(org.drools.drl.ast.descr.PackageDescr) DrlDumper(org.drools.mvel.DrlDumper) Test(org.junit.Test)

Aggregations

DrlDumper (org.drools.mvel.DrlDumper)19 PackageDescr (org.drools.drl.ast.descr.PackageDescr)16 Test (org.junit.Test)16 InputStreamReader (java.io.InputStreamReader)5 KieSession (org.kie.api.runtime.KieSession)5 PackageDescrBuilder (org.drools.drl.ast.dsl.PackageDescrBuilder)4 DrlParser (org.drools.drl.parser.DrlParser)4 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)4 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)3 KiePackage (org.kie.api.definition.KiePackage)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)2 InputStreamResource (org.drools.core.io.impl.InputStreamResource)2 Cheese (org.drools.mvel.compiler.Cheese)2 KieBase (org.kie.api.KieBase)2 EntryPoint (org.kie.api.runtime.rule.EntryPoint)2 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1