use of org.drools.testcoverage.common.model.Cheese in project drools by kiegroup.
the class MemberOfTest method testMemberOfAndNotMemberOf.
@Test
public void testMemberOfAndNotMemberOf() {
final String drl = "package org.drools.compiler.test;\n" + "\n" + "import " + Cheese.class.getCanonicalName() + ";\n" + "import " + Cheesery.class.getCanonicalName() + ";\n" + "\n" + "global java.util.List list;\n" + "\n" + "rule \"Stilton is memberOf Cheesery\"\n" + " salience 10\n" + " when\n" + " Cheesery( $cheeses : cheeses )\n" + " cheese : Cheese( type memberOf $cheeses )\n" + " then\n" + " list.add( cheese );\n" + "end \n" + "\n" + "rule \"Muzzarela is not memberOf Cheesery\"\n" + " when\n" + " Cheesery( $cheeses : cheeses )\n" + " cheese : Cheese( type not memberOf $cheeses )\n" + " then\n" + " list.add( cheese );\n" + "end";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("member-of-test", kieBaseTestConfiguration, drl);
final KieSession ksession = kbase.newKieSession();
try {
final List list = new ArrayList();
ksession.setGlobal("list", list);
final Cheese stilton = new Cheese("stilton", 12);
final Cheese muzzarela = new Cheese("muzzarela", 10);
final Cheese brie = new Cheese("brie", 15);
ksession.insert(stilton);
ksession.insert(muzzarela);
final Cheesery cheesery = new Cheesery();
cheesery.getCheeses().add(stilton);
cheesery.getCheeses().add(brie);
ksession.insert(cheesery);
ksession.fireAllRules();
assertEquals(2, list.size());
assertEquals(stilton, list.get(0));
assertEquals(muzzarela, list.get(1));
} finally {
ksession.dispose();
}
}
use of org.drools.testcoverage.common.model.Cheese in project drools by kiegroup.
the class ActivationTest method noDormantCheckOnModifies.
/**
* Tests improper deactivation of already activated rule on the agenda. See
* BZ 862325.
*/
@Test
public void noDormantCheckOnModifies() throws Exception {
AgendaEventListener ael = mock(AgendaEventListener.class);
session.addEventListener(ael);
session.setGlobal("LOGGER", LOGGER);
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(getCommands().newInsert(new Person("Bob", 19)));
commands.add(getCommands().newInsert(new Cheese("brie", 10)));
commands.add(getCommands().newFireAllRules());
session.execute(getCommands().newBatchExecution(commands, null));
// both rules should fire exactly once
verify(ael, times(2)).afterMatchFired(any(AfterMatchFiredEvent.class));
// no cancellations should have happened
verify(ael, never()).matchCancelled(any(MatchCancelledEvent.class));
}
use of org.drools.testcoverage.common.model.Cheese in project drools by kiegroup.
the class TimerAndCalendarWithRealTimeTest method testDuration.
@Test(timeout = 15000)
public void testDuration() throws Exception {
final String drl = "package org.drools.compiler.test;\n" + "\n" + "import " + Cheese.class.getCanonicalName() + ";\n" + "import " + Person.class.getCanonicalName() + ";\n" + "\n" + "global java.util.List list;\n" + "\n" + "rule delayed\n" + " duration 100\n" + " when\n" + " cheese : Cheese( )\n" + " then\n" + " list.add( cheese );\n" + "end ";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("timer-and-calendar-test", kieBaseTestConfiguration, drl);
ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
final Cheese brie = new Cheese("brie", 12);
ksession.insert(brie);
ksession.fireAllRules();
// now check for update
assertEquals(0, list.size());
awaitUntilRulesThatFiredAre(1);
// now check for update
assertEquals(1, list.size());
}
use of org.drools.testcoverage.common.model.Cheese in project drools by kiegroup.
the class TimerAndCalendarWithRealTimeTest method testDurationWithNoLoop.
@Test(timeout = 10000)
public void testDurationWithNoLoop() throws Exception {
final String drl = "package org.drools.compiler.test;\n" + "\n" + "import " + Cheese.class.getCanonicalName() + ";\n" + "import " + Person.class.getCanonicalName() + ";\n" + "\n" + "global java.util.List list;\n" + "\n" + "rule delayed\n" + " timer 100\n" + " no-loop true\n" + " when\n" + " cheese : Cheese( )\n" + " then\n" + " list.add( cheese );\n" + "end";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("timer-and-calendar-test", kieBaseTestConfiguration, drl);
ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
final Cheese brie = new Cheese("brie", 12);
ksession.insert(brie);
ksession.fireAllRules();
// now check for update
assertEquals(0, list.size());
awaitUntilRulesThatFiredAre(1);
// now check for update
assertEquals(1, list.size());
}
use of org.drools.testcoverage.common.model.Cheese in project drools by kiegroup.
the class JoinNodeRangeIndexingTest method testCoercionBigDecimalVsInt.
@Test
public void testCoercionBigDecimalVsInt() {
final String drl = "package org.drools.compiler.integrationtests;\n" + "import " + Cheese.class.getCanonicalName() + ";\n" + "import " + Primitives.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "rule R\n" + " when\n" + " Cheese($price : price)\n" + " p : Primitives(bigDecimal < $price)\n" + " then\n" + " list.add( p );\n" + "end";
// Integer is coerced to BigDecimal
final KieBase kbase = getKieBaseWithRangeIndexOption(drl);
assertIndexedTrue(kbase, Primitives.class);
final KieSession ksession = kbase.newKieSession();
try {
final List<Primitives> list = new ArrayList<>();
ksession.setGlobal("list", list);
final Primitives bd42 = new Primitives();
bd42.setBigDecimal(new BigDecimal("42"));
ksession.insert(bd42);
final Primitives bd43 = new Primitives();
bd43.setBigDecimal(new BigDecimal("43"));
ksession.insert(bd43);
ksession.insert(new Cheese("gorgonzola", 43));
ksession.fireAllRules();
Assertions.assertThat(list).containsExactly(bd42);
} finally {
ksession.dispose();
}
}
Aggregations