Search in sources :

Example 16 with OutputClause

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

the class AddDecisionRuleCommandTest method testCanvasCommandAddRuleAndThenUndo.

@Test
public void testCanvasCommandAddRuleAndThenUndo() throws Exception {
    makeCommand(0);
    dtable.getInput().add(new InputClause());
    dtable.getOutput().add(new OutputClause());
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    uiModel.appendColumn(uiInputClauseColumn);
    uiModel.appendColumn(uiOutputClauseColumn);
    uiModel.appendColumn(uiDescriptionColumn);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasAddRuleCommand = command.newCanvasCommand(canvasHandler);
    canvasAddRuleCommand.execute(canvasHandler);
    assertEquals(1, uiModel.getRowCount());
    assertDefaultUiRowValues(0);
    canvasAddRuleCommand.undo(canvasHandler);
    assertEquals(0, uiModel.getRowCount());
    // 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 : OutputClause(org.kie.workbench.common.dmn.api.definition.v1_1.OutputClause) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) 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) InputClause(org.kie.workbench.common.dmn.api.definition.v1_1.InputClause) Test(org.junit.Test)

Example 17 with OutputClause

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

the class AddOutputClauseCommandTest method testGraphCommandExecuteExistingNotAffected.

@Test
public void testGraphCommandExecuteExistingNotAffected() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    final String ruleOneOldOutput = "old rule 1";
    final String ruleTwoOldOutput = "old rule 2";
    dtable.getOutput().add(new OutputClause());
    addRuleWithOutputClauseValues(ruleOneOldOutput);
    addRuleWithOutputClauseValues(ruleTwoOldOutput);
    assertEquals(1, dtable.getOutput().size());
    // Graph command will insert new OutputClause at index 0 of the OutputEntries
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(2, dtable.getOutput().size());
    // first rule
    assertEquals(2, dtable.getRule().get(0).getOutputEntry().size());
    assertEquals(ruleOneOldOutput, dtable.getRule().get(0).getOutputEntry().get(1).getText());
    assertEquals(AddOutputClauseCommand.OUTPUT_CLAUSE_DEFAULT_VALUE, dtable.getRule().get(0).getOutputEntry().get(0).getText());
    // second rule
    assertEquals(2, dtable.getRule().get(1).getOutputEntry().size());
    assertEquals(ruleTwoOldOutput, dtable.getRule().get(1).getOutputEntry().get(1).getText());
    assertEquals(AddOutputClauseCommand.OUTPUT_CLAUSE_DEFAULT_VALUE, dtable.getRule().get(1).getOutputEntry().get(0).getText());
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.v1_1.OutputClause) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 18 with OutputClause

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

the class AddOutputClauseCommandTest method testGraphCommandUndoJustLastOutputClauseColumn.

@Test
public void testGraphCommandUndoJustLastOutputClauseColumn() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    final String ruleOneOldOutput = "old rule 1";
    final String ruleTwoOldOutput = "old rule 2";
    dtable.getOutput().add(new OutputClause());
    addRuleWithOutputClauseValues(ruleOneOldOutput);
    addRuleWithOutputClauseValues(ruleTwoOldOutput);
    assertEquals(1, dtable.getOutput().size());
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.undo(graphCommandExecutionContext));
    assertEquals(1, dtable.getOutput().size());
    // first rule
    assertEquals(1, dtable.getRule().get(0).getOutputEntry().size());
    assertEquals(ruleOneOldOutput, dtable.getRule().get(0).getOutputEntry().get(0).getText());
    // second rule
    assertEquals(1, dtable.getRule().get(1).getOutputEntry().size());
    assertEquals(ruleTwoOldOutput, dtable.getRule().get(1).getOutputEntry().get(0).getText());
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.v1_1.OutputClause) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 19 with OutputClause

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

the class AddOutputClauseCommandTest method setUp.

@Before
public void setUp() throws Exception {
    this.dtable = new DecisionTable();
    this.uiModel = new DMNGridData();
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.outputClause = new OutputClause();
    this.uiModelMapper = new DecisionTableUIModelMapper(() -> uiModel, () -> Optional.of(dtable), listSelector);
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiOutputClauseColumn).getIndex();
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.v1_1.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.v1_1.DecisionTable) DecisionTableUIModelMapper(org.kie.workbench.common.dmn.client.editors.expressions.types.dtable.DecisionTableUIModelMapper) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) Before(org.junit.Before)

Example 20 with OutputClause

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

the class DecisionTablePropertyConverter method dmnFromWB.

public static org.kie.dmn.model.v1_1.DecisionTable dmnFromWB(final DecisionTable wb) {
    org.kie.dmn.model.v1_1.DecisionTable result = new org.kie.dmn.model.v1_1.DecisionTable();
    result.setId(wb.getId().getValue());
    result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    for (InputClause input : wb.getInput()) {
        result.getInput().add(InputClausePropertyConverter.dmnFromWB(input));
    }
    for (OutputClause input : wb.getOutput()) {
        result.getOutput().add(OutputClausePropertyConverter.dmnFromWB(input));
    }
    for (DecisionRule dr : wb.getRule()) {
        result.getRule().add(DecisionRulePropertyConverter.dmnFromWB(dr));
    }
    if (wb.getHitPolicy() != null) {
        result.setHitPolicy(org.kie.dmn.model.v1_1.HitPolicy.fromValue(wb.getHitPolicy().value()));
    }
    if (wb.getAggregation() != null) {
        result.setAggregation(org.kie.dmn.model.v1_1.BuiltinAggregator.fromValue(wb.getAggregation().value()));
    }
    if (wb.getPreferredOrientation() != null) {
        result.setPreferredOrientation(org.kie.dmn.model.v1_1.DecisionTableOrientation.fromValue(wb.getPreferredOrientation().value()));
    }
    result.setOutputLabel(wb.getOutputLabel());
    return result;
}
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)

Aggregations

OutputClause (org.kie.workbench.common.dmn.api.definition.v1_1.OutputClause)13 DecisionTable (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionTable)8 Test (org.junit.Test)6 InputClause (org.kie.workbench.common.dmn.api.definition.v1_1.InputClause)6 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)6 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)6 OutputClause (org.kie.dmn.model.v1_1.OutputClause)5 DecisionRule (org.kie.workbench.common.dmn.api.definition.v1_1.DecisionRule)5 Before (org.junit.Before)4 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)4 UnaryTests (org.kie.workbench.common.dmn.api.definition.v1_1.UnaryTests)3 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)3 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)3 Optional (java.util.Optional)2 QName (javax.xml.namespace.QName)2 DMNType (org.kie.dmn.api.core.DMNType)2 DMNGridRow (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow)2 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)2 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)2 ArrayList (java.util.ArrayList)1