Search in sources :

Example 81 with GraphCommandExecutionContext

use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext in project kie-wb-common by kiegroup.

the class AddOutputClauseCommandTest method testGraphCommandUndoNoOutputClauseColumns.

@Test(expected = IndexOutOfBoundsException.class)
public void testGraphCommandUndoNoOutputClauseColumns() {
    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.model.DecisionRule) Test(org.junit.Test)

Example 82 with GraphCommandExecutionContext

use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext 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 83 with GraphCommandExecutionContext

use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext in project kie-wb-common by kiegroup.

the class AddOutputClauseCommandTest method testGraphCommandUndoJustLastOutputClauseColumn.

@Test
public void testGraphCommandUndoJustLastOutputClauseColumn() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    final String ruleOneOldOutput = "old rule 1";
    final String ruleTwoOldOutput = "old rule 2";
    dtable.getOutput().add(new OutputClause());
    addRuleWithOutputClauseValues(ruleOneOldOutput);
    addRuleWithOutputClauseValues(ruleTwoOldOutput);
    assertEquals(1, dtable.getOutput().size());
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.undo(graphCommandExecutionContext));
    assertEquals(1, dtable.getOutput().size());
    // first rule
    assertEquals(1, dtable.getRule().get(0).getOutputEntry().size());
    assertEquals(ruleOneOldOutput, dtable.getRule().get(0).getOutputEntry().get(0).getText().getValue());
    // second rule
    assertEquals(1, dtable.getRule().get(1).getOutputEntry().size());
    assertEquals(ruleTwoOldOutput, dtable.getRule().get(1).getOutputEntry().get(0).getText().getValue());
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 84 with GraphCommandExecutionContext

use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext 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).getText().setValue(ruleOneOutputValue);
    dtable.getRule().get(1).getOutputEntry().get(0).getText().setValue(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());
    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) 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.model.DecisionRule) Test(org.junit.Test)

Example 85 with GraphCommandExecutionContext

use of org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext in project kie-wb-common by kiegroup.

the class AddOutputClauseCommandTest method testGraphCommandExecuteInsertMiddle.

@Test
public void testGraphCommandExecuteInsertMiddle() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + 1);
    final String ruleOutputOne = "rule out 1";
    final String ruleOutputTwo = "rule out 2";
    dtable.getOutput().add(new OutputClause());
    dtable.getOutput().add(new OutputClause());
    addRuleWithOutputClauseValues(ruleOutputOne, ruleOutputTwo);
    assertEquals(2, dtable.getOutput().size());
    // Graph command will insert new OutputClause at index 1 of the OutputEntries
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(3, dtable.getOutput().size());
    assertNull(dtable.getOutput().get(0).getName());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1", dtable.getOutput().get(1).getName());
    assertNull(dtable.getOutput().get(2).getName());
    final List<LiteralExpression> ruleOutputs = dtable.getRule().get(0).getOutputEntry();
    // first rule
    assertEquals(3, ruleOutputs.size());
    assertEquals(ruleOutputOne, ruleOutputs.get(0).getText().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, ruleOutputs.get(1).getText().getValue());
    assertEquals(dtable.getRule().get(0), ruleOutputs.get(1).getParent());
    assertEquals(ruleOutputTwo, ruleOutputs.get(2).getText().getValue());
    assertEquals(dtable, outputClause.getParent());
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) 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) Test(org.junit.Test)

Aggregations

GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)85 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)84 Test (org.junit.Test)66 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)25 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)20 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)19 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)14 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)11 List (org.kie.workbench.common.dmn.api.definition.model.List)10 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)8 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)8 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)8 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)8 Binding (org.kie.workbench.common.dmn.api.definition.model.Binding)7 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)7 List (java.util.List)6 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)6 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)5 Command (org.kie.workbench.common.stunner.core.command.Command)5 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)4