use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationDuplicateXLSResources.
@Test
public void testIncrementalCompilationDuplicateXLSResources() throws Exception {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
InputStream in1 = null;
InputStream in2 = null;
try {
// Add XLS decision table
in1 = this.getClass().getResourceAsStream("incrementalBuild.dtable.xls");
kfs.write("src/main/resources/incrementalBuild1.dtable.xls", KieServices.Factory.get().getResources().newInputStreamResource(in1));
// Expect no errors
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
// Add the same XLS decision table again as a different resource
in2 = this.getClass().getResourceAsStream("incrementalBuild.dtable.xls");
kfs.write("src/main/resources/incrementalBuild2.dtable.xls", KieServices.Factory.get().getResources().newInputStreamResource(in2));
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/incrementalBuild2.dtable.xls").build();
// Expect duplicate rule errors
assertEquals(1, addResults.getAddedMessages().size());
assertEquals(0, addResults.getRemovedMessages().size());
// Check errors on a full build
List<Message> messages = ks.newKieBuilder(kfs).buildAll().getResults().getMessages();
assertFalse(messages.isEmpty());
} finally {
if (in1 != null) {
in1.close();
}
if (in2 != null) {
in2.close();
}
}
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class XlsFormulaTest method getKieSession.
private KieSession getKieSession(Resource dt) {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write(dt);
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
assertTrue(kb.getResults().getMessages().isEmpty());
// get the session
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
return ksession;
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class DrlxCompiler method createKieContainer.
private static KieContainer createKieContainer(KieServices ks, KieFileSystem kfs, ReleaseId releaseId) {
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
if (results.hasMessages(Message.Level.ERROR)) {
throw new RuntimeException(results.getMessages().toString());
}
return ks.newKieContainer(releaseId);
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class BaseModelTest method getKieContainer.
protected KieContainer getKieContainer(KieModuleModel model, KieFile... stringRules) {
KieServices ks = KieServices.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "kjar-test-" + UUID.randomUUID(), "1.0");
KieBuilder kieBuilder = createKieBuilder(ks, model, releaseId, stringRules);
return ks.newKieContainer(releaseId);
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class BaseModelTest method createKieBuilder.
protected KieBuilder createKieBuilder(KieServices ks, KieModuleModel model, ReleaseId releaseId, boolean failIfBuildError, KieFile... stringRules) {
ks.getRepository().removeKieModule(releaseId);
KieFileSystem kfs = ks.newKieFileSystem();
if (model != null) {
kfs.writeKModuleXML(model.toXML());
}
kfs.writePomXML(KJARUtils.getPom(releaseId));
for (int i = 0; i < stringRules.length; i++) {
kfs.write(stringRules[i].path, stringRules[i].content);
}
KieBuilder kieBuilder;
if (testRunType == RUN_TYPE.FLOW_DSL) {
kieBuilder = ks.newKieBuilder(kfs).buildAll(ExecutableModelFlowProject.class);
} else if (testRunType == RUN_TYPE.PATTERN_DSL) {
kieBuilder = ks.newKieBuilder(kfs).buildAll(ExecutableModelProject.class);
} else {
kieBuilder = ks.newKieBuilder(kfs).buildAll();
}
if (failIfBuildError) {
List<Message> messages = kieBuilder.getResults().getMessages();
if (!messages.isEmpty()) {
fail(messages.toString());
}
}
return kieBuilder;
}
Aggregations