public void testFromInsideNotAndExists() throws Exception { final Reader reader = new InputStreamReader(getClass().getResourceAsStream("test_FromInsideNotAndExists.drl")); RuleBase ruleBase = loadRuleBase(reader); StatefulSession workingMemory = ruleBase.newStatefulSession(); final List list = new ArrayList(); workingMemory.setGlobal("results", list); final Cheese cheddar = new Cheese("cheddar", 7); final Cheese provolone = new Cheese("provolone", 5); final Cheesery cheesery = new Cheesery(); cheesery.addCheese(cheddar); cheesery.addCheese(provolone); FactHandle handle = workingMemory.insert(cheesery); workingMemory.fireAllRules(); assertEquals(0, list.size()); cheesery.addCheese(new Cheese("stilton", 10)); cheesery.removeCheese(cheddar); workingMemory.update(handle, cheesery); workingMemory.fireAllRules(); assertEquals(2, list.size()); }
public void testCollectWithNestedFromWithParams() throws Exception { RuleBase ruleBase = loadRuleBase( new InputStreamReader( getClass().getResourceAsStream("test_CollectWithNestedFrom.drl"))); StatefulSession workingMemory = ruleBase.newStatefulSession(); List results = new ArrayList(); workingMemory.setGlobal("results", results); final Person bob = new Person("bob", "stilton"); Cheesery cheesery = new Cheesery(); cheesery.addCheese(new Cheese("stilton", 10)); cheesery.addCheese(new Cheese("brie", 20)); cheesery.addCheese(new Cheese("muzzarela", 8)); cheesery.addCheese(new Cheese("stilton", 5)); cheesery.addCheese(new Cheese("provolone", 1)); workingMemory.insert(bob); workingMemory.insert(cheesery); ruleBase = serializeRuleBase(ruleBase); workingMemory = serializeWorkingMemory(ruleBase, workingMemory); results = (List) workingMemory.getGlobal("results"); workingMemory.fireAllRules(); assertEquals(1, results.size()); List cheeses = (List) results.get(0); assertEquals(2, cheeses.size()); assertEquals(bob.getLikes(), ((Cheese) cheeses.get(0)).getType()); assertEquals(bob.getLikes(), ((Cheese) cheeses.get(1)).getType()); }