Search in sources :

Example 6 with KieScanner

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

the class KieRepositoryScannerTest method testKScannerWithGDRL.

@Test
public void testKScannerWithGDRL() throws Exception {
    // BZ-1310261
    String rule1 = "import java.util.List;\n" + "rule R when\n" + "  $s : String()\n" + "then\n" + "  list.add(\"Hello \" + $s);\n" + "end";
    String rule2 = "import java.util.List;\n" + "rule R when\n" + "  $s : String()\n" + "then\n" + "  list.add(\"Hi \" + $s);\n" + "end";
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJarWithGDRL(ks, releaseId, rule1);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
    // create a ksesion and check it works as expected
    KieSession ksession = kieContainer.newKieSession("KSession1");
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ksession.insert("Mario");
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals("Hello Mario", list.get(0));
    list.clear();
    ksession.dispose();
    // create a new kjar
    InternalKieModule kJar2 = createKieJarWithGDRL(ks, releaseId, rule2);
    // deploy it on maven
    repository.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
    // since I am not calling start() on the scanner it means it won't have automatic scheduled scanning
    KieScanner scanner = ks.newKieScanner(kieContainer);
    // scan the maven repo to get the new kjar version and deploy it on the kcontainer
    scanner.scanNow();
    // create a ksesion and check it works as expected
    // create a ksesion and check it works as expected
    ksession = kieContainer.newKieSession("KSession1");
    list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ksession.insert("Mario");
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals("Hi Mario", list.get(0));
    list.clear();
    ksession.dispose();
    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) Test(org.junit.Test)

Example 7 with KieScanner

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

the class KieRepositoryScannerTest method testScanIncludedAndIncludingDependency.

@Test
@Ignore
public void testScanIncludedAndIncludingDependency() 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();
    InternalKieModule containerKJar = createIncludingKJar(containerReleaseId, includedReleaseId, "ruleX");
    repository.installArtifact(containerReleaseId, containerKJar, createKPom(fileManager, containerReleaseId, includedReleaseId));
    KieContainer kieContainer = ks.newKieContainer(containerReleaseId);
    KieSession ksession = kieContainer.newKieSession("KSession2");
    checkKSession(ksession, "rule1", "ruleX");
    resetFileManager();
    KieScanner scanner = ks.newKieScanner(kieContainer);
    InternalKieModule kJar2 = createKieJar(ks, includedReleaseId, "rule2");
    repository.installArtifact(includedReleaseId, kJar2, createKPom(fileManager, includedReleaseId));
    resetFileManager();
    InternalKieModule containerKJar2 = createIncludingKJar(containerReleaseId, includedReleaseId, "ruleY");
    repository.installArtifact(containerReleaseId, containerKJar2, createKPom(fileManager, containerReleaseId, includedReleaseId));
    resetFileManager();
    scanner.scanNow();
    KieSession ksession2 = kieContainer.newKieSession("KSession2");
    checkKSession(ksession2, "rule2", "ruleY");
    ks.getRepository().removeKieModule(containerReleaseId);
    ks.getRepository().removeKieModule(includedReleaseId);
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with KieScanner

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

the class KieScannerIncrementalCompilationTest method checkIncrementalCompilation.

private void checkIncrementalCompilation(boolean useJavaInDrl) throws IOException {
    KieServices ks = KieServices.Factory.get();
    KieMavenRepository repository = getKieMavenRepository();
    InternalKieModule kJar1 = createKieJarWithClass(ks, releaseId, FIRST_VALUE, useJavaInDrl);
    repository.installArtifact(releaseId, kJar1, createKPom(releaseId));
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieScanner scanner = ks.newKieScanner(kieContainer);
    checkValue(kieContainer, FIRST_VALUE);
    InternalKieModule kJar2 = createKieJarWithClass(ks, releaseId, SECOND_VALUE, useJavaInDrl);
    repository.installArtifact(releaseId, kJar2, createKPom(releaseId));
    scanner.scanNow();
    checkValue(kieContainer, SECOND_VALUE);
    ks.getRepository().removeKieModule(releaseId);
}
Also used : KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieServices(org.kie.api.KieServices) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer)

Example 9 with KieScanner

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

the class MavenDeployTest method testKScannerWithDeployUsingDistributionManagement.

@Test
public void testKScannerWithDeployUsingDistributionManagement() throws IOException {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test-deploy-dist", "1.0-SNAPSHOT");
    Path m2Folder = Files.createTempDirectory("temp-m2-dist");
    Path settingsXmlPath = generateSettingsXml(m2Folder);
    String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
    try {
        System.setProperty(CUSTOM_SETTINGS_PROPERTY, settingsXmlPath.toString());
        MavenSettings.reinitSettings();
        InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
        KieContainer kieContainer = ks.newKieContainer(releaseId);
        KieMavenRepository repository = getKieMavenRepository();
        repository.deployArtifact(releaseId, kJar1, createKPomWithDistributionManagement(m2Folder, releaseId).toFile());
        // create a ksesion and check it works as expected
        KieSession ksession = kieContainer.newKieSession("KSession1");
        checkKSession(ksession, "rule1", "rule2");
        // create a new kjar
        InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
        // deploy it on maven
        repository.deployArtifact(releaseId, kJar2, createKPomWithDistributionManagement(m2Folder, releaseId).toFile());
        // since I am not calling start() on the scanner it means it won't have automatic scheduled scanning
        KieScanner scanner = ks.newKieScanner(kieContainer);
        // scan the maven repo to get the new kjar version and deploy it on the kcontainer
        scanner.scanNow();
        // create a ksesion and check it works as expected
        KieSession ksession2 = kieContainer.newKieSession("KSession1");
        checkKSession(ksession2, "rule2", "rule3");
        ks.getRepository().removeKieModule(releaseId);
    } finally {
        if (oldSettingsXmlPath == null) {
            System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
        } else {
            System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
        }
        MavenSettings.reinitSettings();
    }
}
Also used : Path(java.nio.file.Path) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test) AbstractKieCiTest(org.kie.scanner.AbstractKieCiTest)

Example 10 with KieScanner

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

the class MavenDeployTest method testDeploy.

@Test
public void testDeploy() throws IOException {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test-deploy", "1.0-SNAPSHOT");
    Path m2Folder = Files.createTempDirectory("temp-m2");
    Path settingsXmlPath = generateSettingsXml(m2Folder);
    String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
    try {
        System.setProperty(CUSTOM_SETTINGS_PROPERTY, settingsXmlPath.toString());
        MavenSettings.reinitSettings();
        InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
        KieContainer kieContainer = ks.newKieContainer(releaseId);
        KieMavenRepository repository = getKieMavenRepository();
        RemoteRepository remote = createRemoteRepository(m2Folder);
        repository.deployArtifact(remote, releaseId, kJar1, createKPom(m2Folder, releaseId).toFile());
        // create a ksesion and check it works as expected
        KieSession ksession = kieContainer.newKieSession("KSession1");
        checkKSession(ksession, "rule1", "rule2");
        // create a new kjar
        InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
        // deploy it on maven
        repository.deployArtifact(remote, releaseId, kJar2, createKPom(m2Folder, releaseId).toFile());
        // since I am not calling start() on the scanner it means it won't have automatic scheduled scanning
        KieScanner scanner = ks.newKieScanner(kieContainer);
        // scan the maven repo to get the new kjar version and deploy it on the kcontainer
        scanner.scanNow();
        // create a ksesion and check it works as expected
        KieSession ksession2 = kieContainer.newKieSession("KSession1");
        checkKSession(ksession2, "rule2", "rule3");
        ks.getRepository().removeKieModule(releaseId);
    } finally {
        if (oldSettingsXmlPath == null) {
            System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
        } else {
            System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
        }
        MavenSettings.reinitSettings();
    }
}
Also used : Path(java.nio.file.Path) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test) AbstractKieCiTest(org.kie.scanner.AbstractKieCiTest)

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