Search in sources :

Example 46 with DecisionRule

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);
}
Also used : BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule)

Example 47 with DecisionRule

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));
}
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 48 with DecisionRule

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());
}
Also used : GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test)

Example 49 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 50 with DecisionRule

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);
}
Also used : DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) AddDecisionRuleCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.dtable.AddDecisionRuleCommand) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) 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