Search in sources :

Example 96 with LiteralExpression

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

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

the class ExpressionEditorViewImplTest method testSetExpressionDoesUpdateExpressionTypeTextWhenHasExpressionIsNotEmpty.

@Test
public void testSetExpressionDoesUpdateExpressionTypeTextWhenHasExpressionIsNotEmpty() {
    final Expression expression = new LiteralExpression();
    final Optional<HasName> hasName = Optional.empty();
    when(hasExpression.getExpression()).thenReturn(expression);
    view.setExpression(NODE_UUID, hasExpression, hasName, false);
    verify(expressionType).setTextContent(eq(LITERAL_EXPRESSION_DEFINITION_NAME));
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) HasName(org.kie.workbench.common.dmn.api.definition.HasName) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Test(org.junit.Test)

Example 98 with LiteralExpression

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

the class ExpressionEditorViewImplTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    this.expressionGridCache = new ExpressionGridCacheImpl();
    this.gridPanelContainer = spy(new DMNGridPanelContainer());
    when(sessionManager.getCurrentSession()).thenReturn(session);
    when(session.getExpressionGridCache()).thenReturn(expressionGridCache);
    when(session.getGridPanel()).thenReturn(gridPanel);
    when(session.getGridLayer()).thenReturn(gridLayer);
    when(session.getCellEditorControls()).thenReturn(cellEditorControls);
    when(session.getMousePanMediator()).thenReturn(mousePanMediator);
    doReturn(viewport).when(gridPanel).getViewport();
    doReturn(viewportMediators).when(viewport).getMediators();
    doReturn(gridPanelElement).when(gridPanel).getElement();
    doReturn(Optional.of(editor)).when(editorDefinition).getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt());
    doReturn(new BaseGridData()).when(editor).getModel();
    this.view = spy(new ExpressionEditorViewImpl(returnToLink, expressionName, expressionType, gridPanelContainer, translationService, listSelector, sessionManager, sessionCommandManager, canvasCommandFactory, expressionEditorDefinitionsSupplier, refreshFormPropertiesEvent, domainObjectSelectionEvent));
    view.init(presenter);
    view.bind(session);
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(undefinedExpressionEditorDefinition.getModelClass()).thenReturn(Optional.empty());
    when(undefinedExpressionEditorDefinition.getName()).thenReturn(UNDEFINED_EXPRESSION_DEFINITION_NAME);
    when(undefinedExpressionEditor.getModel()).thenReturn(new BaseGridData());
    when(undefinedExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(undefinedExpressionEditor));
    when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(new LiteralExpression()));
    when(literalExpressionEditorDefinition.getName()).thenReturn(LITERAL_EXPRESSION_DEFINITION_NAME);
    when(literalExpressionEditor.getModel()).thenReturn(new BaseGridData());
    when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
    doAnswer((i) -> i.getArguments()[1]).when(translationService).format(Mockito.<String>any(), anyObject());
    doAnswer((i) -> i.getArguments()[0]).when(translationService).getTranslation(Mockito.<String>any());
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Optional(java.util.Optional) DMNGridPanelContainer(org.kie.workbench.common.dmn.client.widgets.panel.DMNGridPanelContainer) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) ExpressionGridCacheImpl(org.kie.workbench.common.dmn.client.widgets.grid.ExpressionGridCacheImpl) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Before(org.junit.Before)

Example 99 with LiteralExpression

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

Example 100 with LiteralExpression

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

the class DecisionRuleFactoryTest method testMakeDecisionRule.

@Test
public void testMakeDecisionRule() {
    final DecisionRule rule = DecisionRuleFactory.makeDecisionRule(dtable);
    final List<UnaryTests> inputEntries = rule.getInputEntry();
    assertThat(inputEntries.size()).isEqualTo(2);
    assertThat(inputEntries).allSatisfy(unaryTests -> assertUnaryTestsText(unaryTests, DecisionTableDefaultValueUtilities.INPUT_CLAUSE_UNARY_TEST_TEXT)).allSatisfy(unaryTests -> assertThat(unaryTests.getConstraintType()).isEqualTo(NONE)).allSatisfy(unaryTests -> assertThat(unaryTests.getParent()).isEqualTo(rule));
    final List<LiteralExpression> outputEntries = rule.getOutputEntry();
    assertThat(outputEntries.size()).isEqualTo(2);
    assertThat(outputEntries).allSatisfy(literalExpression -> assertLiteralExpressionText(literalExpression, DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_EXPRESSION_TEXT)).allSatisfy(literalExpression -> assertThat(literalExpression.getParent()).isEqualTo(rule));
    final List<RuleAnnotationClauseText> annotationEntries = rule.getAnnotationEntry();
    assertThat(annotationEntries.size()).isEqualTo(2);
    assertThat(annotationEntries).allSatisfy(clauseText -> assertAnnotationClauseText(clauseText, DecisionTableDefaultValueUtilities.RULE_ANNOTATION_CLAUSE_EXPRESSION_TEXT)).allSatisfy(clauseText -> assertThat(clauseText.getParent()).isEqualTo(rule));
    assertThat(rule.getParent()).isEqualTo(dtable);
}
Also used : RuleAnnotationClause(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClause) NONE(org.kie.workbench.common.dmn.api.definition.model.ConstraintType.NONE) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) Test(org.junit.Test) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) List(java.util.List) InputClause(org.kie.workbench.common.dmn.api.definition.model.InputClause) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) ConstraintType(org.kie.workbench.common.dmn.api.definition.model.ConstraintType) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Before(org.junit.Before) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) 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