Search in sources :

Example 1 with ItemDefNode

use of org.kie.dmn.api.core.ast.ItemDefNode in project drools by kiegroup.

the class DMNCompilerTest method testItemDefAllowedValuesString.

@Test
public void testItemDefAllowedValuesString() {
    final DMNRuntime runtime = createRuntime("0003-input-data-string-allowed-values.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0003-input-data-string-allowed-values");
    assertThat(dmnModel, notNullValue());
    final ItemDefNode itemDef = dmnModel.getItemDefinitionByName("tEmploymentStatus");
    assertThat(itemDef.getName(), is("tEmploymentStatus"));
    assertThat(itemDef.getId(), is(nullValue()));
    final DMNType type = itemDef.getType();
    assertThat(type, is(notNullValue()));
    assertThat(type.getName(), is("tEmploymentStatus"));
    assertThat(type.getId(), is(nullValue()));
    assertThat(type, is(instanceOf(SimpleTypeImpl.class)));
    final SimpleTypeImpl feelType = (SimpleTypeImpl) type;
    final EvaluationContext ctx = new EvaluationContextImpl(ClassLoaderUtil.findDefaultClassLoader(), null);
    assertThat(feelType.getFeelType(), is(instanceOf(AliasFEELType.class)));
    assertThat(feelType.getFeelType().getName(), is("tEmploymentStatus"));
    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 ItemDefNode

use of org.kie.dmn.api.core.ast.ItemDefNode in project drools by kiegroup.

the class DMNInputRuntimeTest method testOrdering.

@Test
public void testOrdering() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Order.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_6318588b-c32f-4070-848b-bd8017e6b94e", "Drawing 1");
    int index = 1;
    for (InputDataNode node : dmnModel.getInputs()) {
        assertTrue(node.getName().endsWith("" + index++));
    }
    index = 1;
    for (DecisionNode node : dmnModel.getDecisions()) {
        assertTrue(node.getName().endsWith("" + index++));
    }
    index = 1;
    for (BusinessKnowledgeModelNode node : dmnModel.getBusinessKnowledgeModels()) {
        assertTrue(node.getName().endsWith("" + index++));
    }
    index = 1;
    for (ItemDefNode node : dmnModel.getItemDefinitions()) {
        assertTrue(node.getName().endsWith("" + index++));
    }
    index = 1;
    for (DecisionServiceNode node : dmnModel.getDecisionServices()) {
        assertTrue(node.getName().endsWith("" + index++));
    }
}
Also used : DecisionServiceNode(org.kie.dmn.api.core.ast.DecisionServiceNode) ItemDefNode(org.kie.dmn.api.core.ast.ItemDefNode) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 3 with ItemDefNode

use of org.kie.dmn.api.core.ast.ItemDefNode in project drools by kiegroup.

the class DMNCompilerTest method testCompositeItemDefinition.

@Test
public void testCompositeItemDefinition() {
    final DMNRuntime runtime = createRuntime("0008-LX-arithmetic.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0008-LX-arithmetic");
    assertThat(dmnModel, notNullValue());
    final ItemDefNode itemDef = dmnModel.getItemDefinitionByName("tLoan");
    assertThat(itemDef.getName(), is("tLoan"));
    assertThat(itemDef.getId(), is("tLoan"));
    final DMNType type = itemDef.getType();
    assertThat(type, is(notNullValue()));
    assertThat(type.getName(), is("tLoan"));
    assertThat(type.getId(), is("tLoan"));
    assertThat(type, is(instanceOf(CompositeTypeImpl.class)));
    final CompositeTypeImpl compType = (CompositeTypeImpl) type;
    assertThat(compType.getFields().size(), is(3));
    final DMNType principal = compType.getFields().get("principal");
    assertThat(principal, is(notNullValue()));
    assertThat(principal.getName(), is("number"));
    assertThat(((SimpleTypeImpl) principal).getFeelType(), is(BuiltInType.NUMBER));
    final DMNType rate = compType.getFields().get("rate");
    assertThat(rate, is(notNullValue()));
    assertThat(rate.getName(), is("number"));
    assertThat(((SimpleTypeImpl) rate).getFeelType(), is(BuiltInType.NUMBER));
    final DMNType termMonths = compType.getFields().get("termMonths");
    assertThat(termMonths, is(notNullValue()));
    assertThat(termMonths.getName(), is("number"));
    assertThat(((SimpleTypeImpl) termMonths).getFeelType(), is(BuiltInType.NUMBER));
}
Also used : ItemDefNode(org.kie.dmn.api.core.ast.ItemDefNode) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) CompositeTypeImpl(org.kie.dmn.core.impl.CompositeTypeImpl) DMNType(org.kie.dmn.api.core.DMNType) Test(org.junit.Test)

Example 4 with ItemDefNode

use of org.kie.dmn.api.core.ast.ItemDefNode in project drools by kiegroup.

the class DMNCompilerTest method testItemDefAllowedValuesString.

@Test
public void testItemDefAllowedValuesString() {
    final DMNRuntime runtime = createRuntime("0003-input-data-string-allowed-values.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0003-input-data-string-allowed-values");
    assertThat(dmnModel, notNullValue());
    final ItemDefNode itemDef = dmnModel.getItemDefinitionByName("tEmploymentStatus");
    assertThat(itemDef.getName(), is("tEmploymentStatus"));
    assertThat(itemDef.getId(), is(nullValue()));
    final DMNType type = itemDef.getType();
    assertThat(type, is(notNullValue()));
    assertThat(type.getName(), is("tEmploymentStatus"));
    assertThat(type.getId(), is(nullValue()));
    assertThat(type, is(instanceOf(SimpleTypeImpl.class)));
    final SimpleTypeImpl feelType = (SimpleTypeImpl) type;
    final EvaluationContext ctx = new EvaluationContextImpl(ClassLoaderUtil.findDefaultClassLoader(), null);
    assertThat(feelType.getFeelType(), is(instanceOf(AliasFEELType.class)));
    assertThat(feelType.getFeelType().getName(), is("tEmploymentStatus"));
    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 5 with ItemDefNode

use of org.kie.dmn.api.core.ast.ItemDefNode in project drools by kiegroup.

the class DMNCompilerTest method testCompositeItemDefinition.

@Test
public void testCompositeItemDefinition() {
    final DMNRuntime runtime = createRuntime("0008-LX-arithmetic.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0008-LX-arithmetic");
    assertThat(dmnModel, notNullValue());
    final ItemDefNode itemDef = dmnModel.getItemDefinitionByName("tLoan");
    assertThat(itemDef.getName(), is("tLoan"));
    assertThat(itemDef.getId(), is("tLoan"));
    final DMNType type = itemDef.getType();
    assertThat(type, is(notNullValue()));
    assertThat(type.getName(), is("tLoan"));
    assertThat(type.getId(), is("tLoan"));
    assertThat(type, is(instanceOf(CompositeTypeImpl.class)));
    final CompositeTypeImpl compType = (CompositeTypeImpl) type;
    assertThat(compType.getFields().size(), is(3));
    final DMNType principal = compType.getFields().get("principal");
    assertThat(principal, is(notNullValue()));
    assertThat(principal.getName(), is("number"));
    assertThat(((SimpleTypeImpl) principal).getFeelType(), is(BuiltInType.NUMBER));
    final DMNType rate = compType.getFields().get("rate");
    assertThat(rate, is(notNullValue()));
    assertThat(rate.getName(), is("number"));
    assertThat(((SimpleTypeImpl) rate).getFeelType(), is(BuiltInType.NUMBER));
    final DMNType termMonths = compType.getFields().get("termMonths");
    assertThat(termMonths, is(notNullValue()));
    assertThat(termMonths.getName(), is("number"));
    assertThat(((SimpleTypeImpl) termMonths).getFeelType(), is(BuiltInType.NUMBER));
}
Also used : ItemDefNode(org.kie.dmn.api.core.ast.ItemDefNode) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) CompositeTypeImpl(org.kie.dmn.core.impl.CompositeTypeImpl) DMNType(org.kie.dmn.api.core.DMNType) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 DMNModel (org.kie.dmn.api.core.DMNModel)5 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)5 ItemDefNode (org.kie.dmn.api.core.ast.ItemDefNode)5 DMNType (org.kie.dmn.api.core.DMNType)4 CompositeTypeImpl (org.kie.dmn.core.impl.CompositeTypeImpl)2 SimpleTypeImpl (org.kie.dmn.core.impl.SimpleTypeImpl)2 EvaluationContext (org.kie.dmn.feel.lang.EvaluationContext)2 EvaluationContextImpl (org.kie.dmn.feel.lang.impl.EvaluationContextImpl)2 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)1 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)1 DecisionServiceNode (org.kie.dmn.api.core.ast.DecisionServiceNode)1 InputDataNode (org.kie.dmn.api.core.ast.InputDataNode)1