use of org.kie.api.io.Resource in project drools by kiegroup.
the class KieSessionTest method createKieSession.
@Before
public void createKieSession() {
Resource[] resources = createResources();
if (resources == null) {
session = KieSessionUtil.getKieSessionFromKieBaseModel(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, kieSessionTestConfiguration);
} else {
session = KieSessionUtil.getKieSessionFromKieBaseModel(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, kieSessionTestConfiguration, resources);
}
firedRules = new TrackingAgendaEventListener();
session.addEventListener(firedRules);
}
use of org.kie.api.io.Resource in project drools by kiegroup.
the class KieBaseUtil method getKieBaseAndBuildInstallModuleFromDrl.
public static KieBase getKieBaseAndBuildInstallModuleFromDrl(final String moduleGroupId, final KieBaseTestConfiguration kieBaseTestConfiguration, final String drl) {
final Resource drlResource = KieServices.Factory.get().getResources().newReaderResource(new StringReader(drl));
drlResource.setTargetPath(TestConstants.DRL_TEST_TARGET_PATH);
return getKieBaseAndBuildInstallModule(KieUtil.generateReleaseId(moduleGroupId), kieBaseTestConfiguration, drlResource);
}
use of org.kie.api.io.Resource 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.io.Resource in project drools by kiegroup.
the class KieUtil method getKieFileSystemWithKieModule.
public static KieFileSystem getKieFileSystemWithKieModule(final KieModuleModel kieModuleModel, final ReleaseId releaseId, final Resource... resources) {
final KieFileSystem fileSystem = KieServices.Factory.get().newKieFileSystem();
fileSystem.generateAndWritePomXML(releaseId);
for (Resource resource : resources) {
fileSystem.write(resource);
}
fileSystem.writeKModuleXML(kieModuleModel.toXML());
return fileSystem;
}
use of org.kie.api.io.Resource in project drools by kiegroup.
the class KieSessionUtil method getKieSessionAndBuildInstallModuleFromDrl.
public static Session getKieSessionAndBuildInstallModuleFromDrl(final String moduleGroupId, final KieBaseTestConfiguration kieBaseTestConfiguration, final KieSessionTestConfiguration kieSessionTestConfiguration, final String drl) {
final Resource drlResource = KieServices.Factory.get().getResources().newReaderResource(new StringReader(drl));
drlResource.setTargetPath(TestConstants.DRL_TEST_TARGET_PATH);
return getKieSessionFromKieBaseModel(moduleGroupId, kieBaseTestConfiguration, kieSessionTestConfiguration, drlResource);
}
Aggregations