use of org.drools.compiler.Message in project drools by kiegroup.
the class IncrementalCompilationTest method testKJarUpgradeDRLWithSpace3.
@Test
public void testKJarUpgradeDRLWithSpace3() throws Exception {
// DROOLS-1399 ter
String drl_1 = "package org.drools.compiler\n" + "rule Rs when $s : String() then System.out.println($s); end\n" + "rule Rx when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + " System.out.println($m); \n" + "end\n";
String drl_2 = "package org.drools.compiler\n" + // <<- notice rule changed
"rule Rs when $s : String( this == \"x\") then System.out.println($s); end\n" + "rule Rx when\n" + // <<- notice the EXTRA SPACE is the an ADDITIONAL change in this other version.
" $m : Message( message == \"Hello World\" )\n" + "then\n" + " System.out.println($m); \n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = createAndDeployJar(ks, releaseId1, drl_1);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
final List<String> fired = new ArrayList<>();
ksession.addEventListener(new DefaultAgendaEventListener() {
@Override
public void afterMatchFired(AfterMatchFiredEvent event) {
fired.add(event.getMatch().getRule().getName());
}
});
ksession.insert(new Message("Hello World"));
ksession.insert("x");
assertEquals(2, ksession.fireAllRules());
assertTrue(fired.contains("Rs"));
assertTrue(fired.contains("Rx"));
fired.clear();
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
km = createAndDeployJar(ks, releaseId2, drl_2);
kc.updateToVersion(releaseId2);
// rule Rx is UNchanged and should NOT fire again
// rule Rs is changed and should match again, and fire again.
assertEquals(1, ksession.fireAllRules());
assertTrue(fired.contains("Rs"));
assertFalse(fired.contains("Rx"));
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class IncrementalCompilationTest method testKJarUpgradeDRLWithSpace2.
@Test
public void testKJarUpgradeDRLWithSpace2() throws Exception {
// DROOLS-1399 bis
String drl_1 = "package org.drools.compiler\n" + "rule Rx when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
String drl_2 = "package org.drools.compiler\n" + "rule Rx when\n" + // <<- notice the EXTRA SPACE is the only change in this other version.
" $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = createAndDeployJar(ks, releaseId1, drl_1);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
km = createAndDeployJar(ks, releaseId2, drl_2);
kc.updateToVersion(releaseId2);
// rule Rx is UNchanged and should NOT fire again
assertEquals(0, ksession.fireAllRules());
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class IncrementalCompilationTest method testKJarUpgradeDRLWithSpace5.
@Test
public void testKJarUpgradeDRLWithSpace5() throws Exception {
// DROOLS-1399 quinquies
String drl_1 = "package org.drools.compiler\n" + "rule Rx when\n" + " $m : Message( message == \"Hello' World\" )\n" + "then\n" + "end\n";
String drl_2 = "package org.drools.compiler\n" + "rule Rx when\n" + // <<- notice the EXTRA SPACE typo was removed
" $m : Message( message == \"Hello' World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = createAndDeployJar(ks, releaseId1, drl_1);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
// <<- notice the ' character
ksession.insert(new Message("Hello' World"));
assertEquals(0, ksession.fireAllRules());
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
km = createAndDeployJar(ks, releaseId2, drl_2);
kc.updateToVersion(releaseId2);
// rule Rx is UNchanged and should NOT fire again
assertEquals(1, ksession.fireAllRules());
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class MarshallingTest method testAccumulate2.
@Test
public void testAccumulate2() throws Exception {
String str = "package org.drools\n" + "\n" + "import org.drools.compiler.Message\n" + "\n" + "rule MyRule\n" + " when\n" + " Number( intValue >= 5 ) from accumulate ( m: Message( ), count( m ) )\n" + " then\n" + " System.out.println(\"Found messages\");\n" + "end\n";
KieBase kBase = loadKnowledgeBaseFromString(str);
KieSession ksession = kBase.newKieSession();
ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
ksession.insert(new Message());
ksession.insert(new Message());
ksession.insert(new Message());
ksession.insert(new Message());
ksession.insert(new Message());
((InternalWorkingMemory) ksession).flushPropagations();
assertEquals(1, ((InternalAgenda) ksession.getAgenda()).agendaSize());
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class SerializedPackageMergeTest method getObject.
private Message getObject() throws ParseException {
Message message = new Message();
message.setMessage("hola");
message.setNumber(50);
message.getList().add("hello");
message.setBirthday(DF.parse("10-Jul-1976"));
return message;
}
Aggregations