Search in sources :

Example 21 with DecisionRule

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

the class AddOutputClauseCommandTest method testCanvasCommandAddOutputClauseToRuleWithoutInputsThenUndo.

@Test
public void testCanvasCommandAddOutputClauseToRuleWithoutInputsThenUndo() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    final String ruleOneOutputValue = "one";
    final String ruleTwoOutputValue = "two";
    dtable.getRule().add(new DecisionRule());
    dtable.getRule().add(new DecisionRule());
    uiModel.appendRow(new BaseGridRow());
    uiModel.appendRow(new BaseGridRow());
    // 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).setText(ruleOneOutputValue);
    dtable.getRule().get(1).getOutputEntry().get(0).setText(ruleTwoOutputValue);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasAddOutputClauseCommand = command.newCanvasCommand(canvasHandler);
    canvasAddOutputClauseCommand.execute(canvasHandler);
    // first rule
    assertEquals(ruleOneOutputValue, uiModel.getRow(0).getCells().get(1).getValue().getValue());
    // second rule
    assertEquals(ruleTwoOutputValue, uiModel.getRow(1).getCells().get(1).getValue().getValue());
    assertEquals(2, uiModel.getColumnCount());
    assertEquals(CanvasCommandResultBuilder.SUCCESS, canvasAddOutputClauseCommand.undo(canvasHandler));
    assertEquals(1, uiModel.getColumnCount());
    // one time in execute(), one time in undo()
    verify(canvasOperation, times(2)).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) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule) Test(org.junit.Test)

Example 22 with DecisionRule

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

the class AddOutputClauseCommandTest method testGraphCommandUndoNoOutputClauseColumns.

@Test(expected = ArrayIndexOutOfBoundsException.class)
public void testGraphCommandUndoNoOutputClauseColumns() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    dtable.getRule().add(new DecisionRule());
    assertEquals(0, dtable.getOutput().size());
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.undo(graphCommandExecutionContext));
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule) Test(org.junit.Test)

Example 23 with DecisionRule

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

the class MoveRowsCommandTest method appendRow.

private void appendRow(final int rowIndex, final String rowIdentifier) {
    final String inValue = "in " + rowIdentifier;
    final String outValue = "out " + rowIdentifier;
    dtable.getRule().add(new DecisionRule() {

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

                {
                    setText(inValue);
                }
            });
            getOutputEntry().add(new LiteralExpression() {

                {
                    setText(outValue);
                }
            });
        }
    });
    final DMNGridRow uiRow = new DMNGridRow();
    uiModel.appendRow(uiRow);
    uiModel.setCellValue(rowIndex, 0, new BaseGridCellValue<>(rowIndex + 1));
    uiModel.setCellValue(rowIndex, 1, new BaseGridCellValue<>(inValue));
    uiModel.setCellValue(rowIndex, 2, new BaseGridCellValue<>(outValue));
    rowsUnderTest.add(uiRow);
}
Also used : DMNGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) UnaryTests(org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)

Example 24 with DecisionRule

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

the class CommandUtilsTest method setUp.

@Before
public void setUp() throws Exception {
    decisionRuleOne = new DecisionRule();
    decisionRuleTwo = new DecisionRule();
    decisionRuleThree = new DecisionRule();
    decisionRuleOne.setId(new Id("1"));
    decisionRuleTwo.setId(new Id("2"));
    decisionRuleThree.setId(new Id("3"));
    allRows.clear();
    allRows.add(decisionRuleOne);
    allRows.add(decisionRuleTwo);
    allRows.add(decisionRuleThree);
    rowsToMove.clear();
    uiModel = new DMNGridData();
    gridWidget = new BaseGridWidget(uiModel, selectionManager, pinnedModeManager, renderer);
}
Also used : BaseGridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.impl.BaseGridWidget) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule) Before(org.junit.Before)

Example 25 with DecisionRule

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

the class DecisionRulePropertyConverter method wbFromDMN.

public static DecisionRule wbFromDMN(final org.kie.dmn.model.v1_1.DecisionRule dmn) {
    Id id = new Id(dmn.getId());
    Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    DecisionRule result = new DecisionRule();
    result.setId(id);
    result.setDescription(description);
    for (org.kie.dmn.model.v1_1.UnaryTests ie : dmn.getInputEntry()) {
        result.getInputEntry().add(UnaryTestsPropertyConverter.wbFromDMN(ie));
    }
    for (org.kie.dmn.model.v1_1.LiteralExpression oe : dmn.getOutputEntry()) {
        result.getOutputEntry().add(LiteralExpressionPropertyConverter.wbFromDMN(oe));
    }
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)

Aggregations

DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)25 Test (org.junit.Test)12 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)12 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)12 DecisionTable (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionTable)9 InputClause (org.kie.workbench.common.dmn.api.definition.v1_1.InputClause)6 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)6 UnaryTests (org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests)6 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)6 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)6 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)6 Before (org.junit.Before)5 OutputClause (org.kie.workbench.common.dmn.api.definition.v1_1.OutputClause)5 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)5 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)3 DecisionTableSection (org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection)3 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2