use of org.drools.testcoverage.common.listener.TrackingAgendaEventListener in project drools by kiegroup.
the class DecisionTableTest method testActivationGroup.
@Test
public void testActivationGroup() {
final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, agendaGroupDecisionTable);
final KieSession ksession = kbase.newKieSession();
final TrackingAgendaEventListener listener = new TrackingAgendaEventListener();
ksession.addEventListener(listener);
// only one rule from activation group may fire
ksession.insert("activationGroup");
ksession.fireAllRules();
Assertions.assertThat(listener.isRuleFired("c1")).isFalse();
Assertions.assertThat(listener.isRuleFired("c2")).isTrue();
Assertions.assertThat(listener.isRuleFired("c3")).isFalse();
ksession.dispose();
}
use of org.drools.testcoverage.common.listener.TrackingAgendaEventListener in project drools by kiegroup.
the class KieSessionTest method createKieSession.
@Before
public void createKieSession() {
Resource[] resources = createResources();
if (resources == null) {
session = KieSessionUtil.getKieSessionFromKieBaseModel(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, kieSessionTestConfiguration);
} else {
session = KieSessionUtil.getKieSessionFromKieBaseModel(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, kieSessionTestConfiguration, resources);
}
firedRules = new TrackingAgendaEventListener();
session.addEventListener(firedRules);
}
use of org.drools.testcoverage.common.listener.TrackingAgendaEventListener in project drools by kiegroup.
the class FusionAfterBeforeTest method testAfterBeforeOperators.
@Test
public void testAfterBeforeOperators() {
final Resource drlResource = KieServices.Factory.get().getResources().newClassPathResource("fusionAfterBeforeTest.drl", getClass());
final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromResources(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, drlResource);
final KieSessionConfiguration ksconf = RuleBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.PSEUDO);
final KieSession ksession = kieBase.newKieSession(ksconf, null);
final TrackingAgendaEventListener listener = new TrackingAgendaEventListener();
ksession.addEventListener(listener);
final EntryPoint stream = ksession.getEntryPoint("EventStream");
SessionPseudoClock clock = ksession.getSessionClock();
try {
for (int i = 0; i < 3; i++) {
final MessageEvent tc = new MessageEvent(MessageEvent.Type.received, new Message());
stream.insert(tc);
ksession.fireAllRules();
clock.advanceTime(8, TimeUnit.SECONDS);
}
ksession.fireAllRules();
} finally {
ksession.dispose();
}
Assertions.assertThat(listener.isRuleFired("AfterMessageEvent")).as("Rule 'AfterMessageEvent' was no fired!").isTrue();
Assertions.assertThat(listener.isRuleFired("BeforeMessageEvent")).as("Rule 'BeforeMessageEvent' was no fired!").isTrue();
// each rules should be fired 2 times
int firedCount = 2;
int actuallyFired = listener.ruleFiredCount("AfterMessageEvent");
Assertions.assertThat(firedCount).as("Rule 'AfterMessageEvent' should be fired 2 times, but was fired " + firedCount + " time(s)!").isEqualTo(actuallyFired);
firedCount = listener.ruleFiredCount("BeforeMessageEvent");
Assertions.assertThat(firedCount).as("Rule 'BeforeMessageEvent' should be fired 2 times, but was fired " + firedCount + " time(s)!").isEqualTo(actuallyFired);
}
use of org.drools.testcoverage.common.listener.TrackingAgendaEventListener in project drools by kiegroup.
the class ActivationGroupTest method testActivationGroupRecursivelyWithDefaultSalience.
@Test
public void testActivationGroupRecursivelyWithDefaultSalience() {
TrackingAgendaEventListener listener = prepareKSession("defaultSalienceWithRecursion");
Assertions.assertThat(listener.rulesCount()).isEqualTo(2);
}
use of org.drools.testcoverage.common.listener.TrackingAgendaEventListener in project drools by kiegroup.
the class UnwantedStringConversionTest method testStringToDecimalConversion.
@Test
public void testStringToDecimalConversion() {
final Resource drlResource = KieServices.Factory.get().getResources().newClassPathResource("unwantedStringConversionTest.drl", getClass());
final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromResources(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, drlResource);
final KieSession ksession = kieBase.newKieSession();
final TrackingAgendaEventListener listener = new TrackingAgendaEventListener();
ksession.addEventListener(listener);
final Message message = new Message();
final SomeEntity someEntity = new SomeEntity("1.5");
message.setSomeEntity(someEntity);
message.setMessage("1.5");
ksession.insert(message);
ksession.fireAllRules();
Assertions.assertThat(listener.isRuleFired("R1")).isFalse();
Assertions.assertThat(listener.isRuleFired("R2")).isFalse();
Assertions.assertThat(listener.rulesCount()).isEqualTo(0);
}
Aggregations