Search in sources :

Example 6 with KieServicesImpl

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

the class KieModuleMavenTest method testKieModuleFromMavenWithTransitiveDependencies.

@Test
public void testKieModuleFromMavenWithTransitiveDependencies() throws Exception {
    final KieServices ks = new KieServicesImpl() {

        @Override
        public KieRepository getRepository() {
            // override repository to not store the artifact on deploy to trigger load from maven repo
            return new KieRepositoryImpl();
        }
    };
    ReleaseId dependency = ks.newReleaseId("org.drools", "drools-core", "5.5.0.Final");
    ReleaseId releaseId = ks.newReleaseId("org.kie", "maven-test", "1.0-SNAPSHOT");
    String pomText = getPom(releaseId, dependency);
    InternalKieModule kJar1 = createKieJar(ks, releaseId, pomText, true, "rule1", "rule2");
    File pomFile = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId, null) + ".pom");
    try {
        FileOutputStream fos = new FileOutputStream(pomFile);
        fos.write(pomText.getBytes());
        fos.flush();
        fos.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kJar1, pomFile);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    Collection<ReleaseId> expectedDependencies = new HashSet<ReleaseId>();
    expectedDependencies.add(ks.newReleaseId("org.drools", "knowledge-api", "5.5.0.Final"));
    expectedDependencies.add(ks.newReleaseId("org.drools", "knowledge-internal-api", "5.5.0.Final"));
    expectedDependencies.add(ks.newReleaseId("org.drools", "drools-core", "5.5.0.Final"));
    expectedDependencies.add(ks.newReleaseId("org.mvel", "mvel2", "2.1.3.Final"));
    expectedDependencies.add(ks.newReleaseId("org.slf4j", "slf4j-api", "1.6.4"));
    Collection<ReleaseId> dependencies = ((InternalKieModule) ((KieContainerImpl) kieContainer).getKieModuleForKBase("KBase1")).getJarDependencies(DependencyFilter.TAKE_ALL_FILTER);
    assertNotNull(dependencies);
    assertEquals(5, dependencies.size());
    boolean matchedAll = dependencies.containsAll(expectedDependencies);
    assertTrue(matchedAll);
}
Also used : KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) IOException(java.io.IOException) KieRepositoryImpl(org.drools.compiler.kie.builder.impl.KieRepositoryImpl) FileOutputStream(java.io.FileOutputStream) KieServicesImpl(org.drools.compiler.kie.builder.impl.KieServicesImpl) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with KieServicesImpl

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

the class KieModuleMavenTest method testResourceTypeInKieModuleReleaseId.

@Test
public void testResourceTypeInKieModuleReleaseId() throws Exception {
    final KieServices ks = new KieServicesImpl() {

        @Override
        public KieRepository getRepository() {
            // override repository to not store the artifact on deploy to trigger load from maven repo
            return new KieRepositoryImpl();
        }
    };
    ReleaseId releaseId = ks.newReleaseId("org.kie", "maven-test.drl", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, true, "rule1", "rule2");
    String pomText = getPom(releaseId);
    File pomFile = new File(System.getProperty("java.io.tmpdir"), MavenRepository.toFileName(releaseId, null) + ".pom");
    try {
        FileOutputStream fos = new FileOutputStream(pomFile);
        fos.write(pomText.getBytes());
        fos.flush();
        fos.close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    KieMavenRepository.getKieMavenRepository().installArtifact(releaseId, kJar1, pomFile);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieBase kieBase = kieContainer.getKieBase("KBase1");
    assertNotNull(kieBase);
    assertEquals("There must be one package built", 1, kieBase.getKiePackages().size());
    ClassLoader classLoader = kieContainer.getClassLoader();
    assertEnumerationSize(1, classLoader.getResources("KBase1/org/test"));
    assertEnumerationSize(1, classLoader.getResources("META-INF/maven/org.kie/maven-test.drl"));
}
Also used : KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) IOException(java.io.IOException) KieBase(org.kie.api.KieBase) KieRepositoryImpl(org.drools.compiler.kie.builder.impl.KieRepositoryImpl) FileOutputStream(java.io.FileOutputStream) KieServicesImpl(org.drools.compiler.kie.builder.impl.KieServicesImpl) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

KieServicesImpl (org.drools.compiler.kie.builder.impl.KieServicesImpl)7 File (java.io.File)6 Test (org.junit.Test)6 FileOutputStream (java.io.FileOutputStream)5 IOException (java.io.IOException)5 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)5 KieRepositoryImpl (org.drools.compiler.kie.builder.impl.KieRepositoryImpl)5 KieServices (org.kie.api.KieServices)5 ReleaseId (org.kie.api.builder.ReleaseId)5 KieContainer (org.kie.api.runtime.KieContainer)5 KieBaseModel (org.kie.api.builder.model.KieBaseModel)3 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Bean (javax.enterprise.inject.spi.Bean)1 FileManager (org.drools.core.util.FileManager)1 Weld (org.jboss.weld.environment.se.Weld)1 WeldContainer (org.jboss.weld.environment.se.WeldContainer)1