Search in sources :

Example 91 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class KieServicesTest method testDisposeClearTheIDReference.

@Test
public void testDisposeClearTheIDReference() {
    ReleaseId releaseId = ks.newReleaseId("org.kie", "test-delete", "1.0.0");
    createAndDeployJar(ks, releaseId, createDRL("ruleA"));
    KieContainer c1 = ks.newKieContainer("id1", releaseId);
    try {
        ks.newKieClasspathContainer("id1");
        fail("should not allow repeated container IDs.");
    } catch (IllegalStateException is) {
    // ok.
    }
    ((KieContainerImpl) c1).dispose();
    // now OK.
    ks.newKieClasspathContainer("id1");
}
Also used : KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) ReleaseId(org.kie.api.builder.ReleaseId) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 92 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class KieServicesTest method testGetKieClasspathIDs.

@Test
public void testGetKieClasspathIDs() {
    String myId = "myId";
    KieContainer c1 = ks.getKieClasspathContainer(myId);
    assertEquals(c1, ks.getKieClasspathContainer());
    assertEquals(c1, ks.getKieClasspathContainer(myId));
    try {
        ks.getKieClasspathContainer("invalid");
        fail("this is not the containerId for the global singleton.");
    } catch (IllegalStateException is) {
    // ok.
    }
}
Also used : KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 93 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class I18nTest method testKieModuleJar.

@Test
public void testKieModuleJar() {
    String str = "package org.drools.compiler.i18ntest;\n" + "import org.drools.compiler.I18nPerson;\n" + "\n" + "global java.util.List list;\n" + "rule \"名称 is 山田花子\"\n" + "    when\n" + "        p : I18nPerson( 名称 == \"山田花子\" )\n" + "    then\n" + "        list.add( \"名称は山田花子です\" );\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "118ntest", "1.0.0");
    byte[] jar = createKJar(ks, releaseId, null, str);
    KieModule km = deployJar(ks, jar);
    KieContainer kc = ks.newKieContainer(km.getReleaseId());
    KieSession ksession = kc.newKieSession();
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    I18nPerson i18nPerson = new I18nPerson();
    i18nPerson.set名称("山田花子");
    ksession.insert(i18nPerson);
    ksession.fireAllRules();
    assertTrue(list.contains("名称は山田花子です"));
    ksession.dispose();
}
Also used : I18nPerson(org.drools.compiler.I18nPerson) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 94 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class Misc2Test method testWiringClassOnPackageMerge.

@Test
public void testWiringClassOnPackageMerge() throws Exception {
    String drl_init = "package init;\n" + "import org.kie.test.TestObject\n" + "rule RInit when\n" + "then\n" + "    TestObject obj1 = new TestObject();\n" + "    TestObject obj2 = new TestObject();" + "    obj1.add(obj2);" + "    insert(obj1);\n" + "end";
    String drl1 = "package p1;\n" + "import org.kie.test.TestObject\n" + "global java.util.List list;\n" + "rule R1 when\n" + "    $obj : TestObject( $objs : objects )\n" + "    $s : Object() from $objs\n" + "then\n" + "    list.add(\"R1\");\n" + "end";
    String drl2 = "package p2;\n" + "import org.kie.test.TestObject\n" + "global java.util.List list;\n" + "rule R2 when\n" + "    $obj : TestObject( $objs : objects )\n" + "    $s : TestObject() from $objs\n" + "then\n" + "    list.add(\"R2\");\n" + "end";
    String javaSrc = "package org.kie.test;\n" + "import java.util.*;\n" + "\n" + "public class TestObject {\n" + "    private final List<TestObject> objects = new ArrayList<TestObject>();\n" + "\n" + "    public List<TestObject> getObjects() {\n" + "        return objects;\n" + "    }\n" + "    public void add(TestObject obj) {\n" + "        objects.add(obj);" + "    }" + "}\n";
    String path = "org/kie/test/MyRuleUnit";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.writeKModuleXML(ks.newKieModuleModel().toXML()).write("src/main/resources/a.drl", drl_init).write("src/main/resources/b.drl", drl1).write("src/main/resources/c.drl", drl2).write("src/main/java/org/kie/test/TestObject.java", javaSrc);
    ks.newKieBuilder(kfs).buildAll();
    KieContainer kcontainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    KieSession kSession = kcontainer.newKieSession();
    List<String> list = new ArrayList<String>();
    kSession.setGlobal("list", list);
    kSession.fireAllRules();
    assertEquals(2, list.size());
    assertTrue(list.contains("R1"));
    assertTrue(list.contains("R2"));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 95 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class Misc2Test method testPackagingJarWithTypeDeclarations.

@Test
public void testPackagingJarWithTypeDeclarations() throws Exception {
    // BZ-1054823
    String drl1 = "package org.drools.compiler\n" + "import org.drools.compiler.Message\n" + "declare Message\n" + "   @role (event)\n" + "end\n" + "rule R1 when\n" + "   $m : Message()\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    // Create an in-memory jar for version 1.0.0
    ReleaseId releaseId = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
    byte[] jar = createKJar(ks, releaseId, null, drl1);
    KieModule km = deployJar(ks, jar);
    // Create a session and fire rules
    KieContainer kc = ks.newKieContainer(km.getReleaseId());
    KieSession ksession = kc.newKieSession();
    ksession.insert(new Message("Hello World"));
    ksession.fireAllRules();
}
Also used : Message(org.drools.compiler.Message) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

KieContainer (org.kie.api.runtime.KieContainer)357 KieServices (org.kie.api.KieServices)271 Test (org.junit.Test)246 KieSession (org.kie.api.runtime.KieSession)191 ReleaseId (org.kie.api.builder.ReleaseId)185 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)108 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)90 KieFileSystem (org.kie.api.builder.KieFileSystem)81 KieModule (org.kie.api.builder.KieModule)75 KieBuilder (org.kie.api.builder.KieBuilder)56 KieModuleModel (org.kie.api.builder.model.KieModuleModel)54 KieBase (org.kie.api.KieBase)49 ArrayList (java.util.ArrayList)44 Results (org.kie.api.builder.Results)40 Resource (org.kie.api.io.Resource)29 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)29 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)27 Message (org.drools.compiler.Message)26 KieBaseModel (org.kie.api.builder.model.KieBaseModel)26 InternalKieContainer (org.drools.core.impl.InternalKieContainer)25