Search in sources :

Example 21 with InputClause

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

the class AddDecisionRuleCommandTest method testCanvasCommandExecuteInsertBelow.

@Test
public void testCanvasCommandExecuteInsertBelow() {
    // The default behaviour of tests in this class is to "insert above"
    final DecisionRule existingRule = new DecisionRule();
    final GridRow existingUiRow = new BaseGridRow();
    dtable.getRule().add(existingRule);
    uiModel.appendRow(existingUiRow);
    dtable.getInput().add(new InputClause());
    dtable.getOutput().add(new OutputClause());
    dtable.getAnnotations().add(new RuleAnnotationClause());
    makeCommand(1);
    uiModel.appendColumn(uiInputClauseColumn);
    uiModel.appendColumn(uiOutputClauseColumn);
    uiModel.appendColumn(uiRuleAnnotationClauseColumn);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasCommand = command.newCanvasCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    canvasCommand.execute(canvasHandler);
    assertEquals(2, uiModel.getRowCount());
    assertEquals(existingUiRow, uiModel.getRow(0));
    assertEquals(uiModelRow, uiModel.getRow(1));
    assertDefaultUiRowValues(1);
    verify(command).updateRowNumbers();
    verify(command).updateParentInformation();
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) 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) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 22 with InputClause

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

the class AddDecisionRuleCommandTest method testGraphCommandExecuteConstructedRuleInputs.

@Test
public void testGraphCommandExecuteConstructedRuleInputs() {
    assertEquals(0, dtable.getRule().size());
    final int inputsCount = 2;
    for (int i = 0; i < inputsCount; i++) {
        dtable.getInput().add(new InputClause());
    }
    makeCommand(0);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(1, dtable.getRule().size());
    assertEquals(rule, dtable.getRule().get(0));
    assertEquals(inputsCount, rule.getInputEntry().size());
    assertEquals(0, rule.getOutputEntry().size());
    for (int inputIndex = 0; inputIndex < inputsCount; inputIndex++) {
        assertTrue(rule.getInputEntry().get(inputIndex).getText() != null);
        assertEquals(DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT, rule.getInputEntry().get(inputIndex).getText().getValue());
        assertEquals(rule, rule.getInputEntry().get(inputIndex).getParent());
    }
    assertEquals(dtable, rule.getParent());
}
Also used : 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.model.InputClause) Test(org.junit.Test)

Example 23 with InputClause

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

the class AddDecisionRuleCommandTest method testCanvasCommandAddRuleAndThenUndo.

@Test
public void testCanvasCommandAddRuleAndThenUndo() throws Exception {
    dtable.getInput().add(new InputClause());
    dtable.getOutput().add(new OutputClause());
    dtable.getAnnotations().add(new RuleAnnotationClause());
    makeCommand(0);
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    uiModel.appendColumn(uiInputClauseColumn);
    uiModel.appendColumn(uiOutputClauseColumn);
    uiModel.appendColumn(uiRuleAnnotationClauseColumn);
    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.model.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) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) Test(org.junit.Test)

Example 24 with InputClause

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

the class DecisionTablePropertyConverter method dmnFromWB.

public static JSITDecisionTable dmnFromWB(final DecisionTable wb) {
    final JSITDecisionTable result = new JSITDecisionTable();
    result.setId(wb.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    description.ifPresent(result::setDescription);
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    for (final RuleAnnotationClause annotation : wb.getAnnotations()) {
        final JSITRuleAnnotationClause converted = RuleAnnotationClausePropertyConverter.dmnFromWB(annotation);
        result.addAnnotation(converted);
    }
    for (InputClause input : wb.getInput()) {
        final JSITInputClause c = InputClausePropertyConverter.dmnFromWB(input);
        result.addInput(c);
    }
    for (OutputClause input : wb.getOutput()) {
        final JSITOutputClause c = OutputClausePropertyConverter.dmnFromWB(input);
        result.addOutput(c);
    }
    if (result.getOutput().size() == 1) {
        final JSITOutputClause at = Js.uncheckedCast(result.getOutput().get(0));
        // DROOLS-3281
        at.setName(null);
        // DROOLS-5178
        at.setTypeRef(null);
    }
    for (DecisionRule dr : wb.getRule()) {
        final JSITDecisionRule c = DecisionRulePropertyConverter.dmnFromWB(dr);
        result.addRule(c);
    }
    if (Objects.nonNull(wb.getHitPolicy())) {
        switch(wb.getHitPolicy()) {
            case ANY:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.ANY.value()));
                break;
            case COLLECT:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.COLLECT.value()));
                break;
            case FIRST:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.FIRST.value()));
                break;
            case UNIQUE:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.UNIQUE.value()));
                break;
            case PRIORITY:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.PRIORITY.value()));
                break;
            case RULE_ORDER:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.RULE_ORDER.value()));
                break;
            case OUTPUT_ORDER:
                result.setHitPolicy(Js.uncheckedCast(JSITHitPolicy.OUTPUT_ORDER.value()));
                break;
        }
    }
    if (Objects.nonNull(wb.getAggregation())) {
        final String wbBuiltinAggregator = wb.getAggregation().value();
        result.setAggregation(Js.uncheckedCast(wbBuiltinAggregator));
    }
    if (Objects.nonNull(wb.getPreferredOrientation())) {
        final String wbPreferredOrientation = wb.getPreferredOrientation().value();
        result.setPreferredOrientation(Js.uncheckedCast(wbPreferredOrientation));
    }
    result.setOutputLabel(wb.getOutputLabel());
    return result;
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) JSITOutputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause) JSITInputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputClause) JSITRuleAnnotationClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotationClause) RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) JSITDecisionRule(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) JSITOutputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITOutputClause) JSITRuleAnnotationClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotationClause) JSITInputClause(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputClause) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) JSITDecisionRule(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule)

Example 25 with InputClause

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

the class BaseDecisionTableEditorDefinitionTest method assertParentHierarchyEnrichment.

protected void assertParentHierarchyEnrichment(final DecisionTable model) {
    final List<DecisionRule> rules = model.getRule();
    final DecisionRule rule = rules.get(0);
    final int inputClauseCount = model.getInput().size();
    final List<InputClause> inputClauses = model.getInput();
    assertThat(inputClauses.size()).isEqualTo(inputClauseCount);
    inputClauses.forEach(inputClause -> {
        assertThat(inputClause.getParent()).isEqualTo(model);
        assertThat(inputClause.getInputExpression().getParent()).isEqualTo(inputClause);
    });
    final int outputClauseCount = model.getOutput().size();
    final List<OutputClause> outputClauses = model.getOutput();
    assertThat(outputClauses.size()).isEqualTo(outputClauseCount);
    outputClauses.forEach(outputClause -> assertThat(outputClause.getParent()).isEqualTo(model));
    assertThat(rule.getParent()).isEqualTo(model);
    final List<UnaryTests> inputEntries = rule.getInputEntry();
    assertThat(inputEntries.size()).isEqualTo(inputClauseCount);
    inputEntries.forEach(inputEntry -> assertThat(inputEntry.getParent()).isEqualTo(rule));
    final List<LiteralExpression> outputEntries = rule.getOutputEntry();
    assertThat(outputEntries.size()).isEqualTo(outputClauseCount);
    outputEntries.forEach(outputEntry -> assertThat(outputEntry.getParent()).isEqualTo(rule));
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InputClauseLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause)

Aggregations

InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)33 Test (org.junit.Test)18 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)14 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)11 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)10 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)10 InputClauseLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.InputClauseLiteralExpression)8 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)8 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)8 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)8 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)7 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)5 ItemDefinition (org.kie.workbench.common.dmn.api.definition.model.ItemDefinition)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 Before (org.junit.Before)4 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)4 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)4 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)3 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)3 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)3