use of org.kie.dmn.api.feel.runtime.events.FEELEvent in project drools by kiegroup.
the class SimpleDecisionTablesTest method testMain.
@Test
public void testMain() {
List<FEELEvent> events = new ArrayList<>();
FEELEventListener listener = evt -> events.add(evt);
feel.addListener(listener);
String expression = loadExpression("simple_decision_tables.feel");
Map context = (Map) feel.evaluate(expression);
System.out.println(printContext(context));
assertThat(context.get("result1"), is("Adult"));
assertThat(context.get("result2"), is("Medium"));
assertThat((Map<?, ?>) context.get("result3"), hasSize(2));
assertThat((Map<?, ?>) context.get("result3"), hasEntry("Out1", "out1b"));
assertThat((Map<?, ?>) context.get("result3"), hasEntry("Out2", "out2b"));
assertThat((Map<?, ?>) context.get("result4"), hasSize(2));
assertThat((Map<?, ?>) context.get("result4"), hasEntry("Out1", "io1a"));
assertThat((Map<?, ?>) context.get("result4"), hasEntry("Out2", "io2a"));
assertThat(context.get("result5"), nullValue());
assertTrue(events.stream().anyMatch(e -> e instanceof HitPolicyViolationEvent && e.getSeverity().equals(Severity.WARN)));
feel.removeListener(listener);
}
use of org.kie.dmn.api.feel.runtime.events.FEELEvent in project drools by kiegroup.
the class KieExtendedBaseFEELTest method testExpression.
@Test
public void testExpression() {
FEELEventListener listener = mock(FEELEventListener.class);
feel.addListener(listener);
feel.addListener(evt -> {
System.out.println(evt);
});
assertResult(expression, result);
if (severity != null) {
ArgumentCaptor<FEELEvent> captor = ArgumentCaptor.forClass(FEELEvent.class);
verify(listener, atLeastOnce()).onEvent(captor.capture());
assertThat(captor.getValue().getSeverity(), is(severity));
} else {
verify(listener, never()).onEvent(any(FEELEvent.class));
}
}
use of org.kie.dmn.api.feel.runtime.events.FEELEvent in project drools by kiegroup.
the class FunctionTestUtil method assertResultError.
public static <T> void assertResultError(final FEELFnResult<T> result, final Class expectedErrorEventClass) {
Assert.assertThat(result, Matchers.notNullValue());
Assert.assertThat(result.isLeft(), Matchers.is(true));
final FEELEvent resultEvent = result.cata(left -> left, right -> null);
checkErrorEvent(resultEvent, expectedErrorEventClass);
}
use of org.kie.dmn.api.feel.runtime.events.FEELEvent in project drools by kiegroup.
the class ExtendedFunctionsBaseFEELTest method testExpression.
@Test
public void testExpression() {
FEELEventListener listener = mock(FEELEventListener.class);
feel.addListener(listener);
feel.addListener(evt -> {
System.out.println(evt);
});
assertResult(expression, result);
if (severity != null) {
ArgumentCaptor<FEELEvent> captor = ArgumentCaptor.forClass(FEELEvent.class);
verify(listener, atLeastOnce()).onEvent(captor.capture());
assertThat(captor.getValue().getSeverity(), is(severity));
} else {
verify(listener, never()).onEvent(any(FEELEvent.class));
}
}
Aggregations