Search in sources :

Example 6 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndComplexCustomType.

@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndComplexCustomType() {
    setupGraphWithDiagram();
    setupGraphWithInputData();
    final Definitions definitions = diagram.getDefinitions();
    final String complexItemDefinitionName = "tSmurf";
    final String complexItemDefinitionPart1Name = "tDateOfBirth";
    final String complexItemDefinitionPart2Name = "tIsBlue";
    final QName complexItemDefinitionPart1TypeRef = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
    final QName complexItemDefinitionPart2TypeRef = new QName(QName.NULL_NS_URI, BuiltInType.BOOLEAN.getName());
    final ItemDefinition complexItemDefinition = new ItemDefinition();
    complexItemDefinition.setName(new Name(complexItemDefinitionName));
    complexItemDefinition.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name(complexItemDefinitionPart1Name));
            setTypeRef(complexItemDefinitionPart1TypeRef);
        }
    });
    complexItemDefinition.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name(complexItemDefinitionPart2Name));
            setTypeRef(complexItemDefinitionPart2TypeRef);
        }
    });
    definitions.getItemDefinition().add(complexItemDefinition);
    final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, complexItemDefinitionName);
    inputData1.getVariable().setTypeRef(inputData1TypeRef);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    definition.enrich(Optional.of(NODE_UUID), decision, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    final List<InputClause> input = model.getInput();
    assertThat(input.size()).isEqualTo(3);
    assertThat(input.get(0).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(0).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_2);
    assertThat(input.get(0).getInputExpression().getTypeRef()).isEqualTo(INPUT_DATA_QNAME_2);
    assertThat(input.get(1).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(1).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + complexItemDefinitionPart1Name);
    assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(complexItemDefinitionPart1TypeRef);
    assertThat(input.get(2).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(2).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + complexItemDefinitionPart2Name);
    assertThat(input.get(2).getInputExpression().getTypeRef()).isEqualTo(complexItemDefinitionPart2TypeRef);
    assertStandardOutputClauseEnrichment(model);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 7 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenDecisionTypeRefIsStructureWithMultipleFields.

@Test
public void testModelEnrichmentWhenDecisionTypeRefIsStructureWithMultipleFields() {
    final DMNGraphUtils dmnGraphUtils = mock(DMNGraphUtils.class);
    final Definitions definitions = mock(Definitions.class);
    final HasExpression hasExpression = mock(HasExpression.class);
    final Decision decision = mock(Decision.class);
    final InformationItemPrimary informationItemPrimary = mock(InformationItemPrimary.class);
    final ItemDefinition tPerson = mockTPersonStructure();
    when(dmnGraphUtils.getModelDefinitions()).thenReturn(definitions);
    when(definitions.getItemDefinition()).thenReturn(Collections.singletonList(tPerson));
    when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(decision);
    when(decision.getVariable()).thenReturn(informationItemPrimary);
    when(informationItemPrimary.getTypeRef()).thenReturn(new QName("", TYPE_PERSON));
    final DecisionTableEditorDefinitionEnricher enricher = new DecisionTableEditorDefinitionEnricher(null, dmnGraphUtils, itemDefinitionUtils);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    final DecisionTable model = oModel.get();
    enricher.buildOutputClausesByDataType(hasExpression, model, new DecisionRule());
    final List<OutputClause> outputClauses = model.getOutput();
    assertThat(outputClauses.size()).isEqualTo(2);
    final OutputClause outputClause1 = outputClauses.get(0);
    final OutputClause outputClause2 = outputClauses.get(1);
    assertEquals("age", outputClause1.getName());
    assertEquals(NUMBER.asQName(), outputClause1.getTypeRef());
    assertEquals("name", outputClause2.getName());
    assertEquals(STRING.asQName(), outputClause2.getTypeRef());
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) DMNGraphUtils(org.kie.workbench.common.dmn.client.graph.DMNGraphUtils) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Test(org.junit.Test)

Example 8 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionEnricherTest method testAddInputClauseRequirementWhenDataTypeIsStructureAndDontHaveFields.

@Test
public void testAddInputClauseRequirementWhenDataTypeIsStructureAndDontHaveFields() {
    final ItemDefinition tPerson = mock(ItemDefinition.class);
    final String inputData = "InputData";
    final List<DecisionTableEditorDefinitionEnricher.ClauseRequirement> inputClauseRequirements = new ArrayList<>();
    final ItemDefinitionUtils itemDefinitionUtils = new ItemDefinitionUtils(mock(DMNGraphUtils.class));
    final DecisionTableEditorDefinitionEnricher enricher = new DecisionTableEditorDefinitionEnricher(null, null, itemDefinitionUtils);
    when(tPerson.getName()).thenReturn(new Name(TYPE_PERSON));
    when(tPerson.getTypeRef()).thenReturn(null);
    when(tPerson.getItemComponent()).thenReturn(emptyList());
    enricher.addInputClauseRequirement(tPerson, inputClauseRequirements, inputData);
    assertEquals(1, inputClauseRequirements.size());
    assertEquals("InputData", inputClauseRequirements.get(0).text);
    assertEquals(TYPE_PERSON, inputClauseRequirements.get(0).typeRef.getLocalPart());
}
Also used : ItemDefinitionUtils(org.kie.workbench.common.dmn.client.editors.types.common.ItemDefinitionUtils) DMNGraphUtils(org.kie.workbench.common.dmn.client.graph.DMNGraphUtils) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) ArrayList(java.util.ArrayList) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 9 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndRecursiveCustomType.

@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndRecursiveCustomType() {
    setupGraphWithDiagram();
    setupGraphWithInputData();
    final Definitions definitions = diagram.getDefinitions();
    final String tSmurfName = "tSmurf";
    final String tDateOfBirthName = "tDateOfBirth";
    final String tIsBlueName = "tIsBlue";
    final String tParentName = "tParent";
    final QName dateBuiltInType = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
    final QName booleanBuiltInType = new QName(QName.NULL_NS_URI, BuiltInType.BOOLEAN.getName());
    final QName parentCustomType = new QName(QName.NULL_NS_URI, tSmurfName);
    final ItemDefinition tSmurfCustomDataType = new ItemDefinition();
    tSmurfCustomDataType.setName(new Name(tSmurfName));
    tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name(tDateOfBirthName));
            setTypeRef(dateBuiltInType);
        }
    });
    tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name(tIsBlueName));
            setTypeRef(booleanBuiltInType);
        }
    });
    tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {

        {
            setName(new Name(tParentName));
            setTypeRef(parentCustomType);
        }
    });
    definitions.getItemDefinition().add(tSmurfCustomDataType);
    final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, tSmurfName);
    inputData1.getVariable().setTypeRef(inputData1TypeRef);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    definition.enrich(Optional.of(NODE_UUID), decision, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    final List<InputClause> input = model.getInput();
    assertThat(input.size()).isEqualTo(4);
    assertThat(input.get(0).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(0).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_2);
    assertThat(input.get(0).getInputExpression().getTypeRef()).isEqualTo(INPUT_DATA_QNAME_2);
    assertThat(input.get(1).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(1).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + tDateOfBirthName);
    assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(dateBuiltInType);
    assertThat(input.get(2).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(2).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + tIsBlueName);
    assertThat(input.get(2).getInputExpression().getTypeRef()).isEqualTo(booleanBuiltInType);
    assertThat(input.get(3).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
    assertThat(input.get(3).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + "." + tParentName);
    assertThat(input.get(3).getInputExpression().getTypeRef()).isEqualTo(parentCustomType);
    assertStandardOutputClauseEnrichment(model);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 10 with ItemDefinition

use of org.kie.workbench.common.dmn.api.definition.model.ItemDefinition in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionEnricherTest method testComputingClauseNameWithoutModelRefWhenModelRefHasMultipleLevels.

@Test
public void testComputingClauseNameWithoutModelRefWhenModelRefHasMultipleLevels() {
    final ItemDefinition itemComponent = new ItemDefinition();
    itemComponent.setName(new Name("a.b.c.age"));
    itemComponent.setAllowOnlyVisualChange(true);
    assertEquals("age", new DecisionTableEditorDefinitionEnricher(null, null, null).computeClauseName(itemComponent));
}
Also used : ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Aggregations

ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)119 Test (org.junit.Test)86 DataType (org.kie.workbench.common.dmn.client.editors.types.common.DataType)39 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)37 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)36 ArrayList (java.util.ArrayList)18 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)16 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)9 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)8 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)7 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)7 JSITItemDefinition (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition)7 Text (org.kie.workbench.common.dmn.api.property.dmn.Text)6 DataTypeManager (org.kie.workbench.common.dmn.client.editors.types.common.DataTypeManager)6 QName (javax.xml.namespace.QName)4 Import (org.kie.workbench.common.dmn.api.definition.model.Import)4 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)4 RefreshDataTypesListEvent (org.kie.workbench.common.dmn.client.editors.types.common.events.RefreshDataTypesListEvent)4 DMNGraphUtils (org.kie.workbench.common.dmn.client.graph.DMNGraphUtils)4 PMMLDocumentMetadata (org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata)3