use of org.drools.testcoverage.common.model.MyFact in project drools by kiegroup.
the class AccumulateConsistencyTest method testMinMatchUnification.
@Test
public void testMinMatchUnification() {
final String drl = "package org.drools.compiler.integrationtests;\n" + "import " + Person.class.getCanonicalName() + ";\n" + "import " + MyFact.class.getCanonicalName() + ";\n" + "rule R\n" + "when\n" + " MyFact($i : currentValue)\n" + " accumulate( $p : Person( name == \"John\" ),\n" + " $i := min( $p.getAge() ) )\n" + "then\n" + " System.out.println($i);\n" + "end";
final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("accumulate-test", kieBaseTestConfiguration, drl);
KieSessionConfiguration kieSessionConfiguration = KieServices.get().newKieSessionConfiguration();
kieSessionConfiguration.setProperty(AccumulateNullPropagationOption.PROPERTY_NAME, Boolean.toString(accumulateNullPropagation));
final KieSession kieSession = kieBase.newKieSession(kieSessionConfiguration, null);
try {
kieSession.insert(new Person("John", 20));
kieSession.insert(new MyFact("A", 20));
assertEquals(1, kieSession.fireAllRules());
} finally {
kieSession.dispose();
}
}
use of org.drools.testcoverage.common.model.MyFact in project drools by kiegroup.
the class EnabledTest method testEnabledExpression2.
@Test
public void testEnabledExpression2() {
final String drl = "import " + MyFact.class.getName() + ";\n" + "rule R1\n" + " enabled( rule.name == $f.name )" + "when\n" + " $f : MyFact()\n" + "then end\n" + "rule R2\n" + "when\n" + " MyFact( name == \"R2\" )\n" + "then end\n";
final KieServices ks = KieServices.Factory.get();
// Create an in-memory jar for version 1.0.0
final ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-enabled", "1.0.0");
final KieModule km = KieUtil.getKieModuleFromDrls(releaseId1, kieBaseTestConfiguration, drl);
// Create a session and fire rules
final KieContainer kc = ks.newKieContainer(km.getReleaseId());
AgendaEventListener ael = mock(AgendaEventListener.class);
KieSession ksession = kc.newKieSession();
try {
ksession.addEventListener(ael);
ksession.insert(new MyFact("R1", null));
assertEquals(1, ksession.fireAllRules());
ksession.dispose();
ArgumentCaptor<AfterMatchFiredEvent> event = ArgumentCaptor.forClass(AfterMatchFiredEvent.class);
verify(ael).afterMatchFired(event.capture());
assertEquals("R1", event.getValue().getMatch().getRule().getName());
ael = mock(AgendaEventListener.class);
ksession.dispose();
ksession = kc.newKieSession();
ksession.addEventListener(ael);
ksession.insert(new MyFact("R2", null));
assertEquals(1, ksession.fireAllRules());
ksession.dispose();
event = ArgumentCaptor.forClass(AfterMatchFiredEvent.class);
verify(ael).afterMatchFired(event.capture());
assertEquals("R2", event.getValue().getMatch().getRule().getName());
} finally {
ksession.dispose();
}
}
use of org.drools.testcoverage.common.model.MyFact in project drools by kiegroup.
the class IncrementalCompilationCepTest method testRemoveRuleAndThenFactInStreamMode.
@Test
public void testRemoveRuleAndThenFactInStreamMode() {
// DROOLS-731
final String header = "package org.some.test\n" + "import " + MyFact.class.getCanonicalName() + "\n";
final String declaration = "declare MyFact\n" + "@role(event)" + "end\n";
final String rule2 = "rule R when\n" + " $FactA : MyFact ($FactA_field2 : currentValue == 105742)\n" + " not MyFact($FactA_field2 == 105742)\n" + "then\n" + "end\n";
final String file2 = header + declaration + rule2;
final KieServices ks = KieServices.Factory.get();
// Create an in-memory jar for version 1.0.0
final ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieUtil.getKieModuleFromDrls(releaseId1, kieBaseTestConfiguration, file2);
// Create a session and fire rules
final KieContainer kc = ks.newKieContainer(releaseId1);
final KieSession ksession = kc.newKieSession();
final MyFact myFact = new MyFact("entry:" + 105742, 105742);
final FactHandle fh = ksession.insert(myFact);
// Create a new jar for version 1.1.0
final ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
KieUtil.getKieModuleFromDrls(releaseId2, kieBaseTestConfiguration);
// try to update the container to version 1.1.0
kc.updateToVersion(releaseId2);
ksession.delete(fh);
}
use of org.drools.testcoverage.common.model.MyFact in project drools by kiegroup.
the class AccumulateConsistencyTest method testMinNoMatchUnification.
@Test
public void testMinNoMatchUnification() {
final String drl = "package org.drools.compiler.integrationtests;\n" + "import " + Person.class.getCanonicalName() + ";\n" + "import " + MyFact.class.getCanonicalName() + ";\n" + "rule R\n" + "when\n" + " MyFact($i : currentValue)\n" + " accumulate( $p : Person( name == \"John\" ),\n" + " $i := min( $p.getAge() ) )\n" + "then\n" + " System.out.println($i);\n" + "end";
final KieBase kieBase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("accumulate-test", kieBaseTestConfiguration, drl);
KieSessionConfiguration kieSessionConfiguration = KieServices.get().newKieSessionConfiguration();
kieSessionConfiguration.setProperty(AccumulateNullPropagationOption.PROPERTY_NAME, Boolean.toString(accumulateNullPropagation));
final KieSession kieSession = kieBase.newKieSession(kieSessionConfiguration, null);
try {
kieSession.insert(new Person("Paul", 20));
kieSession.insert(new MyFact("A", null));
if (accumulateNullPropagation) {
assertEquals(1, kieSession.fireAllRules());
} else {
// don't propagate null
assertEquals(0, kieSession.fireAllRules());
}
} finally {
kieSession.dispose();
}
}
use of org.drools.testcoverage.common.model.MyFact in project drools by kiegroup.
the class AccumulateRecalculationTest method scenario.
private void scenario(final String drl) {
final KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().newKieSession();
final MyFact fact0 = new MyFact("target", 0);
final MyFact fact1 = new MyFact("src1", 4);
final MyFact fact2 = new MyFact("src2", 5);
final FactHandle fh0 = ksession.insert(fact0);
final FactHandle fh1 = ksession.insert(fact1);
final FactHandle fh2 = ksession.insert(fact2);
int fireCount = ksession.fireAllRules();
Assertions.assertThat(fact0.getCurrentValue().intValue()).isEqualTo(9);
Assertions.assertThat(fireCount).isEqualTo(2);
fact2.setCurrentValue(6);
ksession.update(fh2, fact2);
fireCount = ksession.fireAllRules();
Assertions.assertThat(fact0.getCurrentValue().intValue()).isEqualTo(10);
Assertions.assertThat(fireCount).isEqualTo(2);
}
Aggregations