use of org.kie.api.builder.Results in project drools by kiegroup.
the class DMNUpdateTest method testRemoveAndAddSomething.
@Test
public void testRemoveAndAddSomething() {
final KieServices ks = KieServices.Factory.get();
final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test", "1.0.0"), ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()));
DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
DMNContext dmnContext = runtime.newContext();
dmnContext.set("Full Name", "John Doe");
DMNResult evaluateAll = runtime.evaluateAll(runtime.getModels().get(0), dmnContext);
assertThat(evaluateAll.getDecisionResultByName("Greeting Message").getResult(), is("Hello John Doe"));
ReleaseId v101 = ks.newReleaseId("org.kie", "dmn-test", "1.0.1");
KieHelper.createAndDeployJar(ks, v101, ks.getResources().newClassPathResource("0001-input-data-string-itIT.dmn", this.getClass()));
Results updateResults = kieContainer.updateToVersion(v101);
assertThat(updateResults.hasMessages(Level.ERROR), is(false));
runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
DMNContext dmnContext2 = runtime.newContext();
dmnContext2.set("Full Name", "John Doe");
DMNResult evaluateAll2 = runtime.evaluateAll(runtime.getModels().get(0), dmnContext2);
assertThat(evaluateAll2.getDecisionResultByName("Greeting Message").getResult(), is("Salve John Doe"));
}
use of org.kie.api.builder.Results in project drools by kiegroup.
the class DMNUpdateTest method testReplaceDisposeCreateReplace.
@Test
public void testReplaceDisposeCreateReplace() {
final KieServices ks = KieServices.Factory.get();
ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0");
KieContainer kieContainer = KieHelper.getKieContainer(v100, ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()));
DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
DMNContext dmnContext = runtime.newContext();
dmnContext.set("Full Name", "John Doe");
DMNResult evaluateAll = runtime.evaluateAll(runtime.getModels().get(0), dmnContext);
assertThat(evaluateAll.getDecisionResultByName("Greeting Message").getResult(), is("Hello John Doe"));
ReleaseId v101 = ks.newReleaseId("org.kie", "dmn-test", "1.0.1");
Resource newClassPathResource = ks.getResources().newClassPathResource("0001-input-data-string-itIT.dmn", this.getClass());
newClassPathResource.setTargetPath("0001-input-data-string.dmn");
KieHelper.createAndDeployJar(ks, v101, newClassPathResource);
Results updateResults = kieContainer.updateToVersion(v101);
assertThat(updateResults.hasMessages(Level.ERROR), is(false));
runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
DMNContext dmnContext2 = runtime.newContext();
dmnContext2.set("Full Name", "John Doe");
DMNResult evaluateAll2 = runtime.evaluateAll(runtime.getModels().get(0), dmnContext2);
assertThat(evaluateAll2.getDecisionResultByName("Greeting Message").getResult(), is("Salve John Doe"));
kieContainer.dispose();
kieContainer = ks.newKieContainer(v100);
runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
DMNContext dmnContext3 = runtime.newContext();
dmnContext3.set("Full Name", "John Doe");
DMNResult evaluateAll3 = runtime.evaluateAll(runtime.getModels().get(0), dmnContext3);
assertThat(evaluateAll3.getDecisionResultByName("Greeting Message").getResult(), is("Hello John Doe"));
updateResults = kieContainer.updateToVersion(v101);
assertThat(updateResults.hasMessages(Level.ERROR), is(false));
runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
DMNContext dmnContext4 = runtime.newContext();
dmnContext4.set("Full Name", "John Doe");
DMNResult evaluateAll4 = runtime.evaluateAll(runtime.getModels().get(0), dmnContext4);
assertThat(evaluateAll4.getDecisionResultByName("Greeting Message").getResult(), is("Salve John Doe"));
}
use of org.kie.api.builder.Results in project drools by kiegroup.
the class DMNUpdateTest method testFromClonedKiePackageThenUpgrade.
@Test
public void testFromClonedKiePackageThenUpgrade() {
final KieServices ks = KieServices.Factory.get();
ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0");
KieHelper.createAndDeployJar(ks, v100, ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()));
KieContainer kieContainer = ks.newKieContainer(v100);
DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
kieContainer.dispose();
kieContainer = ks.newKieContainer(v100);
runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
ReleaseId v101 = ks.newReleaseId("org.kie", "dmn-test", "1.0.1");
Resource newClassPathResource = ks.getResources().newClassPathResource("0001-input-data-string-itIT.dmn", this.getClass());
newClassPathResource.setTargetPath("0001-input-data-string.dmn");
KieHelper.createAndDeployJar(ks, v101, newClassPathResource);
Results updateResults = kieContainer.updateToVersion(v101);
assertThat(updateResults.hasMessages(Level.ERROR), is(false));
runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
}
use of org.kie.api.builder.Results in project drools by kiegroup.
the class DMNProfilesTest method testJust47.
@Test
public void testJust47() {
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmm = ks.newKieModuleModel();
kmm.setConfigurationProperty("org.kie.dmn.profiles.Just47DMNProfile", Just47DMNProfile.class.getCanonicalName());
kfs.writeKModuleXML(kmm.toXML());
kfs.write(ks.getResources().newClassPathResource("just_47.dmn", this.getClass()));
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
assertThat(results.getMessages().toString(), results.hasMessages(org.kie.api.builder.Message.Level.ERROR), is(false));
final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
final DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_ae46e75f-efc5-48f8-8e82-4f48bf16afc0", "just 47");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext context = DMNFactory.newContext();
context.set("number", 123.123456d);
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
System.out.println(dmnResult);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
DMNContext result = dmnResult.getContext();
assertThat(result.get("decision result"), is(new BigDecimal(47)));
}
use of org.kie.api.builder.Results in project drools by kiegroup.
the class SignavioTest method test.
@Test
public void test() {
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmm = ks.newKieModuleModel();
kmm.setConfigurationProperty("org.kie.dmn.profiles.signavio", "org.kie.dmn.signavio.KieDMNSignavioProfile");
kfs.writeKModuleXML(kmm.toXML());
kfs.write(ks.getResources().newClassPathResource("Test_Signavio_multiple.dmn", this.getClass()));
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
LOG.info("buildAll() completed.");
results.getMessages(Level.WARNING).forEach(e -> LOG.warn("{}", e));
assertTrue(results.getMessages(Level.WARNING).size() == 0);
final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
List<DMNModel> models = runtime.getModels();
DMNContext context = runtime.newContext();
context.set("persons", Arrays.asList(new String[] { "p1", "p2" }));
DMNModel model0 = models.get(0);
System.out.println("EVALUATE ALL:");
DMNResult evaluateAll = runtime.evaluateAll(model0, context);
System.out.println(evaluateAll);
assertThat((List<?>) evaluateAll.getContext().get("Greeting for each Person in Persons"), contains("Hello p1", "Hello p2"));
}
Aggregations