Search in sources :

Example 1 with SimpleTypeImpl

use of org.kie.dmn.core.impl.SimpleTypeImpl in project drools by kiegroup.

the class DMNCompilerTest method testItemDefAllowedValuesString.

@Test
public void testItemDefAllowedValuesString() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0003-input-data-string-allowed-values.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0003-input-data-string-allowed-values");
    assertThat(dmnModel, notNullValue());
    ItemDefNode itemDef = dmnModel.getItemDefinitionByName("tEmploymentStatus");
    assertThat(itemDef.getName(), is("tEmploymentStatus"));
    assertThat(itemDef.getId(), is(nullValue()));
    DMNType type = itemDef.getType();
    assertThat(type, is(notNullValue()));
    assertThat(type.getName(), is("tEmploymentStatus"));
    assertThat(type.getId(), is(nullValue()));
    assertThat(type, is(instanceOf(SimpleTypeImpl.class)));
    SimpleTypeImpl feelType = (SimpleTypeImpl) type;
    EvaluationContext ctx = new EvaluationContextImpl(null);
    assertThat(feelType.getFeelType(), is(BuiltInType.STRING));
    assertThat(feelType.getAllowedValuesFEEL().size(), is(4));
    assertThat(feelType.getAllowedValuesFEEL().get(0).apply(ctx, "UNEMPLOYED"), is(true));
    assertThat(feelType.getAllowedValuesFEEL().get(1).apply(ctx, "EMPLOYED"), is(true));
    assertThat(feelType.getAllowedValuesFEEL().get(2).apply(ctx, "SELF-EMPLOYED"), is(true));
    assertThat(feelType.getAllowedValuesFEEL().get(3).apply(ctx, "STUDENT"), is(true));
}
Also used : EvaluationContextImpl(org.kie.dmn.feel.lang.impl.EvaluationContextImpl) SimpleTypeImpl(org.kie.dmn.core.impl.SimpleTypeImpl) ItemDefNode(org.kie.dmn.api.core.ast.ItemDefNode) EvaluationContext(org.kie.dmn.feel.lang.EvaluationContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) DMNType(org.kie.dmn.api.core.DMNType) Test(org.junit.Test)

Example 2 with SimpleTypeImpl

use of org.kie.dmn.core.impl.SimpleTypeImpl in project drools by kiegroup.

the class DMNTypeTest method testAllowedValuesForASimpleTypeCollection.

@Test
public void testAllowedValuesForASimpleTypeCollection() {
    // DROOLS-2357
    final String testNS = "testDROOLS2357";
    FEEL feel = FEEL.newInstance();
    DMNType tDecision1 = typeRegistry.registerType(new SimpleTypeImpl(testNS, "tListOfVowels", null, true, feel.evaluateUnaryTests("\"a\",\"e\",\"i\",\"o\",\"u\""), FEEL_STRING, BuiltInType.STRING));
    assertTrue(tDecision1.isAssignableValue("a"));
    assertTrue(tDecision1.isAssignableValue(Arrays.asList("a")));
    assertFalse(tDecision1.isAssignableValue("z"));
    assertTrue(tDecision1.isAssignableValue(Arrays.asList("a", "e")));
    assertFalse(tDecision1.isAssignableValue(Arrays.asList("a", "e", "zzz")));
}
Also used : SimpleTypeImpl(org.kie.dmn.core.impl.SimpleTypeImpl) FEEL(org.kie.dmn.feel.FEEL) DMNType(org.kie.dmn.api.core.DMNType) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 DMNType (org.kie.dmn.api.core.DMNType)2 SimpleTypeImpl (org.kie.dmn.core.impl.SimpleTypeImpl)2 DMNModel (org.kie.dmn.api.core.DMNModel)1 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)1 ItemDefNode (org.kie.dmn.api.core.ast.ItemDefNode)1 FEEL (org.kie.dmn.feel.FEEL)1 EvaluationContext (org.kie.dmn.feel.lang.EvaluationContext)1 EvaluationContextImpl (org.kie.dmn.feel.lang.impl.EvaluationContextImpl)1