@Test public void testCollectWithNestedFromWithParams() throws Exception { final PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader(getClass().getResourceAsStream("test_CollectWithNestedFrom.drl"))); final Package pkg = builder.getPackage(); RuleBase ruleBase = getSinglethreadRuleBase(); ruleBase.addPackage(pkg); ruleBase = SerializationHelper.serializeObject(ruleBase); final WorkingMemory workingMemory = ruleBase.newStatefulSession(); final 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); 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()); }
@Test public void testForall() throws Exception { final PackageBuilder builder = new PackageBuilder(); builder.addPackageFromDrl( new InputStreamReader(getClass().getResourceAsStream("test_Forall.drl"))); final Package pkg = builder.getPackage(); RuleBase ruleBase = getSinglethreadRuleBase(); ruleBase.addPackage(pkg); ruleBase = SerializationHelper.serializeObject(ruleBase); final WorkingMemory workingMemory = ruleBase.newStatefulSession(); final List list = new ArrayList(); workingMemory.setGlobal("results", list); final State state = new State("SP"); workingMemory.insert(state); final Person bob = new Person("Bob"); bob.setStatus(state.getState()); bob.setLikes("stilton"); workingMemory.insert(bob); workingMemory.fireAllRules(); assertEquals(0, list.size()); workingMemory.insert(new Cheese(bob.getLikes(), 10)); workingMemory.fireAllRules(); assertEquals(1, list.size()); }