Search in sources :

Example 26 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.

the class MBeansMonitoringTest method testEventOffset.

@Test
public void testEventOffset() throws Exception {
    String drl = "package org.drools.compiler.test\n" + "import org.drools.compiler.StockTick\n" + "declare StockTick\n" + "    @role(event)\n" + "    @expires(10s)\n" + "end\n" + "rule X\n" + "when\n" + "    StockTick()\n" + "then\n" + "end";
    KieServices ks = KieServices.Factory.get();
    KieModuleModel kproj = ks.newKieModuleModel();
    KieBaseModel kieBaseModel1 = kproj.newKieBaseModel(KBASE1).setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
    KieSessionModel ksession1 = kieBaseModel1.newKieSessionModel(KSESSION1).setDefault(true).setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
    ReleaseId releaseId1 = ks.newReleaseId("org.kie.test", "mbeans", "1.0.0");
    createKJar(ks, kproj, releaseId1, null, drl);
    KieContainer kc = ks.newKieContainer(releaseId1);
    KieBase kiebase = kc.getKieBase(KBASE1);
    MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
    ObjectName kbOn = DroolsManagementAgent.createObjectNameFor((InternalKnowledgeBase) kiebase);
    mbserver.invoke(kbOn, "startInternalMBeans", new Object[0], new String[0]);
    Object expOffset = mbserver.getAttribute(new ObjectName(kbOn + ",group=EntryPoints,EntryPoint=DEFAULT,ObjectType=org.drools.compiler.StockTick"), "ExpirationOffset");
    assertEquals(10001, ((Number) expOffset).longValue());
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBase(org.kie.api.KieBase) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieSessionModel(org.kie.api.builder.model.KieSessionModel) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieContainer(org.kie.api.runtime.KieContainer) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 27 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.

the class KieBuilderTest method testNotExistingInclude.

@Test
public void testNotExistingInclude() throws Exception {
    String drl = "package org.drools.compiler.integrationtests\n" + "declare CancelFact\n" + " cancel : boolean = true\n" + "end\n" + "rule R1 when\n" + " $m : CancelFact( cancel == true )\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
    KieModuleModel module = ks.newKieModuleModel();
    final String defaultBaseName = "defaultKBase";
    KieBaseModel defaultBase = module.newKieBaseModel(defaultBaseName).addInclude("notExistingKB1").addInclude("notExistingKB2");
    defaultBase.setDefault(true);
    defaultBase.addPackage("*");
    defaultBase.newKieSessionModel("defaultKSession").setDefault(true);
    kfs.writeKModuleXML(module.toXML());
    KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
    assertEquals(2, kb.getResults().getMessages().size());
}
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) Test(org.junit.Test)

Example 28 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.

the class KieBuilderTest method testNoPomXml.

@Test
public void testNoPomXml() throws ClassNotFoundException, InterruptedException, IOException {
    String namespace = "org.kie.test";
    KieModuleModel kProj = createKieProject(namespace);
    ReleaseId releaseId = KieServices.Factory.get().getRepository().getDefaultReleaseId();
    KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
    generateKProjectXML(kfs, namespace, kProj);
    generateMessageClass(kfs, namespace);
    generateRule(kfs, namespace);
    MemoryFileSystem mfs = ((KieFileSystemImpl) kfs).asMemoryFileSystem();
    createAndTestKieContainer(releaseId, createKieBuilder(kfs), namespace);
}
Also used : MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) KieFileSystem(org.kie.api.builder.KieFileSystem) KieFileSystemImpl(org.drools.compiler.kie.builder.impl.KieFileSystemImpl) KieModuleModel(org.kie.api.builder.model.KieModuleModel) ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 29 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.

the class KieBuilderTest method testInvalidProjectXml.

@Test
public void testInvalidProjectXml() throws ClassNotFoundException, InterruptedException, IOException {
    String namespace = "org.kie.test";
    KieModuleModel kProj = createKieProject(namespace);
    ReleaseId releaseId = KieServices.Factory.get().newReleaseId(namespace, "memory", "1.0-SNAPSHOT");
    KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
    generatePomXML(kfs, releaseId);
    kfs.writeKModuleXML("xxxx");
    generateMessageClass(kfs, namespace);
    generateRule(kfs, namespace);
    KieBuilder kieBuilder = createKieBuilder(kfs);
    kieBuilder.buildAll();
    assertTrue(kieBuilder.getResults().hasMessages(Level.ERROR));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 30 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.

the class CepEspTest method testThrowsWhenCreatingKieBaseUsingWindowsInCloudMode.

@Test
public void testThrowsWhenCreatingKieBaseUsingWindowsInCloudMode() {
    String drl = "declare TestEvent\n" + "    @role( event )\n" + "    name : String\n" + "end\n" + "\n" + "rule R when\n" + "        TestEvent ( name == \"EventA\" ) over window:time( 1s ) from entry-point EventStream\n" + "    then\n" + "        // consequence\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    KieModuleModel kieModule = ks.newKieModuleModel();
    KieBaseModel defaultBase = kieModule.newKieBaseModel("KBase").setDefault(true).addPackage("*").setEventProcessingMode(EventProcessingOption.CLOUD);
    defaultBase.newKieSessionModel("KSession").setClockType(ClockTypeOption.get("pseudo")).setDefault(true);
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
    kfs.writeKModuleXML(kieModule.toXML());
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    try {
        kieContainer.getKieBase("KBase");
        fail("Should throw a RuntimeException because the CLOUD kbase is trying to use features only available in STREAM mode");
    } catch (Exception e) {
    }
}
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) IOException(java.io.IOException) ParseException(java.text.ParseException) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

KieModuleModel (org.kie.api.builder.model.KieModuleModel)126 KieFileSystem (org.kie.api.builder.KieFileSystem)78 KieServices (org.kie.api.KieServices)76 Test (org.junit.Test)67 KieBuilder (org.kie.api.builder.KieBuilder)56 KieBaseModel (org.kie.api.builder.model.KieBaseModel)55 KieContainer (org.kie.api.runtime.KieContainer)50 ReleaseId (org.kie.api.builder.ReleaseId)38 KieSession (org.kie.api.runtime.KieSession)27 KieSessionModel (org.kie.api.builder.model.KieSessionModel)25 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)18 InternalKieContainer (org.drools.core.impl.InternalKieContainer)14 KieModule (org.kie.api.builder.KieModule)14 KieBase (org.kie.api.KieBase)11 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)10 Results (org.kie.api.builder.Results)10 Resource (org.kie.api.io.Resource)9 ArrayList (java.util.ArrayList)8 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)8 Before (org.junit.Before)7