use of org.drools.testcoverage.common.model.Cheesery in project drools by kiegroup.
the class ContainsTest method testContainsCheese.
@Test
public void testContainsCheese() {
final String drl = "package org.drools.compiler.integrationtests.operators;\n" + "\n" + "import " + Cheese.class.getCanonicalName() + ";\n" + "import " + Cheesery.class.getCanonicalName() + ";\n" + "\n" + "global java.util.List list;\n" + "\n" + "rule \"Cheesery contains stilton\"\n" + " salience 10\n" + " when\n" + " stilton : Cheese( type == \"stilton\" )\n" + " Cheesery( cheeses contains stilton )\n" + " then\n" + " list.add( stilton );\n" + "end \n" + "\n" + "rule \"Cheesery does not contain brie\"\n" + " when\n" + " brie : Cheese( type == \"brie\" )\n" + " Cheesery( cheeses not contains brie )\n" + " then\n" + " list.add( brie );\n" + "end ";
final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("contains-test", kieBaseTestConfiguration, drl);
final KieSession ksession = kieBase.newKieSession();
try {
final List list = new ArrayList();
ksession.setGlobal("list", list);
final Cheese stilton = new Cheese("stilton", 12);
ksession.insert(stilton);
final Cheese brie = new Cheese("brie", 10);
ksession.insert(brie);
final Cheesery cheesery = new Cheesery();
cheesery.getCheeses().add(stilton);
ksession.insert(cheesery);
ksession.fireAllRules();
assertEquals(2, list.size());
assertEquals(stilton, list.get(0));
assertEquals(brie, list.get(1));
} finally {
ksession.dispose();
}
}
Aggregations