Search in sources :

Example 46 with KieModule

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

the class DynamicRuleLoadTest method testKJarUpgrade.

@Test
public void testKJarUpgrade() throws Exception {
    // DROOLS-919
    KieServices ks = KieServices.Factory.get();
    // Create an in-memory jar for version 1.0.0
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
    KieModule km = createAndDeployJar(ks, releaseId1, drl1, drl2_1);
    // Create a session and fire rules
    kieContainer = ks.newKieContainer(km.getReleaseId());
    ksession = kieContainer.newKieSession();
    ksession.setGlobal("test", this);
    ksession.insert(new Message("Hi Universe"));
    ksession.fireAllRules();
    assertTrue(done);
}
Also used : Message(org.drools.compiler.Message) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 47 with KieModule

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

the class DynamicRuleLoadTest method testKJarUpgradeWithJavaClass.

@Test
public void testKJarUpgradeWithJavaClass() throws Exception {
    KieServices ks = KieServices.Factory.get();
    String kmodule = "<kmodule xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" + "         xmlns=\"http://www.drools.org/xsd/kmodule\">\n" + "  <kbase name=\"kbase1\">\n" + "    <ksession name=\"ksession1\" default=\"true\"/>\n" + "  </kbase>\n" + "</kmodule>";
    // Create an in-memory jar for version 1.0.0
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade-java", "1.0.0");
    Resource javaResource = ResourceFactory.newByteArrayResource(javaSrc.getBytes()).setResourceType(ResourceType.JAVA).setSourcePath("org/drools/compiler/test/PersonObject.java");
    Resource drlResource = ResourceFactory.newByteArrayResource(person_drl.getBytes()).setResourceType(ResourceType.DRL).setSourcePath("kbase1/person.drl");
    KieModule km = createAndDeployJar(ks, kmodule, releaseId1, javaResource, drlResource);
    // Create a session and fire rules
    kieContainer = ks.newKieContainer(km.getReleaseId());
    ksession = kieContainer.newKieSession();
    Class<?> clazz = kieContainer.getClassLoader().loadClass("org.drools.compiler.test.PersonObject");
    Object person = clazz.newInstance();
    ksession.insert(person);
    ksession.fireAllRules();
    assertNotNull(person);
    Object personId = valueOf(person, "id");
    assertNotNull(personId);
    assertEquals("Person from version 1", personId);
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade-java", "1.1.0");
    Resource javaResource2 = ResourceFactory.newByteArrayResource(javaSrc_2.getBytes()).setResourceType(ResourceType.JAVA).setSourcePath("org/drools/compiler/test/PersonObject.java");
    Resource drlResource2 = ResourceFactory.newByteArrayResource(person_drl.getBytes()).setResourceType(ResourceType.DRL).setSourcePath("kbase1/person.drl");
    createAndDeployJar(ks, kmodule, releaseId2, javaResource2, drlResource2);
    // update container
    kieContainer.updateToVersion(releaseId2);
    assertEquals(releaseId2, kieContainer.getReleaseId());
    // now let's run the rules
    ksession = kieContainer.newKieSession();
    person = kieContainer.getClassLoader().loadClass("org.drools.compiler.test.PersonObject").newInstance();
    ksession.insert(person);
    ksession.fireAllRules();
    assertNotNull(person);
    personId = valueOf(person, "id");
    assertNotNull(personId);
    assertEquals("Person from version 2", personId);
}
Also used : Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) Test(org.junit.Test)

Example 48 with KieModule

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

the class CommonTestMethodBase method deployJarIntoRepository.

private static KieModule deployJarIntoRepository(KieServices ks, byte[] jar) {
    Resource jarRes = ks.getResources().newByteArrayResource(jar);
    KieModule km = ks.getRepository().addKieModule(jarRes);
    return km;
}
Also used : Resource(org.kie.api.io.Resource) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule)

Example 49 with KieModule

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

the class CommonTestMethodBase method createAndDeployJar.

public static KieModule createAndDeployJar(KieServices ks, ReleaseId releaseId, String... drls) {
    byte[] jar = createJar(ks, releaseId, drls);
    // Deploy jar into the repository
    KieModule km = deployJarIntoRepository(ks, jar);
    return km;
}
Also used : InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule)

Example 50 with KieModule

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

the class CommonTestMethodBase method createAndDeployJar.

public static KieModule createAndDeployJar(KieServices ks, String kmoduleContent, Predicate<String> classFilter, ReleaseId releaseId, Resource... resources) {
    byte[] jar = createJar(ks, kmoduleContent, classFilter, releaseId, resources);
    KieModule km = deployJarIntoRepository(ks, jar);
    return km;
}
Also used : InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule)

Aggregations

KieModule (org.kie.api.builder.KieModule)124 KieServices (org.kie.api.KieServices)104 Test (org.junit.Test)94 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)84 ReleaseId (org.kie.api.builder.ReleaseId)84 KieContainer (org.kie.api.runtime.KieContainer)75 KieSession (org.kie.api.runtime.KieSession)64 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)53 Message (org.drools.compiler.Message)25 KieFileSystem (org.kie.api.builder.KieFileSystem)23 Resource (org.kie.api.io.Resource)20 ArrayList (java.util.ArrayList)15 KieModuleModel (org.kie.api.builder.model.KieModuleModel)15 KieBuilder (org.kie.api.builder.KieBuilder)13 KieRepository (org.kie.api.builder.KieRepository)10 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)7 KieBaseModel (org.kie.api.builder.model.KieBaseModel)7 KieBase (org.kie.api.KieBase)6 List (java.util.List)5 Results (org.kie.api.builder.Results)5