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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations