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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations