public static KieModule createAndDeployJarIgnoringErrors(KieServices ks, ReleaseId releaseId, Resource... resources) { byte[] jar = createJarIgnoringErrors(ks, releaseId, resources); KieModule km = KieHelper.deployJarIntoRepository(ks, jar); return km; }
@SafeVarargs public static <K, V> Map<K, V> mapOf(Map.Entry<K, V>... attributes) { return prototype(attributes); }
@Test public void testImportTransitiveBaseModel() { final DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("Sayhello1ID1D.dmn", this.getClass(), "ModelB.dmn", "ModelB2.dmn", "ModelC.dmn"); getAndAssertModelNoErrors(runtime, "http://www.trisotech.com/dmn/definitions/_ae5b3c17-1ac3-4e1d-b4f9-2cf861aec6d9", "Say hello 1ID1D"); }
@Test public void testImportTransitiveEvaluate3Layers() { final DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("Sayhello1ID1D.dmn", this.getClass(), "ModelB.dmn", "ModelB2.dmn", "ModelC.dmn"); final DMNModel dmnModel = getAndAssertModelNoErrors(runtime, "http://www.trisotech.com/dmn/definitions/_10435dcd-8774-4575-a338-49dd554a0928", "Model C"); final DMNContext context = runtime.newContext(); context.set("Model B", mapOf(entry("modelA", mapOf(entry("Person name", "B.A.John"))))); context.set("Model B2", mapOf(entry("modelA", mapOf(entry("Person name", "B2.A.John2"))))); final DMNResult evaluateAll = runtime.evaluateAll(dmnModel, context); LOG.debug("{}", evaluateAll); assertThat(DMNRuntimeUtil.formatMessages(evaluateAll.getMessages()), evaluateAll.hasErrors(), is(false)); assertThat(evaluateAll.getDecisionResultByName("Model C Decision based on Bs").getResult(), is("B: Evaluating Say Hello to: Hello, B.A.John; B2:Evaluating Say Hello to: Hello, B2.A.John2")); }
private void testAllowDMNAPItoEvaluateDirectDependencyImportedDecisions_evaluateResultsAndCheck(final DMNRuntime runtime, final Function<DMNContext, DMNResult> fn) { final DMNContext context = runtime.newContext(); context.set("modelA", mapOf(entry("Person name", "John"))); final DMNResult evaluateAll = fn.apply(context); LOG.debug("{}", evaluateAll); LOG.debug("{}", evaluateAll.getDecisionResults()); assertThat(DMNRuntimeUtil.formatMessages(evaluateAll.getMessages()), evaluateAll.hasErrors(), is(false)); assertThat(evaluateAll.getDecisionResultByName("Evaluating Say Hello").getResult(), is("Evaluating Say Hello to: Hello, John")); assertThat(evaluateAll.getDecisionResultByName("modelA.Greet the Person").getResult(), is("Hello, John")); }
@Test public void testListContainmentDT() { // DROOLS-2416 final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("list_containment_DT.dmn", this.getClass()); final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_6ab2bd6d-adaa-45c4-a141-a84382a201eb", "list containment DT"); assertThat(dmnModel, notNullValue()); assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false)); final DMNContext context = DMNFactory.newContext(); context.set("Passenger", prototype(entry("name", "Osama bin Laden"))); final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context); assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false)); final DMNContext result = dmnResult.getContext(); assertThat(result.get("Boarding Status"), is("Denied")); }
@Test public void testGetEntries() { // DROOLS-3308 DMN implement missing functions only described in chapter "10.3.2.6 Context" final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("getentriesgetvalue.dmn", this.getClass()); final DMNModel dmnModel = getAndAssertModelNoErrors(runtime, "http://www.trisotech.com/dmn/definitions/_0fad1a80-0642-4278-ac3d-47668c4f689a", "Drawing 1"); final DMNContext emptyContext = DMNFactory.newContext(); final DMNResult dmnResult = runtime.evaluateAll(dmnModel, emptyContext); LOG.debug("{}", dmnResult); assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false)); assertThat(dmnResult.getDecisionResultByName("using get entries").getEvaluationStatus(), is(DecisionEvaluationStatus.SUCCEEDED)); assertThat(dmnResult.getDecisionResultByName("using get entries").getResult(), is(Arrays.asList("value2"))); }
public static DMNRuntime createRuntime(final Class testClass) { final KieServices ks = KieServices.Factory.get(); final KieContainer kieContainer = KieHelper.getKieContainer( ks.newReleaseId("org.kie", "dmn-test-"+UUID.randomUUID(), "1.0")); final DMNRuntime runtime = typeSafeGetKieRuntime(kieContainer); Assert.assertNotNull(runtime); return runtime; }
@Test public void testDecisionTableWithCalculatedResult() { final DMNRuntime runtime = DMNRuntimeUtil.createRuntime( "calculation1.dmn", this.getClass() ); checkDecisionTableWithCalculatedResult(runtime); }
public static DMNModel getAndAssertModelNoErrors(final DMNRuntime runtime, final String namespace, final String modelName) { DMNModel dmnModel = runtime.getModel(namespace, modelName); assertThat(dmnModel, notNullValue()); assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false)); return dmnModel; } }
public static KieContainer getKieContainerIgnoringErrors(ReleaseId releaseId, Resource... resources) { KieServices ks = KieServices.Factory.get(); createAndDeployJarIgnoringErrors(ks, releaseId, resources); return ks.newKieContainer(releaseId); }
@Test public void testErrorMessages() { final List<DMNMessage> messages = DMNRuntimeUtil.createExpectingDMNMessages("car_damage_responsibility2.dmn", this.getClass()); assertThat(messages.isEmpty(), is(false)); }
@Test public void testImportingID() { // DROOLS-2944 DMN decision logic referencing DMN<import> InputData final DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("Sayhello1ID1D.dmn", this.getClass(), "Importing_ID.dmn"); final DMNModel dmnModel = getAndAssertModelNoErrors(runtime, "http://www.trisotech.com/dmn/definitions/_24bac498-2a5a-403d-8b44-d407628784c4", "Importing ID"); final DMNContext context = runtime.newContext(); context.set("my import hello", mapOf(entry("Person name", "DROOLS-2944"))); final DMNResult evaluateAll = runtime.evaluateAll(dmnModel, context); LOG.debug("{}", evaluateAll); assertThat(DMNRuntimeUtil.formatMessages(evaluateAll.getMessages()), evaluateAll.hasErrors(), is(false)); assertThat(evaluateAll.getDecisionResultByName("Hello decision using imported InputData").getResult(), is("Hello, DROOLS-2944")); }
private static void testDecisionService20180920_testEvaluateAll(final DMNRuntime runtime, final DMNModel dmnModel) { final DMNContext context = DMNFactory.newContext(); context.set("Model A", mapOf(entry("Input 1", "input 1 value"))); final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context); LOG.debug("{}", dmnResult); dmnResult.getDecisionResults().forEach(x -> LOG.debug("{}", x)); assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false)); final DMNContext result = dmnResult.getContext(); assertThat(result.get("Decision B"), is("input 1 value")); assertThat(result.get("Invoke Decision B DS"), is("A value")); }
@Test public void testGetValue() { // DROOLS-3308 DMN implement missing functions only described in chapter "10.3.2.6 Context" final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("getentriesgetvalue.dmn", this.getClass()); final DMNModel dmnModel = getAndAssertModelNoErrors(runtime, "http://www.trisotech.com/dmn/definitions/_0fad1a80-0642-4278-ac3d-47668c4f689a", "Drawing 1"); final DMNContext emptyContext = DMNFactory.newContext(); final DMNResult dmnResult = runtime.evaluateAll(dmnModel, emptyContext); LOG.debug("{}", dmnResult); assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false)); assertThat(dmnResult.getDecisionResultByName("using get value").getEvaluationStatus(), is(DecisionEvaluationStatus.SUCCEEDED)); assertThat(dmnResult.getDecisionResultByName("using get value").getResult(), is("value2")); } }
@Test public void testAllowDMNAPItoEvaluateDirectDependencyImportedDecisions() { // DROOLS-3012 Allow DMN API to evaluate direct-dependency imported Decisions final DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("Sayhello1ID1D.dmn", this.getClass(), "ModelB.dmn"); final DMNModel dmnModel = getAndAssertModelNoErrors(runtime, "http://www.trisotech.com/dmn/definitions/_2a1d771a-a899-4fef-abd6-fc894332337c", "Model B"); testAllowDMNAPItoEvaluateDirectDependencyImportedDecisions_evaluateResultsAndCheck(runtime, context -> runtime.evaluateByName(dmnModel, context, "modelA.Greet the Person", "Evaluating Say Hello")); testAllowDMNAPItoEvaluateDirectDependencyImportedDecisions_evaluateResultsAndCheck(runtime, context -> runtime.evaluateById(dmnModel, context, "http://www.trisotech.com/dmn/definitions/_ae5b3c17-1ac3-4e1d-b4f9-2cf861aec6d9#_f7fdaec4-d669-4797-b3b4-12b860de2eb5", "_96df766e-23e1-4aa6-9d5d-545fbe2f1e23")); }
public static DMNRuntime createRuntime(final String resourceName, final Class testClass) { final KieServices ks = KieServices.Factory.get(); final KieContainer kieContainer = KieHelper.getKieContainer( ks.newReleaseId("org.kie", "dmn-test-"+UUID.randomUUID(), "1.0"), ks.getResources().newClassPathResource(resourceName, testClass)); final DMNRuntime runtime = typeSafeGetKieRuntime(kieContainer); Assert.assertNotNull(runtime); return runtime; }
@Test public void testImportTransitiveEvaluate2Layers() { final DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("Sayhello1ID1D.dmn", this.getClass(), "ModelB.dmn", "ModelB2.dmn", "ModelC.dmn"); final DMNModel dmnModel = getAndAssertModelNoErrors(runtime, "http://www.trisotech.com/dmn/definitions/_2a1d771a-a899-4fef-abd6-fc894332337c", "Model B"); final DMNContext context = runtime.newContext(); context.set("modelA", mapOf(entry("Person name", "John"))); final DMNResult evaluateAll = runtime.evaluateAll(dmnModel, context); LOG.debug("{}", evaluateAll); assertThat(DMNRuntimeUtil.formatMessages(evaluateAll.getMessages()), evaluateAll.hasErrors(), is(false)); assertThat(evaluateAll.getDecisionResultByName("Evaluating Say Hello").getResult(), is("Evaluating Say Hello to: Hello, John")); }
private static void testDecisionService20180920_testEvaluateDS(final DMNRuntime runtime, final DMNModel dmnModel) { final DMNContext context = DMNFactory.newContext(); context.set("Model A", mapOf(entry("Input 1", "input 1 value"))); final DMNResult dmnResult = runtime.evaluateDecisionService(dmnModel, context, "Decision B DS"); LOG.debug("{}", dmnResult); dmnResult.getDecisionResults().forEach(x -> LOG.debug("{}", x)); assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false)); final DMNContext result = dmnResult.getContext(); assertThat(result.getAll(), not(hasEntry(is("Invoke Decision B DS"), anything()))); // we invoked only the Decision Service, not this other Decision in the model. assertThat(result.get("Decision B"), is("input 1 value")); } }
public static DMNRuntime createRuntimeWithAdditionalResources(final String resourceName, final Class testClass, final String... additionalResources) { final KieServices ks = KieServices.Factory.get(); Resource mainResource = ks.getResources().newClassPathResource(resourceName, testClass); List<Resource> totalResources = new ArrayList<>(); totalResources.add(mainResource); for ( String add : additionalResources ) { totalResources.add( ks.getResources().newClassPathResource(add, testClass) ); } final KieContainer kieContainer = KieHelper.getKieContainer( ks.newReleaseId("org.kie", "dmn-test-"+UUID.randomUUID(), "1.0"), totalResources.toArray(new Resource[] {})); final DMNRuntime runtime = typeSafeGetKieRuntime(kieContainer); Assert.assertNotNull(runtime); return runtime; }