use of org.kie.api.builder.KieBuilder 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.KieBuilder 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.KieBuilder in project drools by kiegroup.
the class SequentialTest method testSequentialWithNoLoop.
@Test(timeout = 10000L)
public void testSequentialWithNoLoop() throws Exception {
// BZ-1228098
String str = "package org.drools.compiler.test\n" + "import \n" + Message.class.getCanonicalName() + ";" + "rule R1 no-loop when\n" + " $s : String( )" + " $m : Message( )\n" + "then\n" + " modify($m) { setMessage($s) };\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/r0.drl", str);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
if (results.hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
throw new RuntimeException(results.getMessages().toString());
}
KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
KieBaseConfiguration kieBaseConf = ks.newKieBaseConfiguration();
kieBaseConf.setOption(SequentialOption.YES);
StatelessKieSession sequentialKsession = kieContainer.newKieBase(kieBaseConf).newStatelessKieSession();
List result = (List) sequentialKsession.execute(CommandFactory.newInsertElements(Arrays.asList("test", new Message())));
assertEquals(2, result.size());
StatelessKieSession ksession = kieContainer.getKieBase().newStatelessKieSession();
result = (List) ksession.execute(CommandFactory.newInsertElements(Arrays.asList("test", new Message())));
assertEquals(2, result.size());
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class BasicUpdateTest method setUp.
@Before
public void setUp() {
final KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
kfs.write(KieServices.Factory.get().getResources().newClassPathResource(UPDATE_TEST_DRL, DeleteTest.class));
final KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
kbuilder.buildAll();
final List<Message> res = kbuilder.getResults().getMessages(Message.Level.ERROR);
assertEquals(res.toString(), 0, res.size());
final KieBase kbase = KieServices.Factory.get().newKieContainer(kbuilder.getKieModule().getReleaseId()).getKieBase();
ksession = kbase.newKieSession();
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class DslExpansionTest method testDSLExpansion_MessageImplNPE.
@Test
public void testDSLExpansion_MessageImplNPE() throws Exception {
final KieServices ks = KieServices.Factory.get();
final ReleaseId releaseId = ks.newReleaseId("org.kie", "dsl-test", "1.0-SNAPSHOT");
final KieModuleModel kproj = ks.newKieModuleModel();
final KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML()).writePomXML(generatePomXml(releaseId)).write("src/main/resources/KBase1/test-dsl.dsl", createDSL()).write("src/main/resources/KBase1/test-rule.dslr", createDRL());
final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
if (!messages.isEmpty()) {
for (final Message m : messages) {
System.out.println(m.getText());
}
}
assertTrue(messages.isEmpty());
}
Aggregations