use of org.kie.dmn.api.core.event.AfterEvaluateContextEntryEvent in project drools by kiegroup.
the class DMNRuntimeEventManagerUtils method fireAfterEvaluateContextEntry.
public static void fireAfterEvaluateContextEntry(DMNRuntimeEventManager eventManager, String nodeName, String variableName, String variableId, String expressionId, Object expressionResult, DMNResult result) {
if (eventManager.hasListeners()) {
AfterEvaluateContextEntryEvent event = new AfterEvaluateContextEntryEventImpl(nodeName, variableName, variableId, expressionId, expressionResult, result);
notifyListeners(eventManager, l -> l.afterEvaluateContextEntry(event));
}
}
use of org.kie.dmn.api.core.event.AfterEvaluateContextEntryEvent in project drools by kiegroup.
the class DMNRuntimeTest method testContextEventListeners.
@Test
public void testContextEventListeners() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("context_listener.dmn", this.getClass());
final DMNRuntimeEventListener listener = mock(DMNRuntimeEventListener.class);
runtime.addListener(listener);
runtime.addListener(DMNRuntimeUtil.createListener());
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_73481d02-76fb-4927-ac11-5d936882e16c", "context listener");
assertThat(dmnModel, notNullValue());
final DMNContext context = DMNFactory.newContext();
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
final ArgumentCaptor<AfterEvaluateContextEntryEvent> argument = ArgumentCaptor.forClass(AfterEvaluateContextEntryEvent.class);
verify(listener, times(1)).beforeEvaluateDecision(any(BeforeEvaluateDecisionEvent.class));
verify(listener, times(1)).afterEvaluateDecision(any(AfterEvaluateDecisionEvent.class));
verify(listener, times(5)).beforeEvaluateContextEntry(any(BeforeEvaluateContextEntryEvent.class));
verify(listener, times(5)).afterEvaluateContextEntry(argument.capture());
AfterEvaluateContextEntryEvent aece = argument.getAllValues().get(0);
assertThat(aece.getNodeName(), is("d1"));
assertThat(aece.getVariableName(), is("a1"));
assertThat(aece.getVariableId(), is("_b199c7b1-cb87-4a92-b045-a2954ccc9d01"));
assertThat(aece.getExpressionId(), is("_898c24f8-93da-4fe2-827c-924c30956833"));
assertThat(aece.getExpressionResult(), is(BigDecimal.valueOf(10)));
aece = argument.getAllValues().get(1);
assertThat(aece.getNodeName(), is("d1"));
assertThat(aece.getVariableName(), is("c1"));
assertThat(aece.getVariableId(), is("_38a88aef-8b3c-424d-b60c-a139ffb610e1"));
assertThat(aece.getExpressionId(), is("_879c4ac6-8b25-4cd1-9b8e-c18d0b0b281c"));
assertThat(aece.getExpressionResult(), is("a"));
aece = argument.getAllValues().get(2);
assertThat(aece.getNodeName(), is("d1"));
assertThat(aece.getVariableName(), is("c2"));
assertThat(aece.getVariableId(), is("_3aad82f0-74b9-4921-8b2f-d6c277c840db"));
assertThat(aece.getExpressionId(), is("_9acf4baf-6c49-4d47-88ab-2e511e598e04"));
assertThat(aece.getExpressionResult(), is("b"));
aece = argument.getAllValues().get(3);
assertThat(aece.getNodeName(), is("d1"));
assertThat(aece.getVariableName(), is("b1"));
assertThat(aece.getVariableId(), is("_f4a6c2ba-e6e9-4dbd-b776-edef2c1a1343"));
assertThat(aece.getExpressionId(), is("_c450d947-1874-41fe-9c0a-da5f1cca7fde"));
assertThat((Map<String, Object>) aece.getExpressionResult(), hasEntry(is("c1"), is("a")));
assertThat((Map<String, Object>) aece.getExpressionResult(), hasEntry(is("c2"), is("b")));
aece = argument.getAllValues().get(4);
assertThat(aece.getNodeName(), is("d1"));
assertThat(aece.getVariableName(), is(DMNContextEvaluator.RESULT_ENTRY));
assertThat(aece.getVariableId(), nullValue());
assertThat(aece.getExpressionId(), is("_4264b25c-d676-4516-ab8a-a4ff34e7a95c"));
assertThat(aece.getExpressionResult(), is("a"));
assertThat(dmnResult.hasErrors(), is(false));
final DMNContext result = dmnResult.getContext();
assertThat(result.get("d1"), is("a"));
}
use of org.kie.dmn.api.core.event.AfterEvaluateContextEntryEvent in project drools by kiegroup.
the class DMNRuntimeTest method testContextEventListeners.
@Test
public void testContextEventListeners() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("context_listener.dmn", this.getClass());
final DMNRuntimeEventListener listener = mock(DMNRuntimeEventListener.class);
runtime.addListener(listener);
runtime.addListener(DMNRuntimeUtil.createListener());
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_73481d02-76fb-4927-ac11-5d936882e16c", "context listener");
assertThat(dmnModel, notNullValue());
final DMNContext context = DMNFactory.newContext();
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
final ArgumentCaptor<AfterEvaluateContextEntryEvent> argument = ArgumentCaptor.forClass(AfterEvaluateContextEntryEvent.class);
verify(listener, times(1)).beforeEvaluateDecision(any(BeforeEvaluateDecisionEvent.class));
verify(listener, times(1)).afterEvaluateDecision(any(AfterEvaluateDecisionEvent.class));
verify(listener, times(5)).beforeEvaluateContextEntry(any(BeforeEvaluateContextEntryEvent.class));
verify(listener, times(5)).afterEvaluateContextEntry(argument.capture());
AfterEvaluateContextEntryEvent aece = argument.getAllValues().get(0);
assertThat(aece.getNodeName(), is("d1"));
assertThat(aece.getVariableName(), is("a1"));
assertThat(aece.getVariableId(), is("_b199c7b1-cb87-4a92-b045-a2954ccc9d01"));
assertThat(aece.getExpressionId(), is("_898c24f8-93da-4fe2-827c-924c30956833"));
assertThat(aece.getExpressionResult(), is(BigDecimal.valueOf(10)));
aece = argument.getAllValues().get(1);
assertThat(aece.getNodeName(), is("d1"));
assertThat(aece.getVariableName(), is("c1"));
assertThat(aece.getVariableId(), is("_38a88aef-8b3c-424d-b60c-a139ffb610e1"));
assertThat(aece.getExpressionId(), is("_879c4ac6-8b25-4cd1-9b8e-c18d0b0b281c"));
assertThat(aece.getExpressionResult(), is("a"));
aece = argument.getAllValues().get(2);
assertThat(aece.getNodeName(), is("d1"));
assertThat(aece.getVariableName(), is("c2"));
assertThat(aece.getVariableId(), is("_3aad82f0-74b9-4921-8b2f-d6c277c840db"));
assertThat(aece.getExpressionId(), is("_9acf4baf-6c49-4d47-88ab-2e511e598e04"));
assertThat(aece.getExpressionResult(), is("b"));
aece = argument.getAllValues().get(3);
assertThat(aece.getNodeName(), is("d1"));
assertThat(aece.getVariableName(), is("b1"));
assertThat(aece.getVariableId(), is("_f4a6c2ba-e6e9-4dbd-b776-edef2c1a1343"));
assertThat(aece.getExpressionId(), is("_c450d947-1874-41fe-9c0a-da5f1cca7fde"));
assertThat((Map<String, Object>) aece.getExpressionResult(), hasEntry(is("c1"), is("a")));
assertThat((Map<String, Object>) aece.getExpressionResult(), hasEntry(is("c2"), is("b")));
aece = argument.getAllValues().get(4);
assertThat(aece.getNodeName(), is("d1"));
assertThat(aece.getVariableName(), is(DMNContextEvaluator.RESULT_ENTRY));
assertThat(aece.getVariableId(), nullValue());
assertThat(aece.getExpressionId(), is("_4264b25c-d676-4516-ab8a-a4ff34e7a95c"));
assertThat(aece.getExpressionResult(), is("a"));
assertThat(dmnResult.hasErrors(), is(false));
final DMNContext result = dmnResult.getContext();
assertThat(result.get("d1"), is("a"));
}
Aggregations