use of org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText 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);
}
use of org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText in project kie-wb-common by kiegroup.
the class DeleteRuleAnnotationClauseCommandTest method testExtractColumnData.
@Test
public void testExtractColumnData() {
final DeleteRuleAnnotationClauseCommand command = mock(DeleteRuleAnnotationClauseCommand.class);
doCallRealMethod().when(command).extractColumnData();
final int clauseIndex = 2;
final DecisionRule rule1 = mock(DecisionRule.class);
final DecisionRule rule2 = mock(DecisionRule.class);
final List<DecisionRule> rules = Arrays.asList(rule1, rule2);
final List rule1AnnotationEntry = mock(List.class);
final List rule2AnnotationEntry = mock(List.class);
final RuleAnnotationClauseText text1 = mock(RuleAnnotationClauseText.class);
final RuleAnnotationClauseText text2 = mock(RuleAnnotationClauseText.class);
when(command.getDecisionTable()).thenReturn(decisionTable);
when(command.getRuleAnnotationClauseIndex()).thenReturn(clauseIndex);
when(rule1AnnotationEntry.get(clauseIndex)).thenReturn(text1);
when(rule2AnnotationEntry.get(clauseIndex)).thenReturn(text2);
when(rule1.getAnnotationEntry()).thenReturn(rule1AnnotationEntry);
when(rule2.getAnnotationEntry()).thenReturn(rule2AnnotationEntry);
when(decisionTable.getRule()).thenReturn(rules);
final List<RuleAnnotationClauseText> columnData = command.extractColumnData();
assertEquals(2, columnData.size());
assertTrue(columnData.contains(text1));
assertTrue(columnData.contains(text2));
}
use of org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText 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.RuleAnnotationClauseText in project kie-wb-common by kiegroup.
the class DecisionTableUIModelMapperTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() {
this.uiModel = new BaseGridData();
this.uiModel.appendRow(new BaseGridRow());
this.uiModel.appendRow(new BaseGridRow());
this.uiModel.appendColumn(uiRowNumberColumn);
this.uiModel.appendColumn(uiInputClauseColumn);
this.uiModel.appendColumn(uiOutputClauseColumn);
this.uiModel.appendColumn(uiAnnotationClauseColumn);
doReturn(0).when(uiRowNumberColumn).getIndex();
doReturn(1).when(uiInputClauseColumn).getIndex();
doReturn(2).when(uiOutputClauseColumn).getIndex();
doReturn(3).when(uiAnnotationClauseColumn).getIndex();
this.dtable = new DecisionTable();
this.dtable.getInput().add(new InputClause());
this.dtable.getOutput().add(new OutputClause());
this.dtable.getAnnotations().add(new RuleAnnotationClause());
this.dtable.getRule().add(new DecisionRule() {
{
getInputEntry().add(new UnaryTests() {
{
getText().setValue("i1");
}
});
getOutputEntry().add(new LiteralExpression() {
{
getText().setValue("o1");
}
});
getAnnotationEntry().add(new RuleAnnotationClauseText() {
{
getText().setValue("a1");
}
});
}
});
this.dtable.getRule().add(new DecisionRule() {
{
getInputEntry().add(new UnaryTests() {
{
getText().setValue("i2");
}
});
getOutputEntry().add(new LiteralExpression() {
{
getText().setValue("o2");
}
});
getAnnotationEntry().add(new RuleAnnotationClauseText() {
{
getText().setValue("a2");
}
});
}
});
this.mapper = new DecisionTableUIModelMapper(() -> uiModel, () -> Optional.of(dtable), listSelector, DEFAULT_HEIGHT);
}
use of org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText in project kie-wb-common by kiegroup.
the class DecisionRuleFactoryTest method testMakeDecisionRule.
@Test
public void testMakeDecisionRule() {
final DecisionRule rule = DecisionRuleFactory.makeDecisionRule(dtable);
final List<UnaryTests> inputEntries = rule.getInputEntry();
assertThat(inputEntries.size()).isEqualTo(2);
assertThat(inputEntries).allSatisfy(unaryTests -> assertUnaryTestsText(unaryTests, DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT)).allSatisfy(unaryTests -> assertThat(unaryTests.getConstraintType()).isEqualTo(NONE)).allSatisfy(unaryTests -> assertThat(unaryTests.getParent()).isEqualTo(rule));
final List<LiteralExpression> outputEntries = rule.getOutputEntry();
assertThat(outputEntries.size()).isEqualTo(2);
assertThat(outputEntries).allSatisfy(literalExpression -> assertLiteralExpressionText(literalExpression, DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT)).allSatisfy(literalExpression -> assertThat(literalExpression.getParent()).isEqualTo(rule));
final List<RuleAnnotationClauseText> annotationEntries = rule.getAnnotationEntry();
assertThat(annotationEntries.size()).isEqualTo(2);
assertThat(annotationEntries).allSatisfy(clauseText -> assertAnnotationClauseText(clauseText, DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_EXPRESSION_TEXT)).allSatisfy(clauseText -> assertThat(clauseText.getParent()).isEqualTo(rule));
assertThat(rule.getParent()).isEqualTo(dtable);
}
Aggregations