use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testCollectNodeSharing.
@Test
public void testCollectNodeSharing() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_collectNodeSharing.drl");
KieSession wm = kbase.newKieSession();
List results = new ArrayList();
wm.setGlobal("results", results);
wm = SerializationHelper.getSerialisedStatefulKnowledgeSession(wm, true);
results = (List) wm.getGlobal("results");
wm.insert(new Cheese("stilton", 10));
wm = SerializationHelper.getSerialisedStatefulKnowledgeSession(wm, true);
results = (List) wm.getGlobal("results");
wm.insert(new Cheese("brie", 15));
wm.fireAllRules();
wm = SerializationHelper.getSerialisedStatefulKnowledgeSession(wm, true);
results = (List) wm.getGlobal("results");
assertEquals(1, results.size());
assertEquals(2, ((List) results.get(0)).size());
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class ExtendsTest method testExtendsBasic2.
@Test
public void testExtendsBasic2() {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_RuleExtend.drl");
KieSession ksession = kbase.newKieSession();
final List results = new ArrayList();
ksession.setGlobal("results", results);
final Cheese stilton = new Cheese("stilton", 5);
final Cheese cheddar = new Cheese("cheddar", 7);
final Cheese brie = new Cheese("brie", 5);
ksession.insert(stilton);
ksession.insert(cheddar);
ksession.insert(brie);
ksession.fireAllRules();
assertEquals(2, results.size());
assertEquals("stilton", results.get(0));
assertEquals("brie", results.get(1));
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testCollectWithNestedFromWithParams.
@Test
public void testCollectWithNestedFromWithParams() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_CollectWithNestedFrom.drl");
KieSession workingMemory = kbase.newKieSession();
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());
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testMVELCollect.
@Test
public void testMVELCollect() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_MVELCollect.drl");
KieSession wm = kbase.newKieSession();
final List results = new ArrayList();
wm.setGlobal("results", results);
wm.insert(new Cheese("stilton", 10));
wm.insert(new Cheese("stilton", 7));
wm.insert(new Cheese("stilton", 8));
wm.insert(new Cheese("brie", 5));
wm.insert(new Cheese("provolone", 150));
wm.insert(new Cheese("provolone", 20));
wm.insert(new Person("Bob", "stilton"));
wm.insert(new Person("Mark", "provolone"));
wm.fireAllRules();
assertEquals(1, results.size());
assertEquals(6, ((List) results.get(0)).size());
}
use of org.drools.mvel.compiler.Cheese in project drools by kiegroup.
the class FirstOrderLogicTest method testCollectModifyAlphaRestriction.
@Test
public void testCollectModifyAlphaRestriction() throws Exception {
KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(getClass(), kieBaseTestConfiguration, "test_CollectAlphaRestriction.drl");
KieSession wm = kbase.newKieSession();
final List results = new ArrayList();
wm.setGlobal("results", results);
final Cheese[] cheese = new Cheese[] { new Cheese("stilton", 10), new Cheese("stilton", 2), new Cheese("stilton", 5), new Cheese("brie", 15), new Cheese("brie", 16), new Cheese("provolone", 8) };
final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
for (int i = 0; i < cheese.length; i++) {
cheeseHandles[i] = (FactHandle) wm.insert(cheese[i]);
}
// ---------------- 1st scenario
int fireCount = 0;
wm.fireAllRules();
assertEquals(++fireCount, results.size());
assertEquals(3, ((Collection) results.get(fireCount - 1)).size());
assertEquals(ArrayList.class.getName(), results.get(fireCount - 1).getClass().getName());
// ---------------- 2nd scenario
final int index = 1;
cheese[index].setType("brie");
wm.update(cheeseHandles[index], cheese[index]);
wm.fireAllRules();
assertEquals(++fireCount, results.size());
assertEquals(2, ((Collection) results.get(fireCount - 1)).size());
assertEquals(ArrayList.class.getName(), results.get(fireCount - 1).getClass().getName());
// ---------------- 3rd scenario
wm.retract(cheeseHandles[2]);
wm.fireAllRules();
assertEquals(++fireCount, results.size());
assertEquals(1, ((Collection) results.get(fireCount - 1)).size());
assertEquals(ArrayList.class.getName(), results.get(fireCount - 1).getClass().getName());
}
Aggregations