use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class KieRepositoryScannerTest method checkUpdateDRLInSameSession.
private void checkUpdateDRLInSameSession(String drl1, String drl2) throws IOException {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT");
InternalKieModule kJar1 = createKieJarFromDrl(ks, releaseId, drl1);
KieMavenRepository repository = getKieMavenRepository();
repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieScanner scanner = ks.newKieScanner(kieContainer);
KieSession ksession = kieContainer.newKieSession("KSession1");
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.insert("111");
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("XXX:111", list.get(0));
list.clear();
InternalKieModule kJar2 = createKieJarFromDrl(ks, releaseId, drl2);
repository.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
scanner.scanNow();
ksession.insert("222");
ksession.fireAllRules();
assertEquals(2, list.size());
assertTrue(list.containsAll(asList("YYY:111", "YYY:222")));
ks.getRepository().removeKieModule(releaseId);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class KieRepositoryScannerTest method testKScannerWithType.
private void testKScannerWithType(boolean useTypeDeclaration) throws Exception {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT");
InternalKieModule kJar1 = createKieJarWithClass(ks, releaseId, useTypeDeclaration, 2, 7);
KieMavenRepository repository = getKieMavenRepository();
repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieScanner scanner = ks.newKieScanner(kieContainer);
KieSession ksession = kieContainer.newKieSession("KSession1");
checkKSession(ksession, 14);
InternalKieModule kJar2 = createKieJarWithClass(ks, releaseId, useTypeDeclaration, 3, 5);
repository.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
scanner.scanNow();
KieSession ksession2 = kieContainer.newKieSession("KSession1");
checkKSession(ksession2, 15);
ks.getRepository().removeKieModule(releaseId);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class KieRepositoryScannerTest method testScanIncludedDependency.
@Test
public void testScanIncludedDependency() throws Exception {
KieMavenRepository repository = getKieMavenRepository();
KieServices ks = KieServices.Factory.get();
ReleaseId containerReleaseId = KieServices.Factory.get().newReleaseId("org.kie", "test-container", "1.0.0-SNAPSHOT");
ReleaseId includedReleaseId = KieServices.Factory.get().newReleaseId("org.kie", "test-project", "1.0.0-SNAPSHOT");
InternalKieModule kJar1 = createKieJar(ks, includedReleaseId, "rule1");
repository.installArtifact(includedReleaseId, kJar1, createKPom(fileManager, includedReleaseId));
resetFileManager();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kproj = ks.newKieModuleModel();
kproj.newKieBaseModel("KBase2").addInclude("KBase1").newKieSessionModel("KSession2");
kfs.writeKModuleXML(kproj.toXML());
kfs.writePomXML(getPom(containerReleaseId, includedReleaseId));
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty());
InternalKieModule containerKJar = (InternalKieModule) kieBuilder.getKieModule();
repository.installArtifact(containerReleaseId, containerKJar, createKPom(fileManager, containerReleaseId, includedReleaseId));
KieContainer kieContainer = ks.newKieContainer(containerReleaseId);
KieSession ksession = kieContainer.newKieSession("KSession2");
checkKSession(ksession, "rule1");
KieScanner scanner = ks.newKieScanner(kieContainer);
InternalKieModule kJar2 = createKieJar(ks, includedReleaseId, "rule2");
repository.installArtifact(includedReleaseId, kJar2, createKPom(fileManager, includedReleaseId));
scanner.scanNow();
KieSession ksession2 = kieContainer.newKieSession("KSession2");
checkKSession(ksession2, "rule2");
ks.getRepository().removeKieModule(containerReleaseId);
ks.getRepository().removeKieModule(includedReleaseId);
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class KieRepositoryScannerTest method createKieJarFromDrl.
private InternalKieModule createKieJarFromDrl(KieServices ks, ReleaseId releaseId, String drl) throws IOException {
KieFileSystem kfs = createKieFileSystemWithKProject(ks, false);
kfs.writePomXML(getPom(releaseId));
kfs.write("src/main/resources/KBase1/rule1.drl", drl);
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty());
return (InternalKieModule) kieBuilder.getKieModule();
}
use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.
the class KieRepositoryScannerTest method testLoadKieJarFromMavenRepo.
@Test
public void testLoadKieJarFromMavenRepo() throws Exception {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT");
final String drl = " global java.util.List list; \n" + " rule R1 \n" + " when \n" + " not(String()) \n" + " then \n" + " list.add(15);\n" + " end ";
InternalKieModule kJar1 = createKieJarFromDrl(ks, releaseId, drl);
KieMavenRepository repository = getKieMavenRepository();
repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieSession ksession2 = kieContainer.newKieSession("KSession1");
checkKSession(ksession2, 15);
ks.getRepository().removeKieModule(releaseId);
}
Aggregations