Search in sources :

Example 11 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-runtimes by kiegroup.

the class DecisionExplainabilityResourceExecutorTest method testGetDecisionModel.

@ParameterizedTest
@MethodSource("getDecisionModelTestProvider")
public void testGetDecisionModel(String[] args) {
    String namespace = args[0];
    String name = args[1];
    DecisionExplainabilityResourceExecutor executor = new DecisionExplainabilityResourceExecutor();
    DecisionModels decisionModels = mock(DecisionModels.class);
    DecisionModel model = new DmnDecisionModel(generateDMNRuntime(namespace, name), namespace, name);
    when(decisionModels.getDecisionModel(eq(namespace), eq(name))).thenReturn(model);
    ModelIdentifier modelIdentifier = new ModelIdentifier("dmn", String.format("%s%s%s", namespace, RESOURCE_ID_SEPARATOR, name));
    DecisionModel decisionModelResponse = executor.getDecisionModel(decisionModels, modelIdentifier);
    Assertions.assertNotNull(decisionModelResponse);
    Assertions.assertEquals(namespace, decisionModelResponse.getDMNModel().getNamespace());
    Assertions.assertEquals(name, decisionModelResponse.getDMNModel().getName());
}
Also used : ModelIdentifier(org.kie.kogito.explainability.model.ModelIdentifier) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DecisionModels(org.kie.kogito.decision.DecisionModels) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-runtimes by kiegroup.

the class DecisionTracingListenerTest method testWithRealRuntime.

private static List<EvaluateEvent> testWithRealRuntime(Map<String, Object> contextVariables, int expectedEvents, BiConsumer<DecisionModel, DMNContext> modelConsumer) {
    final DMNRuntime runtime = createDMNRuntime();
    Consumer<EvaluateEvent> eventConsumer = mock(Consumer.class);
    DecisionTracingListener listener = new DecisionTracingListener(eventConsumer);
    runtime.addListener(listener);
    final DecisionModel model = new DmnDecisionModel(runtime, MODEL_NAMESPACE, MODEL_NAME, () -> TEST_EXECUTION_ID_2);
    final DMNContext context = model.newContext(contextVariables);
    modelConsumer.accept(model, context);
    ArgumentCaptor<EvaluateEvent> eventCaptor = ArgumentCaptor.forClass(EvaluateEvent.class);
    verify(eventConsumer, times(expectedEvents)).accept(eventCaptor.capture());
    return eventCaptor.getAllValues();
}
Also used : DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DMNContext(org.kie.dmn.api.core.DMNContext) DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DecisionTestUtils.createDMNRuntime(org.kie.kogito.dmn.DecisionTestUtils.createDMNRuntime) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)

Example 13 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-runtimes by kiegroup.

the class BaseQuarkusDecisionTracingTest method testAsyncListenerAndCollectorWithRealEventsIsWorking.

@Test
void testAsyncListenerAndCollectorWithRealEventsIsWorking() throws IOException {
    final DMNRuntime runtime = buildDMNRuntime();
    final DecisionModel model = buildDecisionModel(runtime);
    final List<EvaluateEvent> events = testListener(true, runtime, model);
    assertEquals(getEvaluationEventCount(), events.size());
    testCollector(events, model);
}
Also used : DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) Test(org.junit.jupiter.api.Test)

Example 14 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-runtimes by kiegroup.

the class BaseQuarkusDecisionTracingTest method testSyncListenerAndCollectorWithRealEventsIsWorking.

@Test
void testSyncListenerAndCollectorWithRealEventsIsWorking() throws IOException {
    final DMNRuntime runtime = buildDMNRuntime();
    final DecisionModel model = buildDecisionModel(runtime);
    final List<EvaluateEvent> events = testListener(false, runtime, model);
    assertEquals(getEvaluationEventCount(), events.size());
    testCollector(events, model);
}
Also used : DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) Test(org.junit.jupiter.api.Test)

Example 15 with DecisionModel

use of org.kie.kogito.decision.DecisionModel in project kogito-runtimes by kiegroup.

the class DMNKogitoTest method testBasic.

@Test
public void testBasic() {
    DMNRuntime dmnRuntime = DMNKogito.createGenericDMNRuntime(new InputStreamReader(DMNKogitoTest.class.getResourceAsStream("TrafficViolation.dmn")));
    assertEquals(1, dmnRuntime.getModels().size());
    final String TRAFFIC_VIOLATION_NS = "https://github.com/kiegroup/drools/kie-dmn/_A4BCA8B8-CF08-433F-93B2-A2598F19ECFF";
    final String TRAFFIC_VIOLATION_NAME = "Traffic Violation";
    DecisionModel kogitoAPI = new DmnDecisionModel(dmnRuntime, TRAFFIC_VIOLATION_NS, TRAFFIC_VIOLATION_NAME);
    assertEquals(TRAFFIC_VIOLATION_NS, kogitoAPI.getDMNModel().getNamespace());
    assertEquals(TRAFFIC_VIOLATION_NAME, kogitoAPI.getDMNModel().getName());
    assertEquals(2, kogitoAPI.getDMNModel().getInputs().size(), "Traffic Violation model has 2 inputs");
}
Also used : InputStreamReader(java.io.InputStreamReader) DecisionModel(org.kie.kogito.decision.DecisionModel) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Test(org.junit.jupiter.api.Test)

Aggregations

DecisionModel (org.kie.kogito.decision.DecisionModel)28 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)22 DmnDecisionModel (org.kie.kogito.dmn.DmnDecisionModel)22 InputStreamReader (java.io.InputStreamReader)15 Test (org.junit.jupiter.api.Test)14 ArrayList (java.util.ArrayList)7 Prediction (org.kie.kogito.explainability.model.Prediction)7 PredictionInput (org.kie.kogito.explainability.model.PredictionInput)7 PredictionOutput (org.kie.kogito.explainability.model.PredictionOutput)7 PredictionProvider (org.kie.kogito.explainability.model.PredictionProvider)7 SimplePrediction (org.kie.kogito.explainability.model.SimplePrediction)7 DMNContext (org.kie.dmn.api.core.DMNContext)6 EvaluateEvent (org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)6 HashMap (java.util.HashMap)5 DMNResult (org.kie.dmn.api.core.DMNResult)5 PartialDependencePlotExplainer (org.kie.kogito.explainability.global.pdp.PartialDependencePlotExplainer)4 PartialDependenceGraph (org.kie.kogito.explainability.model.PartialDependenceGraph)4 Random (java.util.Random)3 LimeConfig (org.kie.kogito.explainability.local.lime.LimeConfig)3 LimeExplainer (org.kie.kogito.explainability.local.lime.LimeExplainer)3