Search in sources :

Example 31 with DecisionRule

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

the class AddInputClauseCommandTest method testCanvasCommandAddRuleAndThenUndo.

@Test
public void testCanvasCommandAddRuleAndThenUndo() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    final String ruleOneInputValue = "one";
    final String ruleTwoInputValue = "two";
    dtable.getRule().add(new DecisionRule());
    dtable.getRule().add(new DecisionRule());
    uiModel.appendRow(new BaseGridRow());
    uiModel.appendRow(new BaseGridRow());
    // Graph command populates InputEntries so overwrite with test values
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    dtable.getRule().get(0).getInputEntry().get(0).getText().setValue(ruleOneInputValue);
    dtable.getRule().get(1).getInputEntry().get(0).getText().setValue(ruleTwoInputValue);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasAddInputClauseCommand = command.newCanvasCommand(canvasHandler);
    canvasAddInputClauseCommand.execute(canvasHandler);
    // first rule
    assertEquals(ruleOneInputValue, uiModel.getRow(0).getCells().get(1).getValue().getValue());
    // second rule
    assertEquals(ruleTwoInputValue, uiModel.getRow(1).getCells().get(1).getValue().getValue());
    assertEquals(2, uiModel.getColumnCount());
    assertEquals(CanvasCommandResultBuilder.SUCCESS, canvasAddInputClauseCommand.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 32 with DecisionRule

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

the class AddRuleAnnotationClauseCommandTest method testNewGraphCommandExecute.

@Test
public void testNewGraphCommandExecute() {
    final AbstractCanvasHandler context = mock(AbstractCanvasHandler.class);
    final GraphCommandExecutionContext executionContext = mock(GraphCommandExecutionContext.class);
    final DecisionRule rule1 = mock(DecisionRule.class);
    final DecisionRule rule2 = mock(DecisionRule.class);
    final List<DecisionRule> rules = Arrays.asList(rule1, rule2);
    final int clauseIndex = 2;
    final Name ruleAnnotationClauseName = mock(Name.class);
    final List rule1AnnotationEntries = mock(List.class);
    final List rule2AnnotationEntries = mock(List.class);
    doReturn(clauseIndex).when(command).getClauseIndex();
    when(rule1.getAnnotationEntry()).thenReturn(rule1AnnotationEntries);
    when(rule2.getAnnotationEntry()).thenReturn(rule2AnnotationEntries);
    when(ruleAnnotationClause.getName()).thenReturn(ruleAnnotationClauseName);
    when(decisionTable.getRule()).thenReturn(rules);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(context);
    final CommandResult<RuleViolation> commandResult = graphCommand.execute(executionContext);
    verify(rule1AnnotationEntries).add(eq(clauseIndex), clauseTextCaptor.capture());
    verify(rule2AnnotationEntries).add(eq(clauseIndex), clauseTextCaptor.capture());
    verify(componentsWidths).add(uiColumnIndex, null);
    verify(annotations).add(clauseIndex, ruleAnnotationClause);
    verify(ruleAnnotationClause).setParent(decisionTable);
    final List<RuleAnnotationClauseText> capturedValues = clauseTextCaptor.getAllValues();
    assertEquals(2, capturedValues.size());
    assertEquals(DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_EXPRESSION_TEXT, capturedValues.get(0).getText().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_EXPRESSION_TEXT, capturedValues.get(1).getText().getValue());
    assertEquals(rule1, capturedValues.get(0).getParent());
    assertEquals(rule2, capturedValues.get(1).getParent());
    assertEquals(GraphCommandResultBuilder.SUCCESS, commandResult);
}
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) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 33 with DecisionRule

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

the class AddRuleAnnotationClauseCommandTest method testNewCanvasCommandExecute.

@Test
public void testNewCanvasCommandExecute() {
    final AbstractCanvasHandler canvasHandler = mock(AbstractCanvasHandler.class);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasCommand = command.newCanvasCommand(canvasHandler);
    final RuleAnnotationClauseColumn column = mock(RuleAnnotationClauseColumn.class);
    final List<DecisionRule> rules = mock(List.class);
    when(rules.size()).thenReturn(3);
    when(decisionTable.getRule()).thenReturn(rules);
    when(uiModelColumnSupplier.get()).thenReturn(column);
    final CommandResult<CanvasViolation> result = canvasCommand.execute(canvasHandler);
    verify(uiModelMapper).fromDMNModel(0, uiColumnIndex);
    verify(uiModelMapper).fromDMNModel(1, uiColumnIndex);
    verify(uiModelMapper).fromDMNModel(2, uiColumnIndex);
    verify(command).updateParentInformation();
    verify(executeCanvasOperation).execute();
    verify(uiModelColumnSupplier).get();
    verify(uiModel).insertColumn(uiColumnIndex, column);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, result);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) RuleAnnotationClauseColumn(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.RuleAnnotationClauseColumn) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 34 with DecisionRule

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

the class DeleteRuleAnnotationClauseCommandTest method testNewGraphCommandExecute.

@Test
public void testNewGraphCommandExecute() {
    final int uiColumnIndex = 3;
    final int annotationClauseIndex = 2;
    final AbstractCanvasHandler handler = mock(AbstractCanvasHandler.class);
    final DeleteRuleAnnotationClauseCommand command = mock(DeleteRuleAnnotationClauseCommand.class);
    final DecisionRule rule1 = mock(DecisionRule.class);
    final DecisionRule rule2 = mock(DecisionRule.class);
    final List<DecisionRule> rules = Arrays.asList(rule1, rule2);
    final List rule1AnnotationEntries = mock(List.class);
    final List rule2AnnotationEntries = mock(List.class);
    final List annotations = mock(List.class);
    final List widths = mock(List.class);
    final GraphCommandExecutionContext context = mock(GraphCommandExecutionContext.class);
    doCallRealMethod().when(command).newGraphCommand(handler);
    when(command.getDecisionTable()).thenReturn(decisionTable);
    when(command.getRuleAnnotationClauseIndex()).thenReturn(annotationClauseIndex);
    when(command.getUiColumnIndex()).thenReturn(uiColumnIndex);
    when(rule1.getAnnotationEntry()).thenReturn(rule1AnnotationEntries);
    when(rule2.getAnnotationEntry()).thenReturn(rule2AnnotationEntries);
    when(decisionTable.getRule()).thenReturn(rules);
    when(decisionTable.getAnnotations()).thenReturn(annotations);
    when(decisionTable.getComponentWidths()).thenReturn(widths);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(handler);
    final CommandResult<RuleViolation> result = graphCommand.execute(context);
    assertEquals(GraphCommandResultBuilder.SUCCESS, result);
    verify(widths).remove(uiColumnIndex);
    verify(rule1AnnotationEntries).remove(annotationClauseIndex);
    verify(rule2AnnotationEntries).remove(annotationClauseIndex);
    verify(annotations).remove(annotationClauseIndex);
}
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 35 with DecisionRule

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

the class DeleteRuleAnnotationClauseCommandTest method testNewGraphCommandUndo.

@Test
public void testNewGraphCommandUndo() {
    final int uiColumnIndex = 3;
    final int annotationClauseIndex = 2;
    final AbstractCanvasHandler handler = mock(AbstractCanvasHandler.class);
    final DeleteRuleAnnotationClauseCommand command = mock(DeleteRuleAnnotationClauseCommand.class);
    final DecisionRule rule1 = mock(DecisionRule.class);
    final DecisionRule rule2 = mock(DecisionRule.class);
    final List<DecisionRule> rules = Arrays.asList(rule1, rule2);
    final List rule1AnnotationEntries = mock(List.class);
    final List rule2AnnotationEntries = mock(List.class);
    final List annotations = mock(List.class);
    final List widths = mock(List.class);
    final GraphCommandExecutionContext context = mock(GraphCommandExecutionContext.class);
    final RuleAnnotationClause oldRuleClause = mock(RuleAnnotationClause.class);
    final GridColumn oldUiModelColumn = mock(GridColumn.class);
    final double oldUiModelColumnWidth = 123.4D;
    final RuleAnnotationClauseText deleted1 = mock(RuleAnnotationClauseText.class);
    final RuleAnnotationClauseText deleted2 = mock(RuleAnnotationClauseText.class);
    final List<RuleAnnotationClauseText> oldCommandData = Arrays.asList(deleted1, deleted2);
    doCallRealMethod().when(command).newGraphCommand(handler);
    when(command.getOldColumnData()).thenReturn(oldCommandData);
    when(command.getOldRuleClause()).thenReturn(oldRuleClause);
    when(oldUiModelColumn.getWidth()).thenReturn(oldUiModelColumnWidth);
    when(command.getOldUiModelColumn()).thenReturn(oldUiModelColumn);
    when(command.getDecisionTable()).thenReturn(decisionTable);
    when(command.getRuleAnnotationClauseIndex()).thenReturn(annotationClauseIndex);
    when(command.getUiColumnIndex()).thenReturn(uiColumnIndex);
    when(rule1.getAnnotationEntry()).thenReturn(rule1AnnotationEntries);
    when(rule2.getAnnotationEntry()).thenReturn(rule2AnnotationEntries);
    when(decisionTable.getRule()).thenReturn(rules);
    when(decisionTable.getAnnotations()).thenReturn(annotations);
    when(decisionTable.getComponentWidths()).thenReturn(widths);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(handler);
    final CommandResult<RuleViolation> result = graphCommand.undo(context);
    assertEquals(GraphCommandResultBuilder.SUCCESS, result);
    verify(annotations).add(annotationClauseIndex, oldRuleClause);
    verify(rule1AnnotationEntries).add(annotationClauseIndex, deleted1);
    verify(rule2AnnotationEntries).add(annotationClauseIndex, deleted2);
}
Also used : RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) List(java.util.List) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) 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