Search in sources :

Example 21 with RuleAnnotationClauseText

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

Example 22 with RuleAnnotationClauseText

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));
}
Also used : List(java.util.List) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 23 with RuleAnnotationClauseText

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));
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) RuleAnnotationClauseColumn(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.RuleAnnotationClauseColumn) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 24 with RuleAnnotationClauseText

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);
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) 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) Before(org.junit.Before)

Example 25 with RuleAnnotationClauseText

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);
}
Also used : RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) NONE(org.kie.workbench.common.dmn.api.definition.model.ConstraintType.NONE) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) List(java.util.List) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Before(org.junit.Before) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Aggregations

RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)25 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)14 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)12 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)11 Test (org.junit.Test)10 List (java.util.List)5 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)5 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)5 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)5 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)5 Before (org.junit.Before)3 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)3 Text (org.kie.workbench.common.dmn.api.property.dmn.Text)3 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)3 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)3 AbstractGraphCommand (org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommand)3 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)2 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2 JSITDecisionRule (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule)2