use of org.kie.api.builder.ReleaseId in project drools by kiegroup.
the class ReleaseIdTest method testAscendingSort.
@Test
public void testAscendingSort() {
List<ReleaseId> list = newUnsortedList();
list.sort(new ReleaseIdComparator(ASCENDING));
assertSame(gav0, list.get(0));
assertSame(gav1, list.get(1));
assertSame(gav2, list.get(2));
assertSame(gav3, list.get(3));
assertSame(gav4, list.get(4));
assertSame(gav5, list.get(5));
assertSame(gav6, list.get(6));
assertSame(gav7, list.get(7));
}
use of org.kie.api.builder.ReleaseId in project drools by kiegroup.
the class KieBaseIncludesTest method testKieBaseIncludesCrossKJarDifferentPackageNames.
/**
* Test the inclusion of a KieBase defined in one KJAR into the KieBase of another KJAR.
* <p/>
* The 2 KieBases use different package names for the rules (i.e. "rules" and "rules2").
*/
@Test
public void testKieBaseIncludesCrossKJarDifferentPackageNames() {
// @formatter:off
String pomContent1 = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n" + "<modelVersion>4.0.0</modelVersion>\n" + "<groupId>org.kie</groupId>\n" + "<artifactId>rules-1</artifactId>\n" + "<version>1.0.0</version>\n" + "<packaging>jar</packaging>\n" + "<dependencies>\n" + "<dependency>\n" + "<groupId>org.kie</groupId>\n" + "<artifactId>rules-2</artifactId>\n" + "<version>1.0.0</version>\n" + "</dependency>\n" + "</dependencies>\n" + "</project>\n";
String kmoduleContent1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kmodule xmlns=\"http://jboss.org/kie/6.0.0/kmodule\">\n" + "<kbase name=\"kbase1\" equalsBehavior=\"equality\" default=\"true\" packages=\"rules\" includes=\"kbase2\">\n" + "<ksession name=\"ksession1\" default=\"true\" type=\"stateful\"/>\n" + "</kbase>\n" + "</kmodule>";
String drl1 = "package org.jboss.ddoyle.drools.rules1\n" + "\n" + "rule \"Rule in KieBase 1\"\n" + "when\n" + "then\n" + "System.out.println(\"Rule in KieBase1\");\n" + "end";
String kmoduleContent2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<kmodule xmlns=\"http://jboss.org/kie/6.0.0/kmodule\">\n" + "<kbase name=\"kbase2\" equalsBehavior=\"equality\" default=\"false\" packages=\"rules2\">\n" + "<ksession name=\"ksession2\" default=\"false\" type=\"stateful\"/>\n" + "</kbase>\n" + "</kmodule>";
String drl2 = "package org.jboss.ddoyle.drools.rules2\n" + "\n" + "rule \"Rule in KieBase 2\"\n" + "when\n" + "then\n" + "System.out.println(\"Rule in KieBase2\");\n" + "end";
// @formatter:on
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "rules-1", "1.0.0");
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "rules-2", "1.0.0");
// First deploy the second KJAR on which the first one depends.
KieFileSystem kfs2 = ks.newKieFileSystem().generateAndWritePomXML(releaseId2).write("src/main/resources/rules2/rules.drl", drl2).writeKModuleXML(kmoduleContent2);
ks.newKieBuilder(kfs2).buildAll();
KieFileSystem kfs1 = ks.newKieFileSystem().writePomXML(pomContent1).write("src/main/resources/rules/rules.drl", drl1).writeKModuleXML(kmoduleContent1);
ks.newKieBuilder(kfs1).buildAll();
KieContainer kc = ks.newKieContainer(releaseId1);
KieBase kieBase = kc.getKieBase();
// Assert the number of rules in the KieBase.
long nrOfRules = getNumberOfRules(kieBase);
// We should have 2 rules in our KieBase. One from our own DRL and one from the DRL in the KieBase we've included.
assertEquals(2, nrOfRules);
}
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());
}
Aggregations