use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationAddErrorThenEmptyWithoutError.
@Test
public void testIncrementalCompilationAddErrorThenEmptyWithoutError() throws Exception {
// BZ-1009369
// Invalid. Type "Smurf" is unknown
String drl1 = "Smurf";
// Valid
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();
// Add file with error - expect 2 build messages
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(2, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
// Add empty file - expect no "added" messages and no "removed" messages
kfs.write("src/main/resources/r2.drl", "");
IncrementalResults addResults1 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, addResults1.getAddedMessages().size());
assertEquals(0, addResults1.getRemovedMessages().size());
// Update file with no errors - expect no "added" messages and no "removed" messages
kfs.write("src/main/resources/r2.drl", drl2);
IncrementalResults addResults2 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, addResults2.getAddedMessages().size());
assertEquals(0, addResults2.getRemovedMessages().size());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class IncrementalCompilationTest method testRemoveAndReaddJavaClass.
@Test
public void testRemoveAndReaddJavaClass() {
// DROOLS-1704
String javaSource = "package org.drools.test;\n" + "public class Person { }\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
ReleaseId releaseId3 = ks.newReleaseId("org.kie", "test-upgrade", "1.2.0");
KieFileSystem kfs = ks.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId1);
KieModuleModel kModuleModel = ks.newKieModuleModel();
kfs.writeKModuleXML(kModuleModel.toXML());
kfs.write("src/main/java/org/drools/test/Person.java", javaSource);
ks.newKieBuilder(kfs).buildAll();
KieContainer kContainer = ks.newKieContainer(releaseId1);
try {
Class.forName("org.drools.test.Person", true, kContainer.getClassLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
kContainer.getKieBase();
kfs = ks.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId2);
kModuleModel = ks.newKieModuleModel();
kfs.writeKModuleXML(kModuleModel.toXML());
ks.newKieBuilder(kfs).buildAll();
kContainer.updateToVersion(releaseId2);
kContainer.getKieBase();
kfs = ks.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId3);
kModuleModel = ks.newKieModuleModel();
kfs.writeKModuleXML(kModuleModel.toXML());
kfs.write("src/main/java/org/drools/test/Person.java", javaSource);
ks.newKieBuilder(kfs).buildAll();
kContainer.updateToVersion(releaseId3);
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithDuplicatedRuleInSameDRL.
@Test
public void testIncrementalCompilationWithDuplicatedRuleInSameDRL() throws Exception {
String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n" + "rule R1 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertFalse(kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).isEmpty());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class RuleUnitTest method testRuleUnitFromKieContainer.
@Test
public void testRuleUnitFromKieContainer() {
String drl = "package org.drools.compiler.integrationtests\n" + "unit " + getCanonicalSimpleName(AdultUnitWithSingleItem.class) + "\n" + "import " + Person.class.getCanonicalName() + "\n" + "rule Adult when\n" + " $p : /person[age >= adultAge]\n" + "then\n" + " System.out.println($p.getName() + \" is adult\");\n" + "end";
String kmodule = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kmodule xmlns=\"http://jboss.org/kie/6.0.0/kmodule\">\n" + " <kbase name=\"unit\" equalsBehavior=\"equality\" eventProcessingMode=\"stream\">\n" + " <ksession name=\"unit-rules\" default=\"true\" type=\"stateful\" clockType=\"pseudo\"/>\n" + " </kbase>\n" + "</kmodule>";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl).writeKModuleXML(kmodule);
ks.newKieBuilder(kfs).buildAll();
KieContainer kcontainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
RuleUnitExecutor executor = kcontainer.newRuleUnitExecutor();
assertTrue(executor.getKieSession().getSessionClock() instanceof SessionPseudoClock);
RuleUnit adultUnit = new AdultUnitWithSingleItem(new Person("Mario", 42));
assertEquals(1, executor.run(adultUnit));
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class RuleUnitTest method testNotExistingDataSource.
@Test
public void testNotExistingDataSource() throws Exception {
String drl1 = "import " + Person.class.getCanonicalName() + "\n" + "import " + AdultUnit.class.getCanonicalName() + "\n" + "rule Adult @Unit( AdultUnit.class ) when\n" + " Person(age >= 18, $name : name) from adults\n" + "then\n" + " System.out.println($name + \" is adult\");\n" + "end";
KieServices ks = KieServices.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1);
Results results = ks.newKieBuilder(kfs).buildAll().getResults();
assertFalse(results.getMessages().isEmpty());
}
Aggregations