Search in sources :

Example 86 with Results

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"));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) Results(org.kie.api.builder.Results) DMNContext(org.kie.dmn.api.core.DMNContext) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 87 with Results

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"));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) Results(org.kie.api.builder.Results) DMNContext(org.kie.dmn.api.core.DMNContext) Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 88 with Results

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));
}
Also used : Results(org.kie.api.builder.Results) Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 89 with Results

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)));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DMNContext(org.kie.dmn.api.core.DMNContext) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) BigDecimal(java.math.BigDecimal) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 90 with Results

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"));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DMNContext(org.kie.dmn.api.core.DMNContext) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

Results (org.kie.api.builder.Results)92 Test (org.junit.Test)81 KieServices (org.kie.api.KieServices)72 KieFileSystem (org.kie.api.builder.KieFileSystem)60 KieContainer (org.kie.api.runtime.KieContainer)36 KieBuilder (org.kie.api.builder.KieBuilder)32 KieSession (org.kie.api.runtime.KieSession)25 IncrementalResults (org.kie.internal.builder.IncrementalResults)20 ReleaseId (org.kie.api.builder.ReleaseId)19 QueryResults (org.kie.api.runtime.rule.QueryResults)17 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)15 KieBase (org.kie.api.KieBase)14 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)13 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)11 KieHelper (org.kie.internal.utils.KieHelper)11 KieModuleModel (org.kie.api.builder.model.KieModuleModel)10 FactType (org.kie.api.definition.type.FactType)10 ArrayList (java.util.ArrayList)9 FlatQueryResults (org.drools.core.runtime.rule.impl.FlatQueryResults)9 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7