use of org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent in project drools by kiegroup.
the class DMNRuntimeEventManagerUtils method fireAfterEvaluateDecisionTable.
public static void fireAfterEvaluateDecisionTable(DMNRuntimeEventManager eventManager, String nodeName, String dtName, DMNResult result, List<Integer> matches, List<Integer> fired) {
AfterEvaluateDecisionTableEvent event = new AfterEvaluateDecisionTableEventImpl(nodeName, dtName, result, matches, fired);
notifyListeners(eventManager, l -> l.afterEvaluateDecisionTable(event));
}
use of org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testDecisionTableDefaultValue.
@Test
public void testDecisionTableDefaultValue() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("decisiontable-default-value.dmn", this.getClass());
final DMNRuntimeEventListener listener = Mockito.mock(DMNRuntimeEventListener.class);
runtime.addListener(listener);
final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "decisiontable-default-value");
assertThat(dmnModel, notNullValue());
assertThat(dmnModel.getMessages().toString(), dmnModel.hasErrors(), is(false));
final DMNContext context = DMNFactory.newContext();
context.set("Age", new BigDecimal(16));
context.set("RiskCategory", "Medium");
context.set("isAffordable", true);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(dmnResult.getMessages().toString(), dmnResult.hasErrors(), is(false));
final DMNContext result = dmnResult.getContext();
assertThat(result.get("Approval Status"), is("Declined"));
final ArgumentCaptor<AfterEvaluateDecisionTableEvent> captor = ArgumentCaptor.forClass(AfterEvaluateDecisionTableEvent.class);
verify(listener).afterEvaluateDecisionTable(captor.capture());
assertThat(captor.getValue().getMatches(), is(empty()));
assertThat(captor.getValue().getSelected(), is(empty()));
}
use of org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testDecisionTableMultipleResults.
@Test
public void testDecisionTableMultipleResults() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("car_damage_responsibility.dmn", this.getClass());
final DMNRuntimeEventListener listener = Mockito.mock(DMNRuntimeEventListener.class);
runtime.addListener(listener);
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_820611e9-c21c-47cd-8e52-5cba2be9f9cc", "Car Damage Responsibility");
assertThat(dmnModel, notNullValue());
final DMNContext context = DMNFactory.newContext();
context.set("Membership Level", "Silver");
context.set("Damage Types", "Body");
context.set("Responsible", "Driver");
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(dmnResult.hasErrors(), is(false));
final DMNContext result = dmnResult.getContext();
assertThat((Map<String, Object>) result.get("Car Damage Responsibility"), hasEntry(is("EU Rent"), is(BigDecimal.valueOf(40))));
assertThat((Map<String, Object>) result.get("Car Damage Responsibility"), hasEntry(is("Renter"), is(BigDecimal.valueOf(60))));
assertThat(result.get("Payment method"), is("Check"));
final ArgumentCaptor<AfterEvaluateDecisionTableEvent> captor = ArgumentCaptor.forClass(AfterEvaluateDecisionTableEvent.class);
verify(listener, times(2)).afterEvaluateDecisionTable(captor.capture());
final AfterEvaluateDecisionTableEvent first = captor.getAllValues().get(0);
assertThat(first.getMatches(), is(Collections.singletonList(5)));
assertThat(first.getSelected(), is(Collections.singletonList(5)));
final AfterEvaluateDecisionTableEvent second = captor.getAllValues().get(1);
assertThat(second.getMatches(), is(Collections.singletonList(3)));
assertThat(second.getSelected(), is(Collections.singletonList(3)));
}
use of org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testTwoDecisionTables.
@Test
public void testTwoDecisionTables() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("two_decision_tables.dmn", this.getClass());
final DMNRuntimeEventListener listener = Mockito.mock(DMNRuntimeEventListener.class);
runtime.addListener(listener);
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_bbb692e7-3d95-407a-bf39-353085bf57f0", "Invocation with two decision table as parameters");
assertThat(dmnModel, notNullValue());
assertThat(dmnModel.getMessages().toString(), dmnModel.hasErrors(), is(false));
final DMNContext context = DMNFactory.newContext();
context.set("Number", 50);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(dmnResult.getMessages().toString(), dmnResult.hasErrors(), is(false));
final DMNContext result = dmnResult.getContext();
assertThat((Map<String, Object>) result.get("Decision Logic 2"), hasEntry("the 5 analysis", "A number greater than 5"));
assertThat((Map<String, Object>) result.get("Decision Logic 2"), hasEntry("the 100 analysis", "A number smaller than 100"));
final ArgumentCaptor<AfterEvaluateDecisionTableEvent> captor = ArgumentCaptor.forClass(AfterEvaluateDecisionTableEvent.class);
verify(listener, times(2)).afterEvaluateDecisionTable(captor.capture());
assertThat(captor.getAllValues().get(0).getDecisionTableName(), is("a"));
assertThat(captor.getAllValues().get(1).getDecisionTableName(), is("b"));
}
use of org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent in project drools by kiegroup.
the class DMNRuntimeTest method testEventListeners.
@Test
public void testEventListeners() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("car_damage_responsibility.dmn", this.getClass());
DMNRuntimeEventListener listener = mock(DMNRuntimeEventListener.class);
runtime.addListener(listener);
runtime.addListener(DMNRuntimeUtil.createListener());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_820611e9-c21c-47cd-8e52-5cba2be9f9cc", "Car Damage Responsibility");
assertThat(dmnModel, notNullValue());
DMNContext context = DMNFactory.newContext();
context.set("Membership Level", "Silver");
context.set("Damage Types", "Body");
context.set("Responsible", "Driver");
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
ArgumentCaptor<AfterEvaluateDecisionTableEvent> argument = ArgumentCaptor.forClass(AfterEvaluateDecisionTableEvent.class);
verify(listener, times(2)).beforeEvaluateDecision(any(BeforeEvaluateDecisionEvent.class));
verify(listener, times(2)).afterEvaluateDecision(any(AfterEvaluateDecisionEvent.class));
verify(listener, times(2)).beforeEvaluateDecisionTable(any(BeforeEvaluateDecisionTableEvent.class));
verify(listener, times(2)).afterEvaluateDecisionTable(argument.capture());
AfterEvaluateDecisionTableEvent dte = argument.getAllValues().get(0);
assertThat(dte.getDecisionTableName(), is("Car Damage Responsibility"));
// rows are 1-based
assertThat(dte.getMatches(), is(Arrays.asList(5)));
dte = argument.getAllValues().get(1);
assertThat(dte.getDecisionTableName(), is("Payment method"));
// rows are 1-based
assertThat(dte.getMatches(), is(Arrays.asList(3)));
assertThat(dmnResult.hasErrors(), is(false));
DMNContext result = dmnResult.getContext();
assertThat((Map<String, Object>) result.get("Car Damage Responsibility"), hasEntry(is("EU Rent"), is(BigDecimal.valueOf(40))));
assertThat((Map<String, Object>) result.get("Car Damage Responsibility"), hasEntry(is("Renter"), is(BigDecimal.valueOf(60))));
assertThat(result.get("Payment method"), is("Check"));
}
Aggregations