Search in sources :

Example 66 with KieBaseModel

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();
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder)

Example 67 with KieBaseModel

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;
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) EclipseJavaCompiler(org.drools.compiler.commons.jci.compilers.EclipseJavaCompiler) ArrayList(java.util.ArrayList) CompilationResult(org.drools.compiler.commons.jci.compilers.CompilationResult) Folder(org.drools.compiler.compiler.io.Folder) EclipseJavaCompilerSettings(org.drools.compiler.commons.jci.compilers.EclipseJavaCompilerSettings)

Example 68 with KieBaseModel

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();
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) KieModule(org.kie.api.builder.KieModule) KieSessionModel(org.kie.api.builder.model.KieSessionModel)

Example 69 with KieBaseModel

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;
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) Field(java.lang.reflect.Field) KieRepository(org.kie.api.builder.KieRepository) ResourceProvider(org.drools.core.common.ResourceProvider)

Example 70 with KieBaseModel

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;
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieSessionModel(org.kie.api.builder.model.KieSessionModel)

Aggregations

KieBaseModel (org.kie.api.builder.model.KieBaseModel)74 KieModuleModel (org.kie.api.builder.model.KieModuleModel)55 KieServices (org.kie.api.KieServices)45 KieFileSystem (org.kie.api.builder.KieFileSystem)31 Test (org.junit.Test)26 KieSessionModel (org.kie.api.builder.model.KieSessionModel)24 KieBuilder (org.kie.api.builder.KieBuilder)22 KieContainer (org.kie.api.runtime.KieContainer)22 ReleaseId (org.kie.api.builder.ReleaseId)20 KieSession (org.kie.api.runtime.KieSession)13 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)10 ArrayList (java.util.ArrayList)7 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7 KieBase (org.kie.api.KieBase)7 KieModule (org.kie.api.builder.KieModule)7 KieRepository (org.kie.api.builder.KieRepository)6 Before (org.junit.Before)5 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4