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")));
}
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();
}
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/"));
}
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);
}
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);
}
Aggregations