Search in sources :

Example 66 with InternalKieModule

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

the class KieModuleMetaDataTest method testKieModuleMetaDataForDependenciesInMemory.

private void testKieModuleMetaDataForDependenciesInMemory(boolean useTypeDeclaration) throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId dependency = ks.newReleaseId("org.drools", "drools-core", "5.5.0.Final");
    ReleaseId releaseId = ks.newReleaseId("org.kie", "metadata-test", "1.0-SNAPSHOT");
    InternalKieModule kieModule = createKieJarWithClass(ks, releaseId, useTypeDeclaration, 2, 7, dependency);
    KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);
    checkDroolsCoreDep(kieModuleMetaData);
    Collection<String> testClasses = kieModuleMetaData.getClasses("org.drools");
    assertEquals(55, testClasses.size());
    Class<?> beanClass = kieModuleMetaData.getClass("org.drools", "QueryResult");
    assertNotNull(beanClass);
    // Classes in dependencies should have TypeMetaInfo
    TypeMetaInfo beanTypeInfo = kieModuleMetaData.getTypeMetaInfo(beanClass);
    assertNotNull(beanTypeInfo);
    if (useTypeDeclaration) {
        assertTrue(beanTypeInfo.isEvent());
    }
    assertEquals(useTypeDeclaration, beanTypeInfo.isDeclaredType());
}
Also used : TypeMetaInfo(org.drools.core.rule.TypeMetaInfo) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 67 with InternalKieModule

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

the class KieRepositoryScannerNexusTest method testKScannerNewContainer.

@Test
public void testKScannerNewContainer() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("com.redhat.gss", "scanner-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, getPomWithDistributionManagement(releaseId), true, "rule1", "rule2");
    KieMavenRepository repository = getKieMavenRepository();
    repository.deployArtifact(releaseId, kJar1, createKPomWithDistributionManagement(fileManager, releaseId));
    // remove kjar from KieRepo
    ks.getRepository().removeKieModule(releaseId);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    // 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, getPomWithDistributionManagement(releaseId), true, "rule2", "rule3");
    // deploy it on maven
    repository.deployArtifact(releaseId, kJar2, createKPomWithDistributionManagement(fileManager, releaseId));
    // remove kjar from KieRepo
    ks.getRepository().removeKieModule(releaseId);
    // create new KieContainer
    KieContainer kieContainer2 = ks.newKieContainer(releaseId);
    // create a ksession for the new container and check it works as expected
    KieSession ksession2 = kieContainer2.newKieSession("KSession1");
    checkKSession(ksession2, "rule2", "rule3");
    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)

Example 68 with InternalKieModule

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

the class KieRepositoryScannerTest method testKScannerStartNotDeployed.

@Test
public void testKScannerStartNotDeployed() throws Exception {
    // BZ-1200784
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-start-not-deployed-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    // starting KieScanner
    KieScanner scanner = ks.newKieScanner(kieContainer);
    // scan the maven repo to get the new kjar version before it is deployed into Maven repo
    // should not throw NPE because of uninitialized dependencies due to parsing parent pom failure
    scanner.scanNow();
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
    // create a ksesion and check it works as expected
    KieSession ksession = kieContainer.newKieSession("KSession1");
    checkKSession(ksession, "rule1", "rule2");
}
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 69 with InternalKieModule

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

the class KieRepositoryScannerTest method testKScannerWithKJarContainingClassLoadedFromClassLoader.

private void testKScannerWithKJarContainingClassLoadedFromClassLoader(boolean differentKbases) throws Exception {
    // DROOLS-1231
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJarWithJavaClass(ks, releaseId, "KBase1", 7);
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
    ks.getRepository().removeKieModule(releaseId);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieScanner scanner = ks.newKieScanner(kieContainer);
    Class<?> beanClass = kieContainer.getClassLoader().loadClass("org.kie.test.Bean");
    KieSession ksession = kieContainer.newKieSession("KSession1");
    Object bean = beanClass.getDeclaredConstructors()[0].newInstance(2);
    ksession.insert(bean);
    checkKSession(ksession, 14);
    InternalKieModule kJar2 = createKieJarWithJavaClass(ks, releaseId, differentKbases ? "KBase2" : "KBase1", 5);
    repository.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
    ks.getRepository().removeKieModule(releaseId);
    // forces cache of old Bean class definition before updating to newer release
    Class<?> beanClass1 = Class.forName("org.kie.test.Bean", true, kieContainer.getClassLoader());
    kieContainer.updateToVersion(releaseId);
    beanClass = kieContainer.getClassLoader().loadClass("org.kie.test.Bean");
    KieSession ksession2 = kieContainer.newKieSession("KSession1");
    bean = beanClass.getDeclaredConstructors()[0].newInstance(3);
    ksession2.insert(bean);
    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 70 with InternalKieModule

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

the class KieRepositoryScannerTest method testKScannerNewContainer.

@Test
public void testKScannerNewContainer() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
    ks.getRepository().removeKieModule(releaseId);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    // 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.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
    ks.getRepository().removeKieModule(releaseId);
    // create new KieContainer
    KieContainer kieContainer2 = ks.newKieContainer(releaseId);
    // create a ksession for the new container and check it works as expected
    KieSession ksession2 = kieContainer2.newKieSession("KSession1");
    checkKSession(ksession2, "rule2", "rule3");
    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