public void testXLSDecisionTable() throws Exception { RulesRepository repo = getRepo(); // first, setup the package correctly: PackageItem pkg = repo.createPackage("testXLSDecisionTable", ""); ServiceImplementation.updateDroolsHeader( "import org.acme.insurance.Policy\n import org.acme.insurance.Driver", pkg); repo.save(); InputStream xls = this.getClass().getResourceAsStream("/SampleDecisionTable.xls"); assertNotNull(xls); AssetItem asset = pkg.addAsset("MyDT", ""); asset.updateFormat(AssetFormats.DECISION_SPREADSHEET_XLS); asset.updateBinaryContentAttachment(xls); asset.checkin(""); ContentPackageAssembler asm = new ContentPackageAssembler(pkg); if (asm.hasErrors()) { System.err.println(asm.getErrors().get(0).errorReport); System.err.println(asm.getDRL()); } assertFalse(asm.hasErrors()); String drl = asm.getDRL(); assertContains("policy: Policy", drl); Package bin = asm.getBinaryPackage(); RuleBase rb = RuleBaseFactory.newRuleBase(); rb.addPackage(bin); WorkingMemory wm = rb.newStatefulSession(); // now create some test data Driver driver = new Driver(); Policy policy = new Policy(); wm.insert(driver); wm.insert(policy); wm.fireAllRules(); assertEquals(120, policy.getBasePrice()); asset.updateBinaryContentAttachment( this.getClass().getResourceAsStream("/SampleDecisionTable_WithError.xls")); asset.checkin(""); asm = new ContentPackageAssembler(pkg); assertTrue(asm.hasErrors()); assertEquals(asset.getName(), asm.getErrors().get(0).itemInError.getName()); asm = new ContentPackageAssembler(pkg, false); assertFalse(asm.hasErrors()); drl = asm.getDRL(); assertNotNull(drl); assertContains("Driverx", drl); }
public void testSimplePackageWithDeclaredTypes() throws Exception { RulesRepository repo = getRepo(); PackageItem pkg = repo.createPackage("testSimplePackageWithDeclaredTypes", ""); AssetItem rule1 = pkg.addAsset("rule_1", ""); rule1.updateFormat(AssetFormats.DRL); rule1.updateContent("rule 'rule1' \n when Album() \n then System.err.println(42); \n end"); rule1.checkin(""); AssetItem model = pkg.addAsset("model", "qed"); model.updateFormat(AssetFormats.DRL_MODEL); model.updateContent("declare Album\n genre: String \n end"); model.checkin(""); repo.save(); ContentPackageAssembler asm = new ContentPackageAssembler(pkg); assertFalse(asm.hasErrors()); assertNotNull(asm.getBinaryPackage()); Package bin = asm.getBinaryPackage(); assertEquals(pkg.getName(), bin.getName()); assertTrue(bin.isValid()); asm = new ContentPackageAssembler(pkg, false); String drl = asm.getDRL(); assertTrue(drl.indexOf("declare Album") > -1); }
public void testShowSource() throws Exception { RulesRepository repo = getRepo(); // first, setup the package correctly: PackageItem pkg = repo.createPackage("testShowSource", ""); ServiceImplementation.updateDroolsHeader( "import com.billasurf.Board\n global com.billasurf.Person customer", pkg); repo.save(); AssetItem func = pkg.addAsset("func", ""); func.updateFormat(AssetFormats.FUNCTION); func.updateContent("function void foo() { System.out.println(42); }"); func.checkin(""); AssetItem dsl = pkg.addAsset("myDSL", ""); dsl.updateFormat(AssetFormats.DSL); dsl.updateContent("[then]call a func=foo();\n[when]foo=FooBarBaz()"); dsl.checkin(""); AssetItem rule = pkg.addAsset("rule1", ""); rule.updateFormat(AssetFormats.DRL); rule.updateContent("rule 'foo' when Goo() then end"); rule.checkin(""); AssetItem rule2 = pkg.addAsset("rule2", ""); rule2.updateFormat(AssetFormats.DSL_TEMPLATE_RULE); rule2.updateContent("when \n foo \n then \n call a func"); rule2.checkin(""); ContentPackageAssembler asm = new ContentPackageAssembler(pkg, false, null); String drl = asm.getDRL(); assertNotNull(drl); assertContains("import com.billasurf.Board\n global com.billasurf.Person customer", drl); assertContains("package testShowSource", drl); assertContains("function void foo() { System.out.println(42); }", drl); assertContains("foo();", drl); assertContains("FooBarBaz()", drl); assertContains("rule 'foo' when Goo() then end", drl); }