Search in sources :

Example 11 with DecisionRule

use of org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinition method getModelClass.

@Override
public Optional<DecisionTable> getModelClass() {
    final DecisionTable dtable = new DecisionTable();
    dtable.setHitPolicy(HitPolicy.ANY);
    dtable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW);
    final InputClause ic = new InputClause();
    final LiteralExpression le = new LiteralExpression();
    le.setText(INPUT_CLAUSE_EXPRESSION_TEXT);
    ic.setInputExpression(le);
    dtable.getInput().add(ic);
    final OutputClause oc = new OutputClause();
    oc.setName(OUTPUT_CLAUSE_NAME);
    dtable.getOutput().add(oc);
    final DecisionRule dr = new DecisionRule();
    final UnaryTests drut = new UnaryTests();
    drut.setText(INPUT_CLAUSE_UNARY_TEST_TEXT);
    dr.getInputEntry().add(drut);
    final LiteralExpression drle = new LiteralExpression();
    drle.setText(OUTPUT_CLAUSE_EXPRESSION_TEXT);
    dr.getOutputEntry().add(drle);
    final Description d = new Description();
    d.setValue(RULE_DESCRIPTION);
    dr.setDescription(d);
    dtable.getRule().add(dr);
    return Optional.of(dtable);
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.v1_1.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionTable) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) UnaryTests(org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests) InputClause(org.kie.workbench.common.dmn.api.definition.v1_1.InputClause) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)

Example 12 with DecisionRule

use of org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule in project kie-wb-common by kiegroup.

the class DecisionTableEditorDefinitionTest method testModelDefinition.

@Test
public void testModelDefinition() {
    final Optional<DecisionTable> oModel = definition.getModelClass();
    assertThat(oModel).isPresent();
    final DecisionTable model = oModel.get();
    assertThat(model.getHitPolicy()).isEqualTo(HitPolicy.ANY);
    assertThat(model.getPreferredOrientation()).isEqualTo(DecisionTableOrientation.RULE_AS_ROW);
    final List<InputClause> input = model.getInput();
    assertThat(input.size()).isEqualTo(1);
    assertThat(input.get(0).getInputExpression()).isInstanceOf(LiteralExpression.class);
    final List<OutputClause> output = model.getOutput();
    assertThat(output.size()).isEqualTo(1);
    final List<DecisionRule> rules = model.getRule();
    assertThat(rules.size()).isEqualTo(1);
    final DecisionRule rule = rules.get(0);
    assertThat(rule.getInputEntry().size()).isEqualTo(1);
    assertThat(rule.getInputEntry().get(0)).isInstanceOf(UnaryTests.class);
    assertThat(rule.getOutputEntry().size()).isEqualTo(1);
    assertThat(rule.getOutputEntry().get(0)).isInstanceOf(LiteralExpression.class);
    assertThat(rule.getDescription()).isNotNull();
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.v1_1.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionTable) InputClause(org.kie.workbench.common.dmn.api.definition.v1_1.InputClause) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule) Test(org.junit.Test)

Example 13 with DecisionRule

use of org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule 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 DMNGridRow());
    this.uiModel.appendRow(new DMNGridRow());
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiInputClauseColumn);
    this.uiModel.appendColumn(uiOutputClauseColumn);
    this.uiModel.appendColumn(uiDescriptionColumn);
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiInputClauseColumn).getIndex();
    doReturn(2).when(uiOutputClauseColumn).getIndex();
    doReturn(3).when(uiDescriptionColumn).getIndex();
    this.dtable = new DecisionTable();
    this.dtable.getInput().add(new InputClause());
    this.dtable.getOutput().add(new OutputClause());
    this.dtable.getRule().add(new DecisionRule() {

        {
            getInputEntry().add(new UnaryTests() {

                {
                    setText("i1");
                }
            });
            getOutputEntry().add(new LiteralExpression() {

                {
                    setText("o1");
                }
            });
            setDescription(new Description("desc1"));
        }
    });
    this.dtable.getRule().add(new DecisionRule() {

        {
            getInputEntry().add(new UnaryTests() {

                {
                    setText("i2");
                }
            });
            getOutputEntry().add(new LiteralExpression() {

                {
                    setText("o2");
                }
            });
            setDescription(new Description("desc2"));
        }
    });
    this.mapper = new DecisionTableUIModelMapper(() -> uiModel, () -> Optional.of(dtable), listSelector);
    this.cellValueSupplier = Optional::empty;
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.v1_1.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionTable) DMNGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Optional(java.util.Optional) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) UnaryTests(org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests) InputClause(org.kie.workbench.common.dmn.api.definition.v1_1.InputClause) DecisionRule(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule) Before(org.junit.Before)

Example 14 with DecisionRule

use of org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule in project kie-wb-common by kiegroup.

the class AddDecisionRuleCommandTest method testCanvasCommandExecuteInsertBelowThenUndo.

@Test
public void testCanvasCommandExecuteInsertBelowThenUndo() {
    // The default behaviour of tests in this class is to "insert above"
    final DecisionRule existingRule = new DecisionRule();
    final DMNGridRow existingUiRow = new DMNGridRow();
    dtable.getRule().add(existingRule);
    uiModel.appendRow(existingUiRow);
    makeCommand(1);
    uiModel.appendColumn(uiInputClauseColumn);
    uiModel.appendColumn(uiOutputClauseColumn);
    uiModel.appendColumn(uiDescriptionColumn);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasCommand = command.newCanvasCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    canvasCommand.execute(canvasHandler);
    canvasCommand.undo(canvasHandler);
    assertEquals(1, uiModel.getRowCount());
    assertEquals(existingUiRow, uiModel.getRow(0));
    // one time in execute(), one time in undo()
    verify(canvasOperation, times(2)).execute();
    verify(command, times(2)).updateRowNumbers();
    verify(command, times(2)).updateParentInformation();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) DMNGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow) 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.v1_1.DecisionRule) Test(org.junit.Test)

Example 15 with DecisionRule

use of org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule in project kie-wb-common by kiegroup.

the class AddDecisionRuleCommandTest method testGraphCommandExecuteInsertBelow.

@Test
public void testGraphCommandExecuteInsertBelow() {
    // The default behaviour of tests in this class is to "insert above"
    final DecisionRule existingRule = new DecisionRule();
    dtable.getRule().add(existingRule);
    makeCommand(1);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    assertEquals(2, dtable.getRule().size());
    assertEquals(existingRule, dtable.getRule().get(0));
    assertEquals(rule, dtable.getRule().get(1));
}
Also used : 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.v1_1.DecisionRule) Test(org.junit.Test)

Aggregations

DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)25 Test (org.junit.Test)12 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)12 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)12 DecisionTable (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionTable)9 InputClause (org.kie.workbench.common.dmn.api.definition.v1_1.InputClause)6 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)6 UnaryTests (org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests)6 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)6 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)6 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)6 Before (org.junit.Before)5 OutputClause (org.kie.workbench.common.dmn.api.definition.v1_1.OutputClause)5 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)5 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)3 DecisionTableSection (org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapperHelper.DecisionTableSection)3 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2