Search in sources :

Example 11 with DecisionRule

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

the class MoveColumnsCommandTest method setUp.

@Before
public void setUp() {
    this.dtable = new DecisionTable();
    this.uiModel = new DMNGridData();
    dtable.getInput().add(inputClauseOne);
    dtable.getInput().add(inputClauseTwo);
    dtable.getInput().add(inputClauseThree);
    dtable.getOutput().add(outputClauseOne);
    dtable.getOutput().add(outputClauseTwo);
    dtable.getOutput().add(outputClauseThree);
    dtable.getAnnotations().add(annotationClauseOne);
    dtable.getAnnotations().add(annotationClauseTwo);
    dtable.getAnnotations().add(annotationClauseThree);
    dtable.getRule().add(new DecisionRule() {

        {
            getInputEntry().add(new UnaryTests());
            getInputEntry().add(new UnaryTests());
            getInputEntry().add(new UnaryTests());
            getOutputEntry().add(new LiteralExpression());
            getOutputEntry().add(new LiteralExpression());
            getOutputEntry().add(new LiteralExpression());
            getAnnotationEntry().add(new RuleAnnotationClauseText());
            getAnnotationEntry().add(new RuleAnnotationClauseText());
            getAnnotationEntry().add(new RuleAnnotationClauseText());
        }
    });
    uiModel.appendColumn(uiRowNumberColumn);
    uiModel.appendColumn(uiInputClauseColumnOne);
    uiModel.appendColumn(uiInputClauseColumnTwo);
    uiModel.appendColumn(uiInputClauseColumnThree);
    uiModel.appendColumn(uiOutputClauseColumnOne);
    uiModel.appendColumn(uiOutputClauseColumnTwo);
    uiModel.appendColumn(uiOutputClauseColumnThree);
    uiModel.appendColumn(uiRuleAnnotationClauseColumnOne);
    uiModel.appendColumn(uiRuleAnnotationClauseColumnTwo);
    uiModel.appendColumn(uiRuleAnnotationClauseColumnThree);
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiInputClauseColumnOne).getIndex();
    doReturn(2).when(uiInputClauseColumnTwo).getIndex();
    doReturn(3).when(uiInputClauseColumnThree).getIndex();
    doReturn(4).when(uiOutputClauseColumnOne).getIndex();
    doReturn(5).when(uiOutputClauseColumnTwo).getIndex();
    doReturn(6).when(uiOutputClauseColumnThree).getIndex();
    doReturn(7).when(uiRuleAnnotationClauseColumnOne).getIndex();
    doReturn(8).when(uiRuleAnnotationClauseColumnTwo).getIndex();
    doReturn(9).when(uiRuleAnnotationClauseColumnThree).getIndex();
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Before(org.junit.Before)

Example 12 with DecisionRule

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

the class DeleteRuleAnnotationClauseCommandTest method testNewCanvasCommandUndo.

@Test
public void testNewCanvasCommandUndo() {
    final DeleteRuleAnnotationClauseCommand command = mock(DeleteRuleAnnotationClauseCommand.class);
    final AbstractCanvasHandler handler = mock(AbstractCanvasHandler.class);
    final GridData uiModel = mock(GridData.class);
    final GridColumn oldUiModelColumn = mock(GridColumn.class);
    final int uiColumnIndex = 3;
    final DecisionRule rule1 = mock(DecisionRule.class);
    final DecisionRule rule2 = mock(DecisionRule.class);
    final List<DecisionRule> rules = Arrays.asList(rule1, rule2);
    final org.uberfire.mvp.Command undoCanvasOperation = mock(org.uberfire.mvp.Command.class);
    final DecisionTableUIModelMapper uiModelMapper = mock(DecisionTableUIModelMapper.class);
    doCallRealMethod().when(command).newCanvasCommand(handler);
    when(command.getUiModel()).thenReturn(uiModel);
    when(command.getUiColumnIndex()).thenReturn(uiColumnIndex);
    when(command.getOldUiModelColumn()).thenReturn(oldUiModelColumn);
    when(command.getDecisionTable()).thenReturn(decisionTable);
    when(decisionTable.getRule()).thenReturn(rules);
    when(command.getUiModelMapper()).thenReturn(uiModelMapper);
    when(command.getUndoCanvasOperation()).thenReturn(undoCanvasOperation);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasCommand = command.newCanvasCommand(handler);
    final CommandResult<CanvasViolation> result = canvasCommand.undo(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, result);
    verify(uiModelMapper).fromDMNModel(0, uiColumnIndex);
    verify(uiModelMapper).fromDMNModel(1, uiColumnIndex);
    verify(command).updateParentInformation();
    verify(undoCanvasOperation).execute();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) DecisionTableUIModelMapper(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapper) Test(org.junit.Test)

Example 13 with DecisionRule

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

the class AddInputClauseCommandTest method testGraphCommandUndoNoInputClauseColumns.

@Test(expected = IndexOutOfBoundsException.class)
public void testGraphCommandUndoNoInputClauseColumns() {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    dtable.getRule().add(new DecisionRule());
    assertEquals(0, dtable.getInput().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 14 with DecisionRule

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

the class AddRuleAnnotationClauseCommandTest method testNewGraphCommandUndo.

@Test
public void testNewGraphCommandUndo() {
    final AbstractCanvasHandler context = mock(AbstractCanvasHandler.class);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(context);
    final GraphCommandExecutionContext executionContext = mock(GraphCommandExecutionContext.class);
    final int ruleAnnotationIndex = 3;
    final DecisionRule rule1 = mock(DecisionRule.class);
    final DecisionRule rule2 = mock(DecisionRule.class);
    final List rule1AnnotationEntries = mock(List.class);
    final List rule2AnnotationEntries = mock(List.class);
    final List<DecisionRule> rules = Arrays.asList(rule1, rule2);
    when(rule1.getAnnotationEntry()).thenReturn(rule1AnnotationEntries);
    when(rule2.getAnnotationEntry()).thenReturn(rule2AnnotationEntries);
    when(decisionTable.getRule()).thenReturn(rules);
    when(annotations.indexOf(ruleAnnotationClause)).thenReturn(ruleAnnotationIndex);
    final CommandResult<RuleViolation> undoResult = graphCommand.undo(executionContext);
    verify(componentsWidths).remove(uiColumnIndex);
    verify(rule1AnnotationEntries).remove(ruleAnnotationIndex);
    verify(rule2AnnotationEntries).remove(ruleAnnotationIndex);
    verify(annotations).remove(ruleAnnotationClause);
    assertEquals(GraphCommandResultBuilder.SUCCESS, undoResult);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) List(java.util.List) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 15 with DecisionRule

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

the class DeleteInputClauseCommandTest method testGraphCommandExecuteRemoveMiddle.

@Test
public void testGraphCommandExecuteRemoveMiddle() {
    final InputClause firstInput = mock(InputClause.class);
    final InputClause lastInput = mock(InputClause.class);
    dtable.getInput().add(0, firstInput);
    dtable.getInput().add(lastInput);
    final UnaryTests inputOneValue = mock(UnaryTests.class);
    final UnaryTests inputTwoValue = mock(UnaryTests.class);
    final UnaryTests inputThreeValue = mock(UnaryTests.class);
    final DecisionRule rule = new DecisionRule();
    rule.getInputEntry().add(inputOneValue);
    rule.getInputEntry().add(inputTwoValue);
    rule.getInputEntry().add(inputThreeValue);
    dtable.getRule().add(rule);
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + 1);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(2, dtable.getInput().size());
    assertEquals(firstInput, dtable.getInput().get(0));
    assertEquals(lastInput, dtable.getInput().get(1));
    assertEquals(2, dtable.getRule().get(0).getInputEntry().size());
    assertEquals(inputOneValue, dtable.getRule().get(0).getInputEntry().get(0));
    assertEquals(inputThreeValue, dtable.getRule().get(0).getInputEntry().get(1));
}
Also used : 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)

Aggregations

DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)51 Test (org.junit.Test)28 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)19 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)19 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)17 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)16 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)16 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)14 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)14 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)13 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)12 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)12 List (java.util.List)9 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)9 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)7 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)7 Before (org.junit.Before)5 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)5 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)5 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)5