Search in sources :

Example 26 with InputClause

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

the class AddOutputClauseCommandTest method testCanvasCommandAddOutputClauseToRuleWithInputs.

@Test
public void testCanvasCommandAddOutputClauseToRuleWithInputs() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + 1);
    final String ruleInputValue = "in value";
    final String ruleOutputValue = "out value";
    dtable.getInput().add(new InputClause());
    dtable.getRule().add(new DecisionRule() {

        {
            getInputEntry().add(new UnaryTests() {

                {
                    getText().setValue(ruleInputValue);
                }
            });
            getOutputEntry().add(new LiteralExpression() {

                {
                    getText().setValue(ruleOutputValue);
                }
            });
        }
    });
    // Graph command populates OutputEntries so overwrite with test values
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    dtable.getRule().get(0).getOutputEntry().get(0).getText().setValue(ruleOutputValue);
    doReturn(1).when(uiInputClauseColumn).getIndex();
    doReturn(2).when(uiOutputClauseColumn).getIndex();
    uiModel.appendColumn(uiInputClauseColumn);
    uiModel.appendRow(new BaseGridRow());
    uiModelMapper.fromDMNModel(0, 1);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasAddOutputClauseCommand = command.newCanvasCommand(canvasHandler);
    canvasAddOutputClauseCommand.execute(canvasHandler);
    assertEquals(ruleInputValue, uiModel.getRow(0).getCells().get(1).getValue().getValue());
    assertEquals(ruleOutputValue, uiModel.getRow(0).getCells().get(2).getValue().getValue());
    assertEquals(3, uiModel.getColumnCount());
    assertEquals(CanvasCommandResultBuilder.SUCCESS, canvasAddOutputClauseCommand.undo(canvasHandler));
    assertEquals(2, uiModel.getColumnCount());
    verify(executeCanvasOperation).execute();
    verify(undoCanvasOperation).execute();
    verify(command, times(2)).updateParentInformation();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 27 with InputClause

use of org.kie.workbench.common.dmn.api.definition.model.InputClause 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);
}
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 28 with InputClause

use of org.kie.workbench.common.dmn.api.definition.model.InputClause 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);
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 29 with InputClause

use of org.kie.workbench.common.dmn.api.definition.model.InputClause 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);
}
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 30 with InputClause

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

the class DecisionTableUIModelMapperTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    this.uiModel = new BaseGridData();
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiInputClauseColumn);
    this.uiModel.appendColumn(uiOutputClauseColumn);
    this.uiModel.appendColumn(uiAnnotationClauseColumn);
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiInputClauseColumn).getIndex();
    doReturn(2).when(uiOutputClauseColumn).getIndex();
    doReturn(3).when(uiAnnotationClauseColumn).getIndex();
    this.dtable = new DecisionTable();
    this.dtable.getInput().add(new InputClause());
    this.dtable.getOutput().add(new OutputClause());
    this.dtable.getAnnotations().add(new RuleAnnotationClause());
    this.dtable.getRule().add(new DecisionRule() {

        {
            getInputEntry().add(new UnaryTests() {

                {
                    getText().setValue("i1");
                }
            });
            getOutputEntry().add(new LiteralExpression() {

                {
                    getText().setValue("o1");
                }
            });
            getAnnotationEntry().add(new RuleAnnotationClauseText() {

                {
                    getText().setValue("a1");
                }
            });
        }
    });
    this.dtable.getRule().add(new DecisionRule() {

        {
            getInputEntry().add(new UnaryTests() {

                {
                    getText().setValue("i2");
                }
            });
            getOutputEntry().add(new LiteralExpression() {

                {
                    getText().setValue("o2");
                }
            });
            getAnnotationEntry().add(new RuleAnnotationClauseText() {

                {
                    getText().setValue("a2");
                }
            });
        }
    });
    this.mapper = new DecisionTableUIModelMapper(() -> uiModel, () -> Optional.of(dtable), listSelector, DEFAULT_HEIGHT);
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Before(org.junit.Before)

Aggregations

InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)33 Test (org.junit.Test)18 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)14 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)11 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)10 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)10 InputClauseLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression)8 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)8 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)8 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)8 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)7 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)5 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 Before (org.junit.Before)4 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)4 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)4 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)3 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)3 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)3