Search in sources :

Example 91 with LiteralExpression

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

the class DeleteRelationRowCommandTest method testCanvasCommandUndoWithColumns.

@Test
public void testCanvasCommandUndoWithColumns() {
    relation.getColumn().add(new InformationItem());
    final LiteralExpression literalExpression = new LiteralExpression();
    literalExpression.getText().setValue(VALUE);
    relation.getRow().get(0).getExpression().add(HasExpression.wrap(rowList, literalExpression));
    uiModel.appendColumn(uiModelColumn);
    uiModelMapper.fromDMNModel(0, 0);
    uiModelMapper.fromDMNModel(0, 1);
    // Delete row and then undo
    final Command<AbstractCanvasHandler, CanvasViolation> cc = command.newCanvasCommand(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.execute(handler));
    reset(command, canvasOperation);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.undo(handler));
    assertEquals(2, uiModel.getColumnCount());
    assertEquals(uiRowNumberColumn, uiModel.getColumns().get(0));
    assertEquals(uiModelColumn, uiModel.getColumns().get(1));
    assertEquals(1, uiModel.getRowCount());
    assertEquals(1, uiModel.getCell(0, 0).getValue().getValue());
    assertEquals(VALUE, uiModel.getCell(0, 1).getValue().getValue());
    verify(command).updateRowNumbers();
    verify(command).updateParentInformation();
    verify(canvasOperation).execute();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Test(org.junit.Test)

Example 92 with LiteralExpression

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

the class ExpressionContainerGridTest method testSelectCellWithPoint.

@Test
public void testSelectCellWithPoint() {
    final Point2D point = mock(Point2D.class);
    final LiteralExpression domainObject = mock(LiteralExpression.class);
    when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(domainObject);
    grid.setExpression(NODE_UUID, hasExpression, Optional.of(hasName), false);
    grid.selectCell(point, false, true);
    verify(gridLayer).select(eq(grid));
    verify(domainObjectSelectionEvent).fire(domainObjectSelectionEventCaptor.capture());
    final DomainObjectSelectionEvent domainObjectSelectionEvent = domainObjectSelectionEventCaptor.getValue();
    assertThat(domainObjectSelectionEvent.getCanvasHandler()).isEqualTo(canvasHandler);
    assertThat(domainObjectSelectionEvent.getDomainObject()).isEqualTo(domainObject);
    verify(cellSelectionManager).selectCell(eq(point), eq(false), eq(true));
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) DomainObjectSelectionEvent(org.kie.workbench.common.stunner.core.client.canvas.event.selection.DomainObjectSelectionEvent) Test(org.junit.Test)

Example 93 with LiteralExpression

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

Example 94 with LiteralExpression

use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression 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());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1", dtable.getOutput().get(0).getName());
    assertNull(dtable.getOutput().get(1).getName());
    // first rule
    final List<LiteralExpression> outputEntriesRuleOne = dtable.getRule().get(0).getOutputEntry();
    assertEquals(2, outputEntriesRuleOne.size());
    assertEquals(ruleOneOldOutput, outputEntriesRuleOne.get(1).getText().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, outputEntriesRuleOne.get(0).getText().getValue());
    assertEquals(dtable.getRule().get(0), outputEntriesRuleOne.get(0).getParent());
    // second rule
    final List<LiteralExpression> outputEntriesRuleTwo = dtable.getRule().get(1).getOutputEntry();
    assertEquals(2, outputEntriesRuleTwo.size());
    assertEquals(ruleTwoOldOutput, outputEntriesRuleTwo.get(1).getText().getValue());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT, outputEntriesRuleTwo.get(0).getText().getValue());
    assertEquals(dtable.getRule().get(1), outputEntriesRuleTwo.get(0).getParent());
    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 95 with LiteralExpression

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

the class AddOutputClauseCommandTest method testCanvasCommandAddOutputClauseToRuleWithInputs.

@Test
public void testCanvasCommandAddOutputClauseToRuleWithInputs() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT + 1);
    final String ruleInputValue = "in value";
    final String ruleOutputValue = "out value";
    dtable.getInput().add(new InputClause());
    dtable.getRule().add(new DecisionRule() {

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

                {
                    getText().setValue(ruleInputValue);
                }
            });
            getOutputEntry().add(new LiteralExpression() {

                {
                    getText().setValue(ruleOutputValue);
                }
            });
        }
    });
    // Graph command populates OutputEntries so overwrite with test values
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    graphCommand.execute(graphCommandExecutionContext);
    dtable.getRule().get(0).getOutputEntry().get(0).getText().setValue(ruleOutputValue);
    doReturn(1).when(uiInputClauseColumn).getIndex();
    doReturn(2).when(uiOutputClauseColumn).getIndex();
    uiModel.appendColumn(uiInputClauseColumn);
    uiModel.appendRow(new BaseGridRow());
    uiModelMapper.fromDMNModel(0, 1);
    final Command<AbstractCanvasHandler, CanvasViolation> canvasAddOutputClauseCommand = command.newCanvasCommand(canvasHandler);
    canvasAddOutputClauseCommand.execute(canvasHandler);
    assertEquals(ruleInputValue, uiModel.getRow(0).getCells().get(1).getValue().getValue());
    assertEquals(ruleOutputValue, uiModel.getRow(0).getCells().get(2).getValue().getValue());
    assertEquals(3, uiModel.getColumnCount());
    assertEquals(CanvasCommandResultBuilder.SUCCESS, canvasAddOutputClauseCommand.undo(canvasHandler));
    assertEquals(2, 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) 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) 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) Test(org.junit.Test)

Aggregations

LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)113 Test (org.junit.Test)64 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)25 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)25 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)23 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)21 List (org.kie.workbench.common.dmn.api.definition.model.List)20 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)16 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)15 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)14 Before (org.junit.Before)13 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)12 Optional (java.util.Optional)11 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)11 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)11 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)11 Context (org.kie.workbench.common.dmn.api.definition.model.Context)10 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)10 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)9 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)9