use of org.kie.workbench.common.dmn.api.definition.model.DecisionTable in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenTopLevelDecisionTableWithoutInputData.
@Test
public void testModelEnrichmentWhenTopLevelDecisionTableWithoutInputData() {
final String uuid = UUID.uuid();
final Node<Definition, Edge> node = new NodeImpl<>(uuid);
graph.addNode(node);
final Optional<DecisionTable> oModel = definition.getModelClass();
definition.enrich(Optional.of(uuid), decision, oModel);
final DecisionTable model = oModel.get();
assertBasicEnrichment(model);
assertStandardInputClauseEnrichment(model);
assertStandardOutputClauseEnrichment(model);
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionTable 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);
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionTable 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());
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionTable in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenHasExpressionIsNotHasVariable.
@Test
public void testModelEnrichmentWhenHasExpressionIsNotHasVariable() {
final Optional<DecisionTable> oModel = definition.getModelClass();
definition.enrich(Optional.empty(), decision, oModel);
final DecisionTable model = oModel.get();
assertBasicEnrichment(model);
assertStandardInputClauseEnrichment(model);
final List<OutputClause> output = model.getOutput();
assertThat(output.size()).isEqualTo(1);
assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
assertThat(output.get(0).getTypeRef()).isEqualTo(BuiltInType.UNDEFINED.asQName());
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionTable 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);
}
Aggregations