use of org.drools.testcoverage.common.model.Message in project drools by kiegroup.
the class IncrementalCompilationTest method testKJarUpgradeSameSessionAddingGlobal.
@Test
public void testKJarUpgradeSameSessionAddingGlobal() {
// DROOLS-523
final String drl1 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "global java.lang.String foo\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
final String drl2_1 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R2_1 when\n" + " $m : Message( message == \"Hi Universe\" )\n" + "then\n" + "end\n";
final String drl2_2 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "global java.lang.String foo\n" + "rule R2_2 when\n" + " $m : Message( message == foo )\n" + "then\n" + "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-upgrade", "1.0.0");
KieUtil.getKieModuleFromDrls(releaseId1, kieBaseTestConfiguration, drl1, drl2_1);
// Create a session and fire rules
final KieContainer kc = ks.newKieContainer(releaseId1);
final KieSession ksession = kc.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
// 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, drl1, drl2_2);
// try to update the container to version 1.1.0
kc.updateToVersion(releaseId2);
ksession.setGlobal("foo", "Hello World");
// continue working with the session
ksession.insert(new Message("Hello World"));
assertEquals(2, ksession.fireAllRules());
}
use of org.drools.testcoverage.common.model.Message in project drools by kiegroup.
the class IncrementalCompilationTest method testDeletedFile.
@Test
public void testDeletedFile() {
final String drl1 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
final String drl2 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R2_2 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "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-delete", "1.0.0");
KieUtil.getKieModuleFromDrls(releaseId1, kieBaseTestConfiguration, drl1, drl2);
final KieContainer kieContainer = ks.newKieContainer(releaseId1);
final KieContainer kieContainer2 = ks.newKieContainer(releaseId1);
KieSession ksession = kieContainer.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(2, ksession.fireAllRules());
final ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-delete", "1.0.1");
KieUtil.getKieModuleFromDrls(releaseId2, kieBaseTestConfiguration, (String) 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
final KieSession ksession2 = kieContainer2.newKieSession();
ksession2.insert(new Message("Hello World"));
assertEquals(2, ksession2.fireAllRules());
}
use of org.drools.testcoverage.common.model.Message in project drools by kiegroup.
the class IncrementalCompilationTest method testKJarUpgradeSameSession.
@Test
public void testKJarUpgradeSameSession() {
final String drl1 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
final String drl2_1 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R2_1 when\n" + " $m : Message( message == \"Hi Universe\" )\n" + "then\n" + "end\n";
final String drl2_2 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R2_2 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "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-upgrade", "1.0.0");
KieUtil.getKieModuleFromDrls(releaseId1, kieBaseTestConfiguration, drl1, drl2_1);
// Create a session and fire rules
final KieContainer kc = ks.newKieContainer(releaseId1);
final KieSession ksession = kc.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
// 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, drl1, drl2_2);
// try to update the container to version 1.1.0
kc.updateToVersion(releaseId2);
// continue working with the session
ksession.insert(new Message("Hello World"));
assertEquals(3, ksession.fireAllRules());
}
use of org.drools.testcoverage.common.model.Message in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithInvalidDRL.
@Test
public void testIncrementalCompilationWithInvalidDRL() {
final String drl1 = "Smurf";
final String drl2_1 = "package org.drools.compiler\n" + "rule R2\n" + "when\n" + " $m : NonExistentClass()\n" + "then\n" + "end\n";
final String drl2_2 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R2\n" + "when\n" + " $m : Message()\n" + "then\n" + "end\n";
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
// First file contains errors
kfs.write("src/main/resources/r1.drl", drl1);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
final Results results1 = kieBuilder.getResults();
assertEquals(2, results1.getMessages().size());
// Second file also contains errors.. expect some added messages
kfs.write("src/main/resources/r2.drl", drl2_1);
final IncrementalResults results2 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(1, results2.getAddedMessages().size());
assertEquals(0, results2.getRemovedMessages().size());
// Correct second file... expect original errors relating to the file to be removed
kfs.write("src/main/resources/r2.drl", drl2_2);
final IncrementalResults results3 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, results3.getAddedMessages().size());
assertEquals(1, results3.getRemovedMessages().size());
// Remove first file... expect related errors to be removed
kfs.delete("src/main/resources/r1.drl");
final IncrementalResults results4 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r1.drl").build();
assertEquals(0, results4.getAddedMessages().size());
assertEquals(2, results4.getRemovedMessages().size());
}
use of org.drools.testcoverage.common.model.Message in project drools by kiegroup.
the class IncrementalCompilationTest method testKJarUpgradeDRLWithSpace.
private void testKJarUpgradeDRLWithSpace(final String drl1, final String drl2, final String factString, final int firstFireCount, final int secondFireCount) {
final KieServices ks = KieServices.Factory.get();
final ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieUtil.getKieModuleFromDrls(releaseId1, kieBaseTestConfiguration, drl1);
final KieContainer kc = ks.newKieContainer(releaseId1);
final KieSession ksession = kc.newKieSession();
ksession.insert(new Message(factString));
assertEquals(firstFireCount, ksession.fireAllRules());
final ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
KieUtil.getKieModuleFromDrls(releaseId2, kieBaseTestConfiguration, drl2);
kc.updateToVersion(releaseId2);
assertEquals(secondFireCount, ksession.fireAllRules());
}
Aggregations