I have written a few Drools rules for my Seam application and am wondering how I go about unit testing these. Does anybody have any sample code that can show me how to go about doing this?
+2
A:
Add the following code to a unit test (JUnit, TestNG, etc):
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(new InputStreamReader(getClass().getResourceAsStream( "rules.drl")));
PackageBuilderErrors errors = builder.getErrors();
Assert.assertEquals(0, errors.getErrors().length);
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(pkg);
StatefullSession session = ruleBase.newStatefulSession(false);
MyFactObject myFact = new MyFactObject();
session.insert(myFact);
session.fireAllRules();
Aaron Chambers
2009-07-30 13:37:51
now mark it as answered, and you get a shiny badge
skaffman
2009-07-30 13:42:30
I have to wait 2 days before I can do so ;)
Aaron Chambers
2009-07-31 02:56:35