use of org.drools.compiler.Message in project drools by kiegroup.
the class WorkingMemoryLoggerTest method testLogAllBoundVariables.
@Test
public void testLogAllBoundVariables() throws Exception {
// BZ-1271909
final String drl = "import " + Message.class.getCanonicalName() + "\n" + "rule \"Hello World\" no-loop\n" + " when\n" + " $messageInstance : Message( $myMessage : message )\n" + " then\n" + " update($messageInstance);\n" + "end\n";
final KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().newKieSession();
final WorkingMemoryInMemoryLogger logger = new WorkingMemoryInMemoryLogger((WorkingMemory) ksession);
final Message message = new Message();
message.setMessage("Hello World");
ksession.insert(message);
ksession.fireAllRules();
for (final LogEvent logEvent : logger.getLogEvents()) {
if (logEvent instanceof ActivationLogEvent) {
assertTrue(((ActivationLogEvent) logEvent).getDeclarations().contains("$messageInstance"));
assertTrue(((ActivationLogEvent) logEvent).getDeclarations().contains("$myMessage"));
}
}
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithAddedError.
@Test
public void testIncrementalCompilationWithAddedError() throws Exception {
String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
String drl2_1 = "package org.drools.compiler\n" + "rule R2_1 when\n" + " $m : Message( message == \"Hi Universe\" )\n" + "then\n" + "end\n";
String drl2_2 = "package org.drools.compiler\n" + "rule R2_2 when\n" + " $m : Message( nonExistentField == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1).write("src/main/resources/r2.drl", drl2_1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
KieSession ksession = kieContainer.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
kfs.write("src/main/resources/r2.drl", drl2_2);
IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(1, results.getAddedMessages().size());
assertEquals(0, results.getRemovedMessages().size());
kieContainer.updateToVersion(ks.getRepository().getDefaultReleaseId());
ksession = kieContainer.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class IncrementalCompilationTest method testKJarUpgradeDRLWithSpace2_usingSingleQuote.
@Test
public void testKJarUpgradeDRLWithSpace2_usingSingleQuote() throws Exception {
// DROOLS-1399 bis (using single quote)
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 testKJarUpgradeWithSpace_usingSingleQuote.
@Test
public void testKJarUpgradeWithSpace_usingSingleQuote() throws Exception {
// DROOLS-1399 (using single quote)
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 = // <<- notice the EXTRA SPACE is the only change in this other version.
"package org.drools.compiler\n " + "rule Rx when\n" + " $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 testKJarUpgradeDRLWithSpace4_usingSingleQuote.
@Test
public void testKJarUpgradeDRLWithSpace4_usingSingleQuote() throws Exception {
// DROOLS-1399 quater (using single quote)
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();
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());
}
Aggregations