use of org.kie.dmn.api.core.DMNType in project drools by kiegroup.
the class InputDataCompiler method compileNode.
@Override
public void compileNode(DRGElement de, DMNCompilerImpl compiler, DMNModelImpl model) {
InputData input = (InputData) de;
InputDataNodeImpl idn = new InputDataNodeImpl(input);
if (input.getVariable() != null) {
DMNCompilerHelper.checkVariableName(model, input, input.getName());
DMNType type = compiler.resolveTypeRef(model, idn, de, input.getVariable(), input.getVariable().getTypeRef());
idn.setType(type);
} else {
idn.setType(DMNTypeRegistry.UNKNOWN);
DMNCompilerHelper.reportMissingVariable(model, de, input, Msg.MISSING_VARIABLE_FOR_INPUT);
}
model.addInput(idn);
}
use of org.kie.dmn.api.core.DMNType 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));
}
use of org.kie.dmn.api.core.DMNType in project drools by kiegroup.
the class DMNCompilerTest method testCompositeItemDefinition.
@Test
public void testCompositeItemDefinition() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0008-LX-arithmetic.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0008-LX-arithmetic");
assertThat(dmnModel, notNullValue());
ItemDefNode itemDef = dmnModel.getItemDefinitionByName("tLoan");
assertThat(itemDef.getName(), is("tLoan"));
assertThat(itemDef.getId(), is("tLoan"));
DMNType type = itemDef.getType();
assertThat(type, is(notNullValue()));
assertThat(type.getName(), is("tLoan"));
assertThat(type.getId(), is("tLoan"));
assertThat(type, is(instanceOf(CompositeTypeImpl.class)));
CompositeTypeImpl compType = (CompositeTypeImpl) type;
assertThat(compType.getFields().size(), is(3));
DMNType principal = compType.getFields().get("principal");
assertThat(principal, is(notNullValue()));
assertThat(principal.getName(), is("number"));
assertThat(((SimpleTypeImpl) principal).getFeelType(), is(BuiltInType.NUMBER));
DMNType rate = compType.getFields().get("rate");
assertThat(rate, is(notNullValue()));
assertThat(rate.getName(), is("number"));
assertThat(((SimpleTypeImpl) rate).getFeelType(), is(BuiltInType.NUMBER));
DMNType termMonths = compType.getFields().get("termMonths");
assertThat(termMonths, is(notNullValue()));
assertThat(termMonths.getName(), is("number"));
assertThat(((SimpleTypeImpl) termMonths).getFeelType(), is(BuiltInType.NUMBER));
}
use of org.kie.dmn.api.core.DMNType 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")));
}
Aggregations