use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class IncrementalCompilationTest method testKJarUpgradeDRLWithSpace5_usingSingleQuote.
@Test
public void testKJarUpgradeDRLWithSpace5_usingSingleQuote() throws Exception {
// DROOLS-1399 quinquies (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();
// <<- notice the ' character on this one
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.kie.api.builder.KieModule in project drools by kiegroup.
the class IncrementalCompilationTest method testDeletedFile.
@Test
public void testDeletedFile() throws Exception {
String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
String drl2 = "package org.drools.compiler\n" + "rule R2_2 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
// Create an in-memory jar for version 1.0.0
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-delete", "1.0.0");
KieModule km = createAndDeployJar(ks, releaseId1, drl1, drl2);
KieContainer kieContainer = ks.newKieContainer(releaseId1);
KieContainer kieContainer2 = ks.newKieContainer(releaseId1);
KieSession ksession = kieContainer.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(2, ksession.fireAllRules());
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-delete", "1.0.1");
km = createAndDeployJar(ks, releaseId2, null, drl2);
kieContainer.updateToVersion(releaseId2);
// test with the old ksession ...
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
// ... and with a brand new one
ksession = kieContainer.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
// check that the second kieContainer hasn't been affected by the update of the first one
KieSession ksession2 = kieContainer2.newKieSession();
ksession2.insert(new Message("Hello World"));
assertEquals(2, ksession2.fireAllRules());
}
use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithEagerRules.
@Test
public void testIncrementalCompilationWithEagerRules() throws Exception {
// DROOLS-978
String drl1 = "rule R1 when\n" + "then\n" + " insert(\"test\");\n" + "end\n" + "\n" + "rule R2\n" + "no-loop true\n" + "when\n" + "then\n" + " insert(1);\n" + "end\n";
String drl2 = "rule R3\n" + "no-loop true\n" + "when\n" + "then\n" + " insert(1);\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.1");
KieModule km = createAndDeployJar(ks, releaseId1, drl1);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
ksession.fireAllRules();
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.2");
km = createAndDeployJar(ks, releaseId2, drl2);
kc.updateToVersion(releaseId2);
ksession.fireAllRules();
}
use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class IncrementalCompilationTest method createAndDeployAndTest.
public static void createAndDeployAndTest(KieContainer kc, String version, String header, String drls, String... ruleNames) {
if (ruleNames == null) {
ruleNames = new String[0];
}
KieServices ks = KieServices.Factory.get();
StringBuilder sbuilder = new StringBuilder();
sbuilder.append(header);
sbuilder.append(drls);
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", version);
KieModule km = createAndDeployJar(ks, releaseId1, sbuilder.toString());
kc.updateToVersion(km.getReleaseId());
KiePackage kpkg = kc.getKieBase().getKiePackage("org.drools.compiler");
assertEquals(ruleNames.length, kpkg.getRules().size());
Map<String, Rule> rules = rulestoMap(kpkg.getRules());
int i = 0;
for (String ruleName : ruleNames) {
assertEquals(ruleName, i++, ((RuleImpl) rules.get(ruleName)).getLoadOrder());
}
}
use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class IncrementalCompilationTest method testKJarUpgrade.
@Test
public void testKJarUpgrade() 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( message == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
// Create an in-memory jar for version 1.0.0
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = createAndDeployJar(ks, releaseId1, drl1, drl2_1);
// Create a session and fire rules
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
ksession.dispose();
// Create a new jar for version 1.1.0
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
km = createAndDeployJar(ks, releaseId2, drl1, drl2_2);
// try to update the container to version 1.1.0
kc.updateToVersion(releaseId2);
// create and use a new session
ksession = kc.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(2, ksession.fireAllRules());
}
Aggregations