use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieUtil method getKieBuilderFromFileSystemWithResources.
private static KieBuilder getKieBuilderFromFileSystemWithResources(final KieBaseTestConfiguration kieBaseTestConfiguration, final KieFileSystem kfs, final boolean failIfBuildError, final Resource... resources) {
for (Resource res : resources) {
kfs.write(res);
}
KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
final Class<? extends KieBuilder.ProjectType> projectClass;
switch(kieBaseTestConfiguration.runType()) {
case STANDARD_FROM_DRL:
projectClass = DrlProject.class;
break;
case FLOW_DSL:
projectClass = ExecutableModelFlowProject.class;
break;
case PATTERN_DSL:
projectClass = ExecutableModelProject.class;
break;
default:
throw new RuntimeException("Unknown type: " + kieBaseTestConfiguration.runType());
}
kbuilder.buildAll(projectClass);
// Messages from KieBuilder with increasing severity
List<Message> msgs = kbuilder.getResults().getMessages(Message.Level.INFO);
if (msgs.size() > 0) {
LOGGER.info("KieBuilder information: {}", msgs.toString());
}
msgs = kbuilder.getResults().getMessages(Message.Level.WARNING);
if (msgs.size() > 0) {
LOGGER.warn("KieBuilder warnings: {}", msgs.toString());
}
msgs = kbuilder.getResults().getMessages(Message.Level.ERROR);
if (msgs.size() > 0) {
LOGGER.error("KieBuilder errors: {}", msgs.toString());
}
if (failIfBuildError) {
Assertions.assertThat(msgs).as(msgs.toString()).isEmpty();
}
return kbuilder;
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieContainerTest method createKieModule.
/**
* Helper method creating simple KieModule with given ReleaseId.
*/
private void createKieModule(final ReleaseId releaseId) {
final KieModuleModel kmodule = kieServices.newKieModuleModel();
kmodule.newKieBaseModel("defaultKBase").setDefault(true).newKieSessionModel(SESSION_NAME);
final KieFileSystem kfs = kieServices.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId);
kfs.writeKModuleXML(kmodule.toXML());
kfs.write("src/main/resources/defaultKBase/test.drl", kieServices.getResources().newByteArrayResource(DRL.getBytes()));
final KieBuilder kbuilder = kieServices.newKieBuilder(kfs);
kbuilder.buildAll();
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class NonStringCompareTest method testNonQuotedStringComapre.
@Test
public void testNonQuotedStringComapre() {
final KieBuilder kbuilder = build("someString");
Assertions.assertThat(kbuilder.getResults().getMessages(Level.ERROR).size()).isEqualTo(1);
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class NonStringCompareTest method testScenario.
private void testScenario(final String factFieldValueForDrl, final String factFieldValueForTest) throws IllegalAccessException, InstantiationException {
final KieBuilder kbuilder = build(factFieldValueForDrl);
Assertions.assertThat(kbuilder.getResults().getMessages(Level.ERROR)).isEmpty();
final KieBase kbase = KieBaseUtil.getDefaultKieBaseFromKieBuilder(kieBaseTestConfiguration, kbuilder);
final KieSession ksession = kbase.newKieSession();
try {
final FactType type = kbase.getFactType(TestConstants.PACKAGE_REGRESSION, "Fact");
final Object fact = type.newInstance();
type.set(fact, "field", factFieldValueForTest);
ksession.insert(fact);
final int count = ksession.fireAllRules();
Assertions.assertThat(count).isEqualTo(1);
} finally {
ksession.dispose();
}
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class DeclarationWithOrTest method testBindingWithOrInLHS.
/**
* Verifies that the rule with binding and OR in LHS compiles and works as expected.
*/
@Test
public void testBindingWithOrInLHS() {
final Resource resource = KieServices.Factory.get().getResources().newReaderResource(new StringReader(DRL));
resource.setTargetPath(TestConstants.DRL_TEST_TARGET_PATH);
final KieBuilder kbuilder = KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, resource);
final KieSession ksession = KieBaseUtil.getDefaultKieBaseFromKieBuilder(kieBaseTestConfiguration, kbuilder).newKieSession();
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
try {
ksession.insert("y");
ksession.fireAllRules();
} finally {
ksession.dispose();
}
Assertions.assertThat(list).as("Unexpected element in result global").containsExactly(FACT);
}
Aggregations