Search in sources :

Example 41 with ReleaseId

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

the class KieRepositoryTest method testLoadingNotAKJar.

@Test
public void testLoadingNotAKJar() {
    // DROOLS-1351
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { this.getClass().getResource("/only-jar-pojo-not-kjar-no-kmodule-1.0.0.jar") });
    Thread.currentThread().setContextClassLoader(urlClassLoader);
    try {
        KieServices ks = KieServices.Factory.get();
        KieRepository kieRepository = ks.getRepository();
        ReleaseId releaseId = ks.newReleaseId("org.test", "only-jar-pojo-not-kjar-no-kmodule", "1.0.0");
        KieModule kieModule = kieRepository.getKieModule(releaseId);
        assertNull(kieModule);
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : KieRepository(org.kie.api.builder.KieRepository) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 42 with ReleaseId

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

the class KieRepositoryTest method testLoadKjarFromClasspath.

@Test
public void testLoadKjarFromClasspath() {
    // DROOLS-1335
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { this.getClass().getResource("/kie-project-simple-1.0.0.jar") });
    Thread.currentThread().setContextClassLoader(urlClassLoader);
    try {
        KieServices ks = KieServices.Factory.get();
        KieRepository kieRepository = ks.getRepository();
        ReleaseId releaseId = ks.newReleaseId("org.test", "kie-project-simple", "1.0.0");
        KieModule kieModule = kieRepository.getKieModule(releaseId);
        assertNotNull(kieModule);
        assertEquals(releaseId, kieModule.getReleaseId());
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : KieRepository(org.kie.api.builder.KieRepository) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 43 with ReleaseId

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

the class KieRepositoryTest method testTryLoadNotExistingKjarFromClasspath.

@Test
public void testTryLoadNotExistingKjarFromClasspath() {
    // DROOLS-1335
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { this.getClass().getResource("/kie-project-simple-1.0.0.jar") });
    Thread.currentThread().setContextClassLoader(urlClassLoader);
    try {
        KieServices ks = KieServices.Factory.get();
        KieRepository kieRepository = ks.getRepository();
        ReleaseId releaseId = ks.newReleaseId("org.test", "kie-project-simple", "1.0.1");
        KieModule kieModule = kieRepository.getKieModule(releaseId);
        assertNull(kieModule);
    } finally {
        Thread.currentThread().setContextClassLoader(cl);
    }
}
Also used : KieRepository(org.kie.api.builder.KieRepository) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 44 with ReleaseId

use of org.kie.api.builder.ReleaseId 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 45 with ReleaseId

use of org.kie.api.builder.ReleaseId 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)

Aggregations

ReleaseId (org.kie.api.builder.ReleaseId)565 KieServices (org.kie.api.KieServices)449 Test (org.junit.Test)398 KieContainer (org.kie.api.runtime.KieContainer)313 KieSession (org.kie.api.runtime.KieSession)234 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)159 KieFileSystem (org.kie.api.builder.KieFileSystem)132 ArrayList (java.util.ArrayList)120 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)100 KieModule (org.kie.api.builder.KieModule)94 KieBuilder (org.kie.api.builder.KieBuilder)86 KieModuleModel (org.kie.api.builder.model.KieModuleModel)85 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)76 File (java.io.File)75 Resource (org.kie.api.io.Resource)53 KieMavenRepository (org.kie.scanner.KieMavenRepository)53 FileOutputStream (java.io.FileOutputStream)51 KieBase (org.kie.api.KieBase)47 Before (org.junit.Before)39 HashMap (java.util.HashMap)31