use of org.kie.workbench.common.dmn.api.definition.model.DecisionTable in project kie-wb-common by kiegroup.
the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsContextEntryDefaultResult.
@Test
public void testModelEnrichmentWhenParentIsContextEntryDefaultResult() {
final String name = "decision";
final Context context = new Context();
final ContextEntry contextEntry = new ContextEntry();
context.getContextEntry().add(contextEntry);
contextEntry.setParent(context);
context.setParent(decision);
decision.setName(new Name(name));
decision.getVariable().setTypeRef(OUTPUT_DATA_QNAME);
final Optional<DecisionTable> oModel = definition.getModelClass();
oModel.get().setParent(contextEntry);
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(OUTPUT_DATA_QNAME);
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 testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndSimpleCustomType.
@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithInputDataAndSimpleCustomType() {
setupGraphWithDiagram();
setupGraphWithInputData();
final Definitions definitions = diagram.getDefinitions();
final String simpleItemDefinitionName = "tSmurf";
final QName simpleItemDefinitionTypeRef = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
final ItemDefinition simpleItemDefinition = new ItemDefinition();
simpleItemDefinition.setName(new Name(simpleItemDefinitionName));
simpleItemDefinition.setTypeRef(simpleItemDefinitionTypeRef);
definitions.getItemDefinition().add(simpleItemDefinition);
final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, simpleItemDefinitionName);
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(2);
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);
assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(simpleItemDefinitionTypeRef);
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 testModelEnrichmentWhenTopLevelDecisionTableWithInputData.
@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithInputData() {
setupGraphWithDiagram();
setupGraphWithInputData();
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(2);
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);
assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(INPUT_DATA_QNAME_1);
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 testModelEnrichmentWhenTopLevelDecisionTableWithMultipleHierarchyCustomTypes.
@Test
@SuppressWarnings("unchecked")
public void testModelEnrichmentWhenTopLevelDecisionTableWithMultipleHierarchyCustomTypes() {
setupGraphWithDiagram();
setupGraphWithInputData();
final Definitions definitions = diagram.getDefinitions();
final String tSmurf = "tSmurf";
final String tSmurfAddress = "tSmurfAddress";
final QName dateBuiltInType = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
final QName stringBuiltInType = new QName(QName.NULL_NS_URI, STRING.getName());
final ItemDefinition tSmurfAddressCustomDataType = new ItemDefinition();
tSmurfAddressCustomDataType.setName(new Name(tSmurfAddress));
tSmurfAddressCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name("line1"));
setTypeRef(stringBuiltInType);
}
});
tSmurfAddressCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name("line2"));
setTypeRef(stringBuiltInType);
}
});
final ItemDefinition tSmurfCustomDataType = new ItemDefinition();
tSmurfCustomDataType.setName(new Name(tSmurf));
tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name("dob"));
setTypeRef(dateBuiltInType);
}
});
tSmurfCustomDataType.getItemComponent().add(new ItemDefinition() {
{
setName(new Name("address"));
getItemComponent().add(tSmurfAddressCustomDataType);
}
});
definitions.getItemDefinition().add(tSmurfCustomDataType);
final QName inputData1TypeRef = new QName(QName.NULL_NS_URI, tSmurf);
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 + ".address." + tSmurfAddress + ".line1");
assertThat(input.get(1).getInputExpression().getTypeRef()).isEqualTo(stringBuiltInType);
assertThat(input.get(2).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(2).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + ".address." + tSmurfAddress + ".line2");
assertThat(input.get(2).getInputExpression().getTypeRef()).isEqualTo(stringBuiltInType);
assertThat(input.get(3).getInputExpression()).isInstanceOf(InputClauseLiteralExpression.class);
assertThat(input.get(3).getInputExpression().getText().getValue()).isEqualTo(INPUT_DATA_NAME_1 + ".dob");
assertThat(input.get(3).getInputExpression().getTypeRef()).isEqualTo(dateBuiltInType);
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 testModelEnrichmentWhenParentIsNestedContextEntryDefaultResult.
@Test
public void testModelEnrichmentWhenParentIsNestedContextEntryDefaultResult() {
final Decision decision = mock(Decision.class);
final String name = "context-entry";
final Context innerContext = new Context();
final ContextEntry innerContextEntry = new ContextEntry();
innerContext.getContextEntry().add(innerContextEntry);
innerContextEntry.setParent(innerContext);
final Context outerContext = new Context();
final ContextEntry outerContextEntry = new ContextEntry();
outerContext.getContextEntry().add(outerContextEntry);
outerContextEntry.setParent(outerContext);
innerContext.setParent(outerContextEntry);
outerContext.setParent(decision);
outerContextEntry.setVariable(new InformationItem(new Id(), new Description(), new Name(name), OUTPUT_DATA_QNAME));
when(decision.asDMNModelInstrumentedBase()).thenReturn(outerContextEntry);
final Optional<DecisionTable> oModel = definition.getModelClass();
oModel.get().setParent(innerContextEntry);
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(OUTPUT_DATA_QNAME);
assertStandardDecisionRuleEnrichment(model);
assertParentHierarchyEnrichment(model);
}
Aggregations