Search in sources :

Example 31 with OutputClause

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

the class AddOutputClauseCommandTest method testGraphCommandExecuteInsertMiddle.

@Test
public void testGraphCommandExecuteInsertMiddle() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + 1);
    final String ruleOutputOne = "rule out 1";
    final String ruleOutputTwo = "rule out 2";
    dtable.getOutput().add(new OutputClause());
    dtable.getOutput().add(new OutputClause());
    addRuleWithOutputClauseValues(ruleOutputOne, ruleOutputTwo);
    assertEquals(2, dtable.getOutput().size());
    // Graph command will insert new OutputClause at index 1 of the OutputEntries
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    assertEquals(3, dtable.getOutput().size());
    assertNull(dtable.getOutput().get(0).getName());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1", dtable.getOutput().get(1).getName());
    assertNull(dtable.getOutput().get(2).getName());
    final List<LiteralExpression> ruleOutputs = dtable.getRule().get(0).getOutputEntry();
    // first rule
    assertEquals(3, ruleOutputs.size());
    assertEquals(ruleOutputOne, ruleOutputs.get(0).getText().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, ruleOutputs.get(1).getText().getValue());
    assertEquals(dtable.getRule().get(0), ruleOutputs.get(1).getParent());
    assertEquals(ruleOutputTwo, ruleOutputs.get(2).getText().getValue());
    assertEquals(dtable, outputClause.getParent());
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 32 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.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, DEFAULT_HEIGHT);
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiOutputClauseColumn).getIndex();
}
Also used : OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.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 33 with OutputClause

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

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsContextEntryDefaultResult.

@Test
public void testModelEnrichmentWhenParentIsContextEntryDefaultResult() {
    final String name = "decision";
    final Context context = new Context();
    final ContextEntry contextEntry = new ContextEntry();
    context.getContextEntry().add(contextEntry);
    contextEntry.setParent(context);
    context.setParent(decision);
    decision.setName(new Name(name));
    decision.getVariable().setTypeRef(OUTPUT_DATA_QNAME);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    oModel.get().setParent(contextEntry);
    definition.enrich(Optional.empty(), decision, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    assertStandardInputClauseEnrichment(model);
    final List<OutputClause> output = model.getOutput();
    assertThat(output.size()).isEqualTo(1);
    assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
    assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 34 with OutputClause

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

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsNestedContextEntryDefaultResult.

@Test
public void testModelEnrichmentWhenParentIsNestedContextEntryDefaultResult() {
    final Decision decision = mock(Decision.class);
    final String name = "context-entry";
    final Context innerContext = new Context();
    final ContextEntry innerContextEntry = new ContextEntry();
    innerContext.getContextEntry().add(innerContextEntry);
    innerContextEntry.setParent(innerContext);
    final Context outerContext = new Context();
    final ContextEntry outerContextEntry = new ContextEntry();
    outerContext.getContextEntry().add(outerContextEntry);
    outerContextEntry.setParent(outerContext);
    innerContext.setParent(outerContextEntry);
    outerContext.setParent(decision);
    outerContextEntry.setVariable(new InformationItem(new Id(), new Description(), new Name(name), OUTPUT_DATA_QNAME));
    when(decision.asDMNModelInstrumentedBase()).thenReturn(outerContextEntry);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    oModel.get().setParent(innerContextEntry);
    definition.enrich(Optional.empty(), decision, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    assertStandardInputClauseEnrichment(model);
    final List<OutputClause> output = model.getOutput();
    assertThat(output.size()).isEqualTo(1);
    assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
    assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 35 with OutputClause

use of org.kie.workbench.common.dmn.api.definition.model.OutputClause 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)

Aggregations

OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)40 Test (org.junit.Test)24 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)21 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)14 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)12 InputClause (org.kie.workbench.common.dmn.api.definition.model.InputClause)10 RuleAnnotationClause (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause)9 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)8 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)8 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)7 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)7 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)7 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)6 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)6 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)5 InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)5 Before (org.junit.Before)4 TDecisionTable (org.kie.dmn.model.v1_2.TDecisionTable)4 TOutputClause (org.kie.dmn.model.v1_2.TOutputClause)4 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)4