use of org.drools.drl.ast.descr.PackageDescr 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)"));
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class DescrBuilderTest method testPackageImports.
@Test
public void testPackageImports() {
PackageDescr pkg = DescrFactory.newPackage().name("org.drools").newImport().target("java.util.List").end().newImport().target("org.drools.examples.*").end().getDescr();
assertEquals(2, pkg.getImports().size());
assertEquals("java.util.List", pkg.getImports().get(0).getTarget());
assertEquals("org.drools.examples.*", pkg.getImports().get(1).getTarget());
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class DescrBuilderTest method testNamedConsequence.
@Test
public void testNamedConsequence() {
PackageDescr pkg = DescrFactory.newPackage().name("org.drools.mvel.compiler").newRule().name("test").lhs().pattern("Cheese").constraint("type == \"stilton\"").end().namedConsequence().name("c1").end().pattern("Cheese").constraint("type == \"cheddar\"").end().end().rhs("// do something").namedRhs("c1", "// do something else").end().getDescr();
assertEquals(1, pkg.getRules().size());
KiePackage kpkg = compilePkgDescr(pkg);
assertEquals("org.drools.mvel.compiler", kpkg.getName());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(Collections.singletonList(kpkg));
KieSession ksession = kbase.newKieSession();
Cheese stilton = new Cheese("stilton", 5);
Cheese cheddar = new Cheese("cheddar", 7);
Cheese brie = new Cheese("brie", 5);
ksession.insert(stilton);
ksession.insert(cheddar);
ksession.insert(brie);
int rules = ksession.fireAllRules();
assertEquals(2, rules);
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class DescrBuilderTest method testFunctions.
@Test
public void testFunctions() {
PackageDescr pkg = DescrFactory.newPackage().name("org.drools").newFunctionImport().target("java.lang.Math.max").end().newFunction().returnType("long").name("myMax").parameter("long", "v1").parameter("long", "v2").body("return max(v1, v2);").end().newRule().name("test").lhs().eval().constraint("myMax(5, 10) == 10").end().end().rhs("// do something").end().getDescr();
assertEquals(1, pkg.getFunctionImports().size());
assertEquals(1, pkg.getFunctions().size());
assertEquals(1, pkg.getRules().size());
KiePackage kpkg = compilePkgDescr(pkg);
assertEquals("org.drools", kpkg.getName());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(Collections.singletonList(kpkg));
KieSession ksession = kbase.newKieSession();
int rules = ksession.fireAllRules();
assertEquals(1, rules);
}
use of org.drools.drl.ast.descr.PackageDescr in project drools by kiegroup.
the class DescrBuilderTest method testRuleRHSComment.
@Test
public void testRuleRHSComment() throws InstantiationException, IllegalAccessException {
PackageDescr pkg = DescrFactory.newPackage().name("org.drools.mvel.compiler").newRule().name("r1").lhs().pattern("StockTick").constraint("company == \"RHT\"").end().end().rhs("// some comment").end().getDescr();
KiePackage kpkg = compilePkgDescr(pkg);
assertEquals("org.drools.mvel.compiler", kpkg.getName());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(Collections.singletonList(kpkg));
KieSession ksession = kbase.newKieSession();
ksession.insert(new StockTick(1, "RHT", 80, 1));
int rules = ksession.fireAllRules();
assertEquals(1, rules);
}
Aggregations