Search in sources :

Example 61 with GraphCommandExecutionContext

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

the class AddDecisionRuleCommandTest method testCanvasCommandExecuteInsertBelow.

@Test
public void testCanvasCommandExecuteInsertBelow() {
    // The default behaviour of tests in this class is to "insert above"
    final DecisionRule existingRule = new DecisionRule();
    final GridRow existingUiRow = new BaseGridRow();
    dtable.getRule().add(existingRule);
    uiModel.appendRow(existingUiRow);
    dtable.getInput().add(new InputClause());
    dtable.getOutput().add(new OutputClause());
    dtable.getAnnotations().add(new RuleAnnotationClause());
    makeCommand(1);
    uiModel.appendColumn(uiInputClauseColumn);
    uiModel.appendColumn(uiOutputClauseColumn);
    uiModel.appendColumn(uiRuleAnnotationClauseColumn);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasCommand = command.newCanvasCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    canvasCommand.execute(canvasHandler);
    assertEquals(2, uiModel.getRowCount());
    assertEquals(existingUiRow, uiModel.getRow(0));
    assertEquals(uiModelRow, uiModel.getRow(1));
    assertDefaultUiRowValues(1);
    verify(command).updateRowNumbers();
    verify(command).updateParentInformation();
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) 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) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 62 with GraphCommandExecutionContext

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

the class AddDecisionRuleCommandTest method testGraphCommandExecuteConstructedRuleInputs.

@Test
public void testGraphCommandExecuteConstructedRuleInputs() {
    assertEquals(0, dtable.getRule().size());
    final int inputsCount = 2;
    for (int i = 0; i < inputsCount; i++) {
        dtable.getInput().add(new InputClause());
    }
    makeCommand(0);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(1, dtable.getRule().size());
    assertEquals(rule, dtable.getRule().get(0));
    assertEquals(inputsCount, rule.getInputEntry().size());
    assertEquals(0, rule.getOutputEntry().size());
    for (int inputIndex = 0; inputIndex < inputsCount; inputIndex++) {
        assertTrue(rule.getInputEntry().get(inputIndex).getText() != null);
        assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, rule.getInputEntry().get(inputIndex).getText().getValue());
        assertEquals(rule, rule.getInputEntry().get(inputIndex).getParent());
    }
    assertEquals(dtable, rule.getParent());
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 63 with GraphCommandExecutionContext

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

the class AddDecisionRuleCommandTest method testCanvasCommandExecuteInsertBelowThenUndo.

@Test
public void testCanvasCommandExecuteInsertBelowThenUndo() {
    // The default behaviour of tests in this class is to "insert above"
    final DecisionRule existingRule = new DecisionRule();
    final GridRow existingUiRow = new BaseGridRow();
    dtable.getRule().add(existingRule);
    uiModel.appendRow(existingUiRow);
    makeCommand(1);
    uiModel.appendColumn(uiInputClauseColumn);
    uiModel.appendColumn(uiOutputClauseColumn);
    uiModel.appendColumn(uiRuleAnnotationClauseColumn);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasCommand = command.newCanvasCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    canvasCommand.execute(canvasHandler);
    canvasCommand.undo(canvasHandler);
    assertEquals(1, uiModel.getRowCount());
    assertEquals(existingUiRow, uiModel.getRow(0));
    // one time in execute(), one time in undo()
    verify(canvasOperation, times(2)).execute();
    verify(command, times(2)).updateRowNumbers();
    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) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 64 with GraphCommandExecutionContext

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

the class AddDecisionRuleCommandTest method testCanvasCommandAddRuleAndThenUndo.

@Test
public void testCanvasCommandAddRuleAndThenUndo() throws Exception {
    dtable.getInput().add(new InputClause());
    dtable.getOutput().add(new OutputClause());
    dtable.getAnnotations().add(new RuleAnnotationClause());
    makeCommand(0);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    uiModel.appendColumn(uiInputClauseColumn);
    uiModel.appendColumn(uiOutputClauseColumn);
    uiModel.appendColumn(uiRuleAnnotationClauseColumn);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasAddRuleCommand = command.newCanvasCommand(canvasHandler);
    canvasAddRuleCommand.execute(canvasHandler);
    assertEquals(1, uiModel.getRowCount());
    assertDefaultUiRowValues(0);
    canvasAddRuleCommand.undo(canvasHandler);
    assertEquals(0, uiModel.getRowCount());
    // one time in execute(), one time in undo()
    verify(canvasOperation, times(2)).execute();
    verify(command, times(2)).updateRowNumbers();
    verify(command, times(2)).updateParentInformation();
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) 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) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 65 with GraphCommandExecutionContext

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

the class AddDecisionRuleCommandTest method testGraphCommandExecuteConstructedRuleOutputs.

@Test
public void testGraphCommandExecuteConstructedRuleOutputs() {
    assertEquals(0, dtable.getRule().size());
    final int outputsCount = 2;
    for (int i = 0; i < outputsCount; i++) {
        dtable.getOutput().add(new OutputClause());
    }
    makeCommand(0);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(1, dtable.getRule().size());
    assertEquals(rule, dtable.getRule().get(0));
    assertEquals(0, rule.getInputEntry().size());
    assertEquals(outputsCount, rule.getOutputEntry().size());
    for (int outputIndex = 0; outputIndex < outputsCount; outputIndex++) {
        assertTrue(rule.getOutputEntry().get(outputIndex).getText() != null);
        assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, rule.getOutputEntry().get(outputIndex).getText().getValue());
        assertEquals(rule, rule.getOutputEntry().get(outputIndex).getParent());
    }
    assertEquals(dtable, rule.getParent());
}
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)

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