use of org.kie.api.builder.ReleaseId in project drools by kiegroup.
the class KieBuilderTest method testMultipleKBaseWithDrlError.
@Test
public void testMultipleKBaseWithDrlError() {
// RHBRMS-2651
final String drl = "package org.drools.compiler;\n" + "rule \"test\"\n" + " when\n" + " Smurf\n" + " then\n" + "end";
final KieServices ks = KieServices.Factory.get();
final KieModuleModel kproj = ks.newKieModuleModel();
kproj.newKieBaseModel("kbase1").newKieSessionModel("ksession1").setDefault(true);
kproj.newKieBaseModel("kbase2").newKieSessionModel("ksession2");
final ReleaseId releaseId = ks.newReleaseId("org.kie", "test-kie-builder", "1.0.0");
final KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).writeKModuleXML(kproj.toXML());
final Resource drlResource = ResourceFactory.newByteArrayResource(drl.getBytes()).setResourceType(ResourceType.DRL).setSourcePath("kbase1/drl1.drl");
kfs.write("src/main/resources/org/drools/compiler/drl1.drl", drlResource);
final KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
final List<org.kie.api.builder.Message> messages = kb.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR);
assertEquals(4, messages.size());
assertTrue(messages.get(0).toString().contains("kbase1"));
assertTrue(messages.get(1).toString().contains("kbase1"));
assertTrue(messages.get(2).toString().contains("kbase2"));
assertTrue(messages.get(3).toString().contains("kbase2"));
}
use of org.kie.api.builder.ReleaseId in project drools by kiegroup.
the class KieBuilderTest method testStatelessSessionDeclarativeChannelRegistration.
@Test
public void testStatelessSessionDeclarativeChannelRegistration() {
final String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
final 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\" type=\"stateless\">\n" + " <channels>\n" + " <channel name=\"testChannel\" type=\"org.drools.compiler.integrationtests.KieBuilderTest$MockChannel\" />\n" + " </channels>\n" + " </ksession>" + " </kbase>\n" + "</kmodule>";
final KieServices ks = KieServices.Factory.get();
final ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-kie-builder", "1.0.0");
final Resource r1 = ResourceFactory.newByteArrayResource(drl1.getBytes()).setResourceType(ResourceType.DRL).setSourcePath("kbase1/drl1.drl");
final KieModule km = createAndDeployJar(ks, kmodule, releaseId1, r1);
KieContainer kieContainer = ks.newKieContainer(km.getReleaseId());
StatelessKieSession statelessKieSession = kieContainer.newStatelessKieSession();
assertEquals(1, statelessKieSession.getChannels().size());
assertTrue(statelessKieSession.getChannels().keySet().contains("testChannel"));
}
use of org.kie.api.builder.ReleaseId in project drools by kiegroup.
the class KieCompilationCacheTest method testCacheWigAccumulate.
@Test
public void testCacheWigAccumulate() throws Exception {
String drl1 = "package org.drools.compiler.integrationtests\n" + "rule R11 when\n" + " Number() from accumulate(String(), \n" + " init(int x = 0;)," + " action(x++;)," + " reverse(x--;)," + " result(x))\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "cache-accumulate", "1.0-SNAPSHOT");
KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/KBase1/org/pkg1/r1.drl", drl1).writeKModuleXML(createKieProjectWithPackagesAnd2KieBases(ks).toXML());
ks.newKieBuilder(kfs).buildAll();
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
MemoryFileSystem mfs = MemoryFileSystem.readFromJar(jar);
File file = mfs.getFile(KieBuilderImpl.getCompilationCachePath(releaseId, "KBase1"));
assertNotNull(file);
Resource jarRes = ks.getResources().newByteArrayResource(jar);
KieModule km = ks.getRepository().addKieModule(jarRes);
KieSession ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession1");
ksession.insert(new String("Hello World"));
assertEquals(1, ksession.fireAllRules());
}
use of org.kie.api.builder.ReleaseId in project drools by kiegroup.
the class KieCompilationCacheTest method testHelloWorldWithPackagesAnd2KieBases.
@Test
public void testHelloWorldWithPackagesAnd2KieBases() throws Exception {
String drl1 = "package org.drools.compiler.integrationtests\n" + "import " + Message.class.getCanonicalName() + "\n" + "rule R11 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n" + "rule R12 when\n" + " $m : Message( message == \"Hi Universe\" )\n" + "then\n" + "end\n";
String drl2 = "package org.drools.compiler.integrationtests\n" + "import " + Message.class.getCanonicalName() + "\n" + "rule R21 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n" + "rule R22 when\n" + " $m : Message( message == \"Aloha Earth\" )\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.drl", drl1).write("src/main/resources/KBase1/org/pkg2/r2.drl", drl2).writeKModuleXML(createKieProjectWithPackagesAnd2KieBases(ks).toXML());
ks.newKieBuilder(kfs).buildAll();
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
MemoryFileSystem mfs = MemoryFileSystem.readFromJar(jar);
File file = mfs.getFile(KieBuilderImpl.getCompilationCachePath(releaseId, "KBase1"));
assertNotNull(file);
file = mfs.getFile(KieBuilderImpl.getCompilationCachePath(releaseId, "KBase2"));
assertNotNull(file);
Resource jarRes = ks.getResources().newByteArrayResource(jar);
KieModule km = ks.getRepository().addKieModule(jarRes);
KieSession ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession1");
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession1");
ksession.insert(new Message("Hi Universe"));
assertEquals(1, ksession.fireAllRules());
ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession1");
ksession.insert(new Message("Aloha Earth"));
assertEquals(0, ksession.fireAllRules());
ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession2");
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession2");
ksession.insert(new Message("Hi Universe"));
assertEquals(0, ksession.fireAllRules());
ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession2");
ksession.insert(new Message("Aloha Earth"));
assertEquals(1, ksession.fireAllRules());
}
use of org.kie.api.builder.ReleaseId in project drools by kiegroup.
the class KieContainerTest method testUpdateToNonExistingRelease.
@Test
public void testUpdateToNonExistingRelease() {
// DROOLS-1562
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "test-release", "1.0.0");
createAndDeployJar(ks, releaseId, createDRL("ruleA"));
KieContainer kieContainer = ks.newKieContainer(releaseId);
Results results = kieContainer.updateToVersion(ks.newReleaseId("org.kie", "test-release", "1.0.1"));
assertEquals(1, results.getMessages(Level.ERROR).size());
assertEquals("1.0.0", ((InternalKieContainer) kieContainer).getContainerReleaseId().getVersion());
}
Aggregations