Search in sources :

Example 76 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule 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 77 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.

the class KieRepositoryScannerTest method createKieJarWithRules.

private InternalKieModule createKieJarWithRules(KieServices ks, ReleaseId releaseId, ReleaseId depId) throws IOException {
    KieFileSystem kfs = createKieFileSystemWithKProject(ks);
    kfs.write("src/main/resources/KBase1/r1.drl", "package org.kie.test\n" + getDRLWithRules(3, 5));
    kfs.writePomXML(getPom(releaseId, depId));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    kieBuilder.buildAll();
    assertTrue(kieBuilder.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 78 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule 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 79 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.

the class KieRepositoryScannerTest method createIncludingKJar.

private InternalKieModule createIncludingKJar(ReleaseId containerReleaseId, ReleaseId includedReleaseId, String rule) {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    String file = "org/test/" + rule + ".drl";
    kfs.write("src/main/resources/KBase2/" + file, createDRL(rule));
    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());
    return (InternalKieModule) kieBuilder.getKieModule();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 80 with InternalKieModule

use of org.drools.compiler.kie.builder.impl.InternalKieModule in project drools by kiegroup.

the class KieRepositoryScannerTest method createKieJarWithGDRL.

private InternalKieModule createKieJarWithGDRL(KieServices ks, ReleaseId releaseId, String rule) throws IOException {
    KieFileSystem kfs = createKieFileSystemWithKProject(ks, false);
    kfs.writePomXML(getPom(releaseId));
    kfs.write("src/main/resources/rule.drl", rule);
    kfs.write("src/main/resources/global.gdrl", "global java.util.List list;");
    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)

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