Search in sources :

Example 16 with KieScanner

use of org.kie.api.builder.KieScanner 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 17 with KieScanner

use of org.kie.api.builder.KieScanner 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 18 with KieScanner

use of org.kie.api.builder.KieScanner in project drools by kiegroup.

the class KieRepositoryScannerTest method testReleaseDowngrade.

@Test
public void testReleaseDowngrade() throws Exception {
    // DROOLS-1720
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "downgrade-test", "1.1");
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "downgrade-test", "1.2");
    ReleaseId kcRelId = ks.newReleaseId("org.kie", "downgrade-test", "[1.0,)");
    final String drl1 = "global java.util.List list; \n" + "rule R1 when then \n" + "    list.add(1);\n" + "end ";
    final String drl2 = "global java.util.List list; \n" + "rule R1 when then \n" + "    list.add(2);\n" + "end ";
    InternalKieModule kJar1 = createKieJarFromDrl(ks, releaseId1, drl1);
    InternalKieModule kJar2 = createKieJarFromDrl(ks, releaseId2, drl2);
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId1, kJar1, createKPom(fileManager, releaseId1));
    repository.installArtifact(releaseId2, kJar2, createKPom(fileManager, releaseId2));
    KieContainer kieContainer = ks.newKieContainer(kcRelId);
    checkKSession(kieContainer.newKieSession("KSession1"), 2);
    kieContainer.updateToVersion(releaseId1);
    checkKSession(kieContainer.newKieSession("KSession1"), 1);
    KieScanner kieScanner = ks.newKieScanner(kieContainer);
    kieScanner.scanNow();
    checkKSession(kieContainer.newKieSession("KSession1"), 2);
    kieContainer.updateToVersion(releaseId1);
    checkKSession(kieContainer.newKieSession("KSession1"), 1);
    kieScanner.scanNow();
    checkKSession(kieContainer.newKieSession("KSession1"), 2);
    ks.getRepository().removeKieModule(releaseId1);
    ks.getRepository().removeKieModule(releaseId2);
}
Also used : KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieServices(org.kie.api.KieServices) 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) Test(org.junit.Test)

Example 19 with KieScanner

use of org.kie.api.builder.KieScanner in project drools by kiegroup.

the class KieRepositoryScannerTest method testScannerOnPomProjectWithFixedVersion.

@Test
public void testScannerOnPomProjectWithFixedVersion() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "scanner-test", "1.0");
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "scanner-test", "2.0");
    KieMavenRepository repository = getKieMavenRepository();
    repository.deployPomArtifact("org.kie", "scanner-master-test", "1.0", createMasterKPom("scanner-test", "1.0"));
    resetFileManager();
    InternalKieModule kJar1 = createKieJarWithClass(ks, releaseId1, false, 2, 7);
    repository.installArtifact(releaseId1, kJar1, createKPom(fileManager, releaseId1));
    KieContainer kieContainer = ks.newKieContainer(ks.newReleaseId("org.kie", "scanner-master-test", "LATEST"));
    KieSession ksession = kieContainer.newKieSession("KSession1");
    checkKSession(ksession, 14);
    KieScanner scanner = ks.newKieScanner(kieContainer);
    repository.deployPomArtifact("org.kie", "scanner-master-test", "2.0", createMasterKPom("scanner-test", "2.0"));
    InternalKieModule kJar2 = createKieJarWithClass(ks, releaseId2, false, 3, 5);
    repository.installArtifact(releaseId2, kJar2, createKPom(fileManager, releaseId1));
    scanner.scanNow();
    KieSession ksession2 = kieContainer.newKieSession("KSession1");
    checkKSession(ksession2, 15);
    ks.getRepository().removeKieModule(releaseId1);
    ks.getRepository().removeKieModule(releaseId2);
}
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) Test(org.junit.Test)

Example 20 with KieScanner

use of org.kie.api.builder.KieScanner in project drools by kiegroup.

the class KieRepositoryScannerTest method testScannerOnPomProjectSameKieSession.

@Test
public void testScannerOnPomProjectSameKieSession() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "scanner-test", "1.0");
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "scanner-test", "2.0");
    KieMavenRepository repository = getKieMavenRepository();
    repository.deployPomArtifact("org.kie", "scanner-master-test", "1.0", createMasterKPom("scanner-test", "1.0"));
    resetFileManager();
    InternalKieModule kJar1 = createKieJarWithClass(ks, releaseId1, true, 2, 7);
    repository.installArtifact(releaseId1, kJar1, createKPom(fileManager, releaseId1));
    KieContainer kieContainer = ks.newKieContainer(ks.newReleaseId("org.kie", "scanner-master-test", "LATEST"));
    KieSession ksession = kieContainer.newKieSession("KSession1");
    checkKSession(false, ksession, 14);
    KieScanner scanner = ks.newKieScanner(kieContainer);
    repository.deployPomArtifact("org.kie", "scanner-master-test", "2.0", createMasterKPom("scanner-test", "2.0"));
    InternalKieModule kJar2 = createKieJarWithClass(ks, releaseId2, true, 3, 5);
    repository.installArtifact(releaseId2, kJar2, createKPom(fileManager, releaseId1));
    scanner.scanNow();
    checkKSession(ksession, 10, 15);
    ks.getRepository().removeKieModule(releaseId1);
    ks.getRepository().removeKieModule(releaseId2);
}
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) Test(org.junit.Test)

Aggregations

KieScanner (org.kie.api.builder.KieScanner)21 KieContainer (org.kie.api.runtime.KieContainer)21 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)20 KieServices (org.kie.api.KieServices)20 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)19 ReleaseId (org.kie.api.builder.ReleaseId)18 Test (org.junit.Test)17 InternalKieScanner (org.drools.compiler.kie.builder.impl.InternalKieScanner)16 KieSession (org.kie.api.runtime.KieSession)16 KieMavenRepository (org.kie.scanner.KieMavenRepository)4 ArrayList (java.util.ArrayList)3 Path (java.nio.file.Path)2 AbstractKieCiTest (org.kie.scanner.AbstractKieCiTest)2 HashMap (java.util.HashMap)1 Dependency (org.apache.maven.model.Dependency)1 MavenRepository (org.appformer.maven.integration.MavenRepository)1 MavenRepository.getMavenRepository (org.appformer.maven.integration.MavenRepository.getMavenRepository)1 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)1 Ignore (org.junit.Ignore)1 KieBuilder (org.kie.api.builder.KieBuilder)1