Search in sources :

Example 71 with InternalKieModule

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);
}
Also used : KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieScanner(org.drools.compiler.kie.builder.impl.InternalKieScanner) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer)

Example 72 with InternalKieModule

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);
}
Also used : KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieScanner(org.drools.compiler.kie.builder.impl.InternalKieScanner) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer)

Example 73 with InternalKieModule

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);
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieScanner(org.drools.compiler.kie.builder.impl.InternalKieScanner) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 74 with InternalKieModule

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();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 75 with InternalKieModule

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);
}
Also used : KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)88 ReleaseId (org.kie.api.builder.ReleaseId)56 KieServices (org.kie.api.KieServices)51 Test (org.junit.Test)45 KieContainer (org.kie.api.runtime.KieContainer)40 KieFileSystem (org.kie.api.builder.KieFileSystem)31 KieSession (org.kie.api.runtime.KieSession)30 KieBuilder (org.kie.api.builder.KieBuilder)28 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)28 KieScanner (org.kie.api.builder.KieScanner)19 InternalKieScanner (org.drools.compiler.kie.builder.impl.InternalKieScanner)18 File (java.io.File)14 FileOutputStream (java.io.FileOutputStream)9 IOException (java.io.IOException)9 KieModule (org.kie.api.builder.KieModule)8 ArrayList (java.util.ArrayList)7 Resource (org.kie.api.io.Resource)7 KieRepositoryImpl (org.drools.compiler.kie.builder.impl.KieRepositoryImpl)6 KieServicesImpl (org.drools.compiler.kie.builder.impl.KieServicesImpl)5 Ignore (org.junit.Ignore)4