Search in sources :

Example 16 with FEELEvent

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);
}
Also used : FEEL(org.kie.dmn.feel.FEEL) CoreMatchers(org.hamcrest.CoreMatchers) FEELEventListener(org.kie.dmn.api.feel.runtime.events.FEELEventListener) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) BigDecimal(java.math.BigDecimal) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent) Map(java.util.Map) IsCollectionWithSize(org.hamcrest.collection.IsCollectionWithSize) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) Description(org.hamcrest.Description) HitPolicyViolationEvent(org.kie.dmn.feel.runtime.events.HitPolicyViolationEvent) Logger(org.slf4j.Logger) Severity(org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity) Collection(java.util.Collection) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) List(java.util.List) Ignore(org.junit.Ignore) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matcher(org.hamcrest.Matcher) ArrayList(java.util.ArrayList) FEELEventListener(org.kie.dmn.api.feel.runtime.events.FEELEventListener) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent) Map(java.util.Map) HitPolicyViolationEvent(org.kie.dmn.feel.runtime.events.HitPolicyViolationEvent) Test(org.junit.Test)

Example 17 with FEELEvent

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));
    }
}
Also used : FEELEventListener(org.kie.dmn.api.feel.runtime.events.FEELEventListener) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent) Test(org.junit.Test)

Example 18 with FEELEvent

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);
}
Also used : FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent)

Example 19 with FEELEvent

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));
    }
}
Also used : FEELEventListener(org.kie.dmn.api.feel.runtime.events.FEELEventListener) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent) Test(org.junit.Test)

Aggregations

FEELEvent (org.kie.dmn.api.feel.runtime.events.FEELEvent)19 Test (org.junit.Test)5 FEELEventListener (org.kie.dmn.api.feel.runtime.events.FEELEventListener)5 FEELEventBase (org.kie.dmn.feel.runtime.events.FEELEventBase)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 EvaluationContextImpl (org.kie.dmn.feel.lang.impl.EvaluationContextImpl)4 List (java.util.List)3 Severity (org.kie.dmn.api.feel.runtime.events.FEELEvent.Severity)3 FEEL (org.kie.dmn.feel.FEEL)3 HitPolicyViolationEvent (org.kie.dmn.feel.runtime.events.HitPolicyViolationEvent)3 BigDecimal (java.math.BigDecimal)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 DMNContext (org.kie.dmn.api.core.DMNContext)2 DMNResultImpl (org.kie.dmn.core.impl.DMNResultImpl)2 InvalidInputEvent (org.kie.dmn.feel.runtime.events.InvalidInputEvent)2 InvalidParametersEvent (org.kie.dmn.feel.runtime.events.InvalidParametersEvent)2 Logger (org.slf4j.Logger)2