use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class DecimalSeparatorTest method init.
public void init() {
final KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmodule = ks.newKieModuleModel();
KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase").setDefault(true);
baseModel.newKieSessionModel("defaultKSession").setDefault(true);
kfs.writeKModuleXML(kmodule.toXML());
kfs.write(ks.getResources().newClassPathResource("decimalSeparator.xls", // README when path is set then test works
this.getClass()));
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class AbstractKnowledgeTest method compile.
public List<String> compile(KieModuleModel kproj, MemoryFileSystem srcMfs, MemoryFileSystem trgMfs, List<String> classes) {
for (KieBaseModel kbase : kproj.getKieBaseModels().values()) {
Folder srcFolder = srcMfs.getFolder("src/main/resources/" + kbase.getName());
Folder trgFolder = trgMfs.getFolder(kbase.getName());
copyFolder(srcMfs, srcFolder, trgMfs, trgFolder, kproj);
}
Folder srcFolder = srcMfs.getFolder("META-INF");
Folder trgFolder = trgMfs.getFolder("META-INF");
trgFolder.create();
copyFolder(srcMfs, srcFolder, trgMfs, trgFolder, kproj);
EclipseJavaCompilerSettings settings = new EclipseJavaCompilerSettings();
settings.setSourceVersion("1.5");
settings.setTargetVersion("1.5");
EclipseJavaCompiler compiler = new EclipseJavaCompiler(settings, "");
CompilationResult res = compiler.compile(classes.toArray(new String[classes.size()]), trgMfs, trgMfs);
if (res.getErrors().length > 0) {
fail(res.getErrors()[0].getMessage());
}
List<String> classes2 = new ArrayList<String>(classes.size());
for (String str : classes) {
classes2.add(filenameToClassname(str));
}
return classes2;
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class SimulateTestBase method createKJar.
protected ReleaseId createKJar(String... pairs) throws IOException {
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel();
KieFileSystem kfs = ks.newKieFileSystem();
for (int i = 0; i < pairs.length; i += 2) {
String id = pairs[i];
String rule = pairs[i + 1];
kfs.write("src/main/resources/" + id.replaceAll("\\.", "/") + "/rule" + i + ".drl", rule);
KieBaseModel kBase1 = kproj.newKieBaseModel(id).setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM).addPackage(id);
KieSessionModel ksession1 = kBase1.newKieSessionModel(id + ".KSession1").setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("pseudo"));
}
kfs.writeKModuleXML(kproj.toXML());
// buildAll() automatically adds the module to the kieRepository
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertTrue(kieBuilder.getResults().getMessages().isEmpty());
KieModule kieModule = kieBuilder.getKieModule();
return kieModule.getReleaseId();
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class KieModuleRepoTest method createMockKieContainer.
private static KieContainerImpl createMockKieContainer(final ReleaseId projectReleaseId, final KieModuleRepo kieModuleRepo) throws Exception {
// kie module
final InternalKieModule mockKieProjectKieModule = mock(InternalKieModule.class);
final ResourceProvider mockKieProjectKieModuleResourceProvider = mock(ResourceProvider.class);
when(mockKieProjectKieModule.createResourceProvider()).thenReturn(mockKieProjectKieModuleResourceProvider);
// kie project
final KieModuleKieProject kieProject = new KieModuleKieProject(mockKieProjectKieModule);
final KieModuleKieProject mockKieProject = spy(kieProject);
doNothing().when(mockKieProject).init();
doReturn(projectReleaseId).when(mockKieProject).getGAV();
doReturn(new HashMap<String, KieBaseModel>()).when(mockKieProject).updateToModule(any(InternalKieModule.class));
// kie repository
final KieRepository kieRepository = new KieRepositoryImpl();
final Field kieModuleRepoField = KieRepositoryImpl.class.getDeclaredField("kieModuleRepo");
kieModuleRepoField.setAccessible(true);
kieModuleRepoField.set(kieRepository, kieModuleRepo);
kieModuleRepoField.setAccessible(false);
// kie container
final KieContainerImpl kieContainerImpl = new KieContainerImpl(mockKieProject, kieRepository);
return kieContainerImpl;
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class ChangeSetBuilderTest method createKieProjectWithPackages.
private KieModuleModel createKieProjectWithPackages(KieServices ks, ReleaseId releaseId) {
KieModuleModel kproj = ks.newKieModuleModel();
KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("KBase1").setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM).addPackage("org.pkg1");
KieSessionModel ksession1 = kieBaseModel1.newKieSessionModel("KSession1").setType(KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("realtime"));
return kproj;
}
Aggregations