use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.
the class MoveRowsCommandTest method appendRow.
private void appendRow(final int rowIndex, final String rowIdentifier) {
final String inValue = "in " + rowIdentifier;
final String outValue = "out " + rowIdentifier;
dtable.getRule().add(new DecisionRule() {
{
getInputEntry().add(new UnaryTests() {
{
getText().setValue(inValue);
}
});
getOutputEntry().add(new LiteralExpression() {
{
getText().setValue(outValue);
}
});
}
});
final GridRow uiRow = new BaseGridRow();
uiModel.appendRow(uiRow);
uiModel.setCellValue(rowIndex, 0, new BaseGridCellValue<>(rowIndex + 1));
uiModel.setCellValue(rowIndex, 1, new BaseGridCellValue<>(inValue));
uiModel.setCellValue(rowIndex, 2, new BaseGridCellValue<>(outValue));
rowsUnderTest.add(uiRow);
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.
the class MoveColumnsCommandTest method testMoveSingleAnnotationColumnWithDuplicatedTitle.
@Test
public void testMoveSingleAnnotationColumnWithDuplicatedTitle() {
final DecisionTable decisionTable = new DecisionTable();
final DMNGridData model = new DMNGridData();
final RuleAnnotationClause clauseOne = new RuleAnnotationClause();
final RuleAnnotationClause clauseTwo = new RuleAnnotationClause();
final RuleAnnotationClause clauseThree = new RuleAnnotationClause();
decisionTable.getAnnotations().add(clauseOne);
decisionTable.getAnnotations().add(clauseTwo);
decisionTable.getAnnotations().add(clauseThree);
decisionTable.getRule().add(new DecisionRule() {
{
getAnnotationEntry().add(new RuleAnnotationClauseText());
getAnnotationEntry().add(new RuleAnnotationClauseText());
getAnnotationEntry().add(new RuleAnnotationClauseText());
}
});
final RuleAnnotationClauseColumn columnOne = mock(RuleAnnotationClauseColumn.class);
final RuleAnnotationClauseColumn columnTwo = mock(RuleAnnotationClauseColumn.class);
final RuleAnnotationClauseColumn columnThree = mock(RuleAnnotationClauseColumn.class);
model.appendColumn(uiRowNumberColumn);
model.appendColumn(columnOne);
model.appendColumn(columnTwo);
model.appendColumn(columnThree);
when(columnOne.getIndex()).thenReturn(1);
when(columnOne.getIndex()).thenReturn(2);
when(columnOne.getIndex()).thenReturn(3);
command = new MoveColumnsCommand(decisionTable, model, 2, Arrays.asList(columnOne), canvasOperation);
graphCommand = command.newGraphCommand(canvasHandler);
canvasCommand = command.newCanvasCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
assertEquals(CanvasCommandResultBuilder.SUCCESS, canvasCommand.execute(canvasHandler));
}
use of org.kie.workbench.common.dmn.api.definition.model.DecisionRule in project kie-wb-common by kiegroup.
the class AddInputClauseCommandTest method testGraphCommandExecute.
@Test
public void testGraphCommandExecute() throws Exception {
makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
dtable.getRule().add(new DecisionRule());
dtable.getRule().add(new DecisionRule());
assertEquals(0, dtable.getInput().size());
final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
// one new input column
assertEquals(1, dtable.getInput().size());
assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_PREFIX + "1", dtable.getInput().get(0).getInputExpression().getText().getValue());
// first rule
final List<UnaryTests> inputEntriesRuleOne = dtable.getRule().get(0).getInputEntry();
assertEquals(1, inputEntriesRuleOne.size());
assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, inputEntriesRuleOne.get(0).getText().getValue());
assertEquals(dtable.getRule().get(0), inputEntriesRuleOne.get(0).getParent());
// second rule
final List<UnaryTests> inputEntriesRuleTwo = dtable.getRule().get(1).getInputEntry();
assertEquals(1, inputEntriesRuleTwo.size());
assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, inputEntriesRuleTwo.get(0).getText().getValue());
assertEquals(dtable.getRule().get(1), inputEntriesRuleTwo.get(0).getParent());
assertEquals(dtable, inputClause.getParent());
}
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 DecisionTableGridTest method testDuplicateDecisionRule.
@Test
@SuppressWarnings("unchecked")
public void testDuplicateDecisionRule() {
setupGrid(makeHasNameForDecision(), 0);
final DecisionTable dtable = grid.getExpression().get().get();
assertThat(dtable.getRule().size()).isEqualTo(1);
final DecisionRule rule0 = dtable.getRule().get(0);
assertThat(rule0.getInputEntry().size()).isEqualTo(1);
assertThat(rule0.getOutputEntry().size()).isEqualTo(1);
rule0.getInputEntry().get(0).getText().setValue("input");
rule0.getOutputEntry().get(0).getText().setValue("output");
rule0.getDescription().setValue("description");
grid.duplicateDecisionRule(0);
verify(sessionCommandManager).execute(eq(canvasHandler), addDecisionRuleCommandCaptor.capture());
final AddDecisionRuleCommand addDecisionRuleCommand = addDecisionRuleCommandCaptor.getValue();
addDecisionRuleCommand.execute(canvasHandler);
assertThat(dtable.getRule().size()).isEqualTo(2);
final DecisionRule rule1 = dtable.getRule().get(1);
assertThat(rule1.getInputEntry().size()).isEqualTo(1);
assertThat(rule1.getOutputEntry().size()).isEqualTo(1);
assertThat(rule0.getInputEntry().get(0).getText().getValue()).isEqualTo("input");
assertThat(rule0.getOutputEntry().get(0).getText().getValue()).isEqualTo("output");
assertThat(rule0.getDescription().getValue()).isEqualTo("description");
assertThat(rule1.getInputEntry().get(0).getText().getValue()).isEqualTo("input");
assertThat(rule1.getOutputEntry().get(0).getText().getValue()).isEqualTo("output");
assertThat(rule1.getDescription().getValue()).isEqualTo("description");
verifyCommandExecuteOperation(BaseExpressionGrid.RESIZE_EXISTING);
}
Aggregations