Search in sources :

Example 6 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class DMNDecisionTableRuntimeTest method testDecisionTableOutputDMNTypeCollectionWithLOV_NOtypecheck.

@Test
public void testDecisionTableOutputDMNTypeCollectionWithLOV_NOtypecheck() {
    // DROOLS-2359
    // do NOT use the DMNRuntimeUtil as that enables typeSafe check override for runtime.
    KieServices ks = KieServices.Factory.get();
    final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.0"), ks.getResources().newClassPathResource("DecisionTableOutputDMNTypeCollectionWithLOV.dmn", this.getClass()));
    DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_ae5d2033-c6d0-411f-a394-da33a70e5638", "List of Words in DT");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("selector", "asd");
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("a decision"), is(Arrays.asList("abc", "a")));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) KieServices(org.kie.api.KieServices) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 7 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class KieModuleBuilderTest method testPomTypeDependencies.

@Test
public void testPomTypeDependencies() throws Exception {
    // RHBPMS-4634
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseIdNoDep = ks.newReleaseId("org.kie", "test-no-dep", "1.0-SNAPSHOT");
    ReleaseId releaseIdWithDep = ks.newReleaseId("org.kie", "test-with-dep", "1.0-SNAPSHOT");
    ReleaseId ejbReleaseId = ks.newReleaseId("org.jboss.as", "jboss-as-ejb-client-bom", "7.1.1.Final");
    ReleaseId jmsReleaseId = ks.newReleaseId("org.jboss.as", "jboss-as-jms-client-bom", "7.1.1.Final");
    String pom = getPomWithPomDependencies(releaseIdNoDep, ejbReleaseId, jmsReleaseId);
    File pomFile = fileManager.newFile("pom.xml");
    fileManager.write(pomFile, pom);
    InternalKieModule kJar1 = createKieJarWithPomDependencies(ks, releaseIdNoDep, pom);
    KieMavenRepository repository = KieMavenRepository.getKieMavenRepository();
    repository.installArtifact(releaseIdNoDep, kJar1, pomFile);
    InternalKieModule kJar2 = createKieJarWithDependencies(ks, releaseIdWithDep, true, "rule1", releaseIdNoDep);
    KieContainer kieContainer2 = ks.newKieContainer(releaseIdWithDep);
    KieSession kieSession = kieContainer2.newKieSession();
}
Also used : KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 8 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class KieModuleMavenTest method testKieModuleFromMavenNoDependencies.

@Test
public void testKieModuleFromMavenNoDependencies() 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", "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);
    KieBaseModel kbaseModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieBaseModel();
    assertNotNull("Default kbase was not found", kbaseModel);
    String kbaseName = kbaseModel.getName();
    assertEquals("KBase1", kbaseName);
    // Check classloader
    assertUrlEnumerationContainsMatch(".*org/kie/maven\\-test/1.0\\-SNAPSHOT.*", kieContainer.getClassLoader().getResources(""));
    assertUrlEnumerationContainsMatch(".*org/kie/maven\\-test/1.0\\-SNAPSHOT.*", kieContainer.getClassLoader().getResources("KBase1/org/test"));
    assertUrlEnumerationContainsMatch(".*org/kie/maven\\-test/1.0\\-SNAPSHOT.*", kieContainer.getClassLoader().getResources("KBase1/org/test/"));
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieRepositoryImpl(org.drools.compiler.kie.builder.impl.KieRepositoryImpl) FileOutputStream(java.io.FileOutputStream) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) IOException(java.io.IOException) 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)

Example 9 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class KieModuleMavenTest method testKieContainerBeforeAndAfterDeployOfSnapshot.

@Test
public void testKieContainerBeforeAndAfterDeployOfSnapshot() throws Exception {
    // BZ-1007977
    KieServices ks = KieServices.Factory.get();
    String group = "org.kie.test";
    String artifact = "test-module";
    String version = "1.0.0-SNAPSHOT";
    ReleaseId releaseId = ks.newReleaseId(group, artifact, version);
    String prefix = new File(".").getAbsolutePath().contains("kie-ci") ? "" : "kie-ci/";
    File kjar = new File(prefix + "src/test/resources/kjar/kjar-module-before.jar");
    File pom = new File(prefix + "src/test/resources/kjar/pom-kjar.xml");
    MavenRepository repository = getMavenRepository();
    repository.installArtifact(releaseId, kjar, pom);
    KieContainer kContainer = ks.newKieContainer(releaseId);
    KieBase kbase = kContainer.getKieBase();
    assertNotNull(kbase);
    Collection<KiePackage> packages = kbase.getKiePackages();
    assertNotNull(packages);
    assertEquals(1, packages.size());
    Collection<Rule> rules = packages.iterator().next().getRules();
    assertEquals(2, rules.size());
    ks.getRepository().removeKieModule(releaseId);
    // deploy new version
    File kjar1 = new File(prefix + "src/test/resources/kjar/kjar-module-after.jar");
    File pom1 = new File(prefix + "src/test/resources/kjar/pom-kjar.xml");
    repository.installArtifact(releaseId, kjar1, pom1);
    KieContainer kContainer2 = ks.newKieContainer(releaseId);
    KieBase kbase2 = kContainer2.getKieBase();
    assertNotNull(kbase2);
    Collection<KiePackage> packages2 = kbase2.getKiePackages();
    assertNotNull(packages2);
    assertEquals(1, packages2.size());
    Collection<Rule> rules2 = packages2.iterator().next().getRules();
    assertEquals(4, rules2.size());
    ks.getRepository().removeKieModule(releaseId);
}
Also used : MavenRepository.getMavenRepository(org.appformer.maven.integration.MavenRepository.getMavenRepository) MavenRepository(org.appformer.maven.integration.MavenRepository) KiePackage(org.kie.api.definition.KiePackage) KieBase(org.kie.api.KieBase) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) Rule(org.kie.api.definition.rule.Rule) File(java.io.File) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 10 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class KieModuleMavenTest method testKieModuleFromMavenWithDependenciesProperties.

@Test
public void testKieModuleFromMavenWithDependenciesProperties() 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", "${version.org.drools}");
    ReleaseId releaseId = ks.newReleaseId("org.kie.test", "maven-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJarWithProperties(ks, releaseId, true, "5.5.0.Final", new ReleaseId[] { dependency }, "rule1", "rule2");
    String pomText = generatePomXmlWithProperties(releaseId, "5.5.0.Final", dependency);
    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);
    KieBaseModel kbaseModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieBaseModel();
    assertNotNull("Default kbase was not found", kbaseModel);
    String kbaseName = kbaseModel.getName();
    assertEquals("KBase1", kbaseName);
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieRepositoryImpl(org.drools.compiler.kie.builder.impl.KieRepositoryImpl) FileOutputStream(java.io.FileOutputStream) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) IOException(java.io.IOException) 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

KieContainer (org.kie.api.runtime.KieContainer)357 KieServices (org.kie.api.KieServices)271 Test (org.junit.Test)246 KieSession (org.kie.api.runtime.KieSession)191 ReleaseId (org.kie.api.builder.ReleaseId)185 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)108 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)90 KieFileSystem (org.kie.api.builder.KieFileSystem)81 KieModule (org.kie.api.builder.KieModule)75 KieBuilder (org.kie.api.builder.KieBuilder)56 KieModuleModel (org.kie.api.builder.model.KieModuleModel)54 KieBase (org.kie.api.KieBase)49 ArrayList (java.util.ArrayList)44 Results (org.kie.api.builder.Results)40 Resource (org.kie.api.io.Resource)29 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)29 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)27 Message (org.drools.compiler.Message)26 KieBaseModel (org.kie.api.builder.model.KieBaseModel)26 InternalKieContainer (org.drools.core.impl.InternalKieContainer)25