Search in sources :

Example 76 with ReleaseId

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

the class KieHelloWorldTest method testHelloWorldOnVersionRange.

@Test
public void testHelloWorldOnVersionRange() throws Exception {
    KieServices ks = KieServices.Factory.get();
    buildVersion(ks, "Hello World", "1.0");
    buildVersion(ks, "Aloha Earth", "1.1");
    buildVersion(ks, "Hi Universe", "1.2");
    ReleaseId latestReleaseId = ks.newReleaseId("org.kie", "hello-world", "LATEST");
    KieSession ksession = ks.newKieContainer(latestReleaseId).newKieSession("KSession1");
    ksession.insert(new Message("Hello World"));
    assertEquals(0, ksession.fireAllRules());
    ksession = ks.newKieContainer(latestReleaseId).newKieSession("KSession1");
    ksession.insert(new Message("Hi Universe"));
    assertEquals(1, ksession.fireAllRules());
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "hello-world", "1.0");
    ksession = ks.newKieContainer(releaseId1).newKieSession("KSession1");
    ksession.insert(new Message("Hello World"));
    assertEquals(1, ksession.fireAllRules());
    ksession = ks.newKieContainer(releaseId1).newKieSession("KSession1");
    ksession.insert(new Message("Hi Universe"));
    assertEquals(0, ksession.fireAllRules());
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "hello-world", "[1.0,1.2)");
    ksession = ks.newKieContainer(releaseId2).newKieSession("KSession1");
    ksession.insert(new Message("Aloha Earth"));
    assertEquals(1, ksession.fireAllRules());
    ksession = ks.newKieContainer(releaseId2).newKieSession("KSession1");
    ksession.insert(new Message("Hi Universe"));
    assertEquals(0, ksession.fireAllRules());
}
Also used : Message(org.drools.compiler.Message) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 77 with ReleaseId

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

the class KieHelloWorldTest method testHelloWorldWithWildcardPackagesComplex.

@Test
public void testHelloWorldWithWildcardPackagesComplex() throws Exception {
    // BZ-1174563
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "hello-world", "1.0-SNAPSHOT");
    KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/rules/rules.drl", createDrlWithGlobal("R1")).write("src/main/resources/rules/tests/tests.drl", createDrlWithGlobal("R2")).write("src/main/resources/aaarules/aaarules.drl", createDrlWithGlobal("R3")).write("src/main/resources/sample/brms601_1310778/rules/rules.drl", createDrlWithGlobal("R4")).write("src/main/resources/sample/brms601_1310778/tests/tests.drl", createDrlWithGlobal("R5")).write("src/main/resources/tests/tests.drl", createDrlWithGlobal("R6")).write("src/main/resources/rules2/rules2.drl", createDrlWithGlobal("R7")).writeKModuleXML(createKieProjectWithPackages(ks, "rules.*").toXML());
    ks.newKieBuilder(kfs).buildAll();
    KieSession ksession = ks.newKieContainer(releaseId).newKieSession("KSession1");
    ksession.insert(new Message("Hello World"));
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    assertEquals(2, ksession.fireAllRules());
    assertTrue(list.contains("R1"));
    assertTrue(list.contains("R2"));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.drools.compiler.Message) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 78 with ReleaseId

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

the class KieHelloWorldTest method testHelloWorldUsingPackages.

@Test
public void testHelloWorldUsingPackages() throws Exception {
    String drlDef = "package org.drools.compiler.integrationtests\n" + "import " + Message.class.getCanonicalName() + "\n" + "rule R_def when\n" + "   $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "hello-world", "1.0-SNAPSHOT");
    KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/KBase1/org/pkg1/r1_1.drl", drlDef).write("src/main/resources/KBase1/org/pkg1/r1_2.drl", createDrl("R1")).write("src/main/resources/KBase1/org/pkg2/r2.drl", createDrl("R2")).writeKModuleXML(createKieProjectWithPackages(ks, "org.pkg1").toXML());
    ks.newKieBuilder(kfs).buildAll();
    KieSession ksession = ks.newKieContainer(releaseId).newKieSession("KSession1");
    ksession.insert(new Message("Hello World"));
    assertEquals(2, ksession.fireAllRules());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.drools.compiler.Message) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 79 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 80 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)

Aggregations

ReleaseId (org.kie.api.builder.ReleaseId)273 Test (org.junit.Test)219 KieServices (org.kie.api.KieServices)214 KieContainer (org.kie.api.runtime.KieContainer)176 KieSession (org.kie.api.runtime.KieSession)137 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)117 KieModule (org.kie.api.builder.KieModule)84 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)73 KieFileSystem (org.kie.api.builder.KieFileSystem)64 KieModuleModel (org.kie.api.builder.model.KieModuleModel)40 KieBuilder (org.kie.api.builder.KieBuilder)34 ArrayList (java.util.ArrayList)32 Message (org.drools.compiler.Message)32 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)27 Resource (org.kie.api.io.Resource)23 Results (org.kie.api.builder.Results)20 KieBaseModel (org.kie.api.builder.model.KieBaseModel)20 InternalKieScanner (org.drools.compiler.kie.builder.impl.InternalKieScanner)18 KieScanner (org.kie.api.builder.KieScanner)18 IncrementalResults (org.kie.internal.builder.IncrementalResults)18