@Test public void testItemDefAllowedValuesString() { final DMNRuntime runtime = DMNRuntimeUtil.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 ) ); }
@Test public void testCompositeItemDefinition() { final DMNRuntime runtime = DMNRuntimeUtil.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 ) ); }
@Test public void testAllowedValuesForASimpleTypeCollection() { // DROOLS-2357 final String testNS = "testDROOLS2357"; final FEEL feel = FEEL.newInstance(); final 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(Collections.singletonList("a"))); assertFalse(tDecision1.isAssignableValue("z")); assertTrue(tDecision1.isAssignableValue(Arrays.asList("a", "e"))); assertFalse(tDecision1.isAssignableValue(Arrays.asList("a", "e", "zzz"))); }