Search in sources :

Example 1 with LiteralExpression

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

the class ExpressionContainerUIModelMapperTest method testFromDMNModelExpressionGridCacheIsHit.

@Test
@SuppressWarnings("unchecked")
public void testFromDMNModelExpressionGridCacheIsHit() {
    setup(false);
    expression = new LiteralExpression();
    mapper.fromDMNModel(0, 0);
    verify(literalExpressionEditorDefinition).getEditor(eq(parent), nodeUUIDCaptor.capture(), eq(hasExpression), eq(Optional.of(hasName)), eq(false), eq(0));
    verify(expressionGridCache).putExpressionGrid(nodeUUIDCaptor.getValue().get(), Optional.of(literalExpressionEditor));
    mapper.fromDMNModel(0, 0);
    // There should only be one interaction with LiteralExpressionEditorDefinition
    verify(literalExpressionEditorDefinition).getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt());
    verify(expressionGridCache).putExpressionGrid(Mockito.<String>any(), any(Optional.class));
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Optional(java.util.Optional) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Test(org.junit.Test)

Example 2 with LiteralExpression

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

the class ExpressionContainerUIModelMapperTest method testFromDMNModelLiteralExpressionType.

@Test
@SuppressWarnings("unchecked")
public void testFromDMNModelLiteralExpressionType() {
    setup(false);
    expression = new LiteralExpression();
    mapper.fromDMNModel(0, 0);
    assertUiModel();
    assertEditorType(literalExpressionEditor.getClass());
    verify(literalExpressionEditorDefinition).getEditor(eq(parent), nodeUUIDCaptor.capture(), eq(hasExpression), eq(Optional.of(hasName)), eq(false), eq(0));
    final Optional<String> nodeUUID = nodeUUIDCaptor.getValue();
    assertThat(nodeUUID.isPresent()).isTrue();
    assertThat(nodeUUID.get()).isEqualTo(NODE_UUID);
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Test(org.junit.Test)

Example 3 with LiteralExpression

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

the class DecisionRuleFactoryTest method testDuplicateDecisionRule.

@Test
public void testDuplicateDecisionRule() {
    final DecisionRule rule = DecisionRuleFactory.makeDecisionRule(dtable);
    final List<UnaryTests> inputEntries = rule.getInputEntry();
    assertThat(inputEntries.size()).isEqualTo(2);
    inputEntries.get(0).getText().setValue(INPUT_CLAUSE_TEXT_1);
    inputEntries.get(1).getText().setValue(INPUT_CLAUSE_TEXT_2);
    inputEntries.get(0).setConstraintType(ConstraintType.ENUMERATION);
    inputEntries.get(1).setConstraintType(ConstraintType.RANGE);
    final List<LiteralExpression> outputEntries = rule.getOutputEntry();
    assertThat(outputEntries.size()).isEqualTo(2);
    outputEntries.get(0).getText().setValue(OUTPUT_CLAUSE_TEXT_1);
    outputEntries.get(1).getText().setValue(OUTPUT_CLAUSE_TEXT_2);
    final List<RuleAnnotationClauseText> annotationEntries = rule.getAnnotationEntry();
    assertThat(annotationEntries.size()).isEqualTo(2);
    annotationEntries.get(0).getText().setValue(RULE_ANNOTATION_CLAUSE_TEXT_1);
    annotationEntries.get(1).getText().setValue(RULE_ANNOTATION_CLAUSE_TEXT_2);
    dtable.getRule().add(rule);
    final DecisionRule duplicate = DecisionRuleFactory.duplicateDecisionRule(0, dtable);
    final List<UnaryTests> duplicateInputEntries = duplicate.getInputEntry();
    assertThat(duplicateInputEntries.size()).isEqualTo(2);
    assertUnaryTestsText(duplicateInputEntries.get(0), INPUT_CLAUSE_TEXT_1);
    assertUnaryTestsText(duplicateInputEntries.get(1), INPUT_CLAUSE_TEXT_2);
    assertThat(duplicateInputEntries.get(0).getConstraintType()).isEqualTo(ConstraintType.ENUMERATION);
    assertThat(duplicateInputEntries.get(1).getConstraintType()).isEqualTo(ConstraintType.RANGE);
    assertUnaryTestsInstancesAreNotTheSame(inputEntries.get(0), duplicateInputEntries.get(0));
    assertUnaryTestsInstancesAreNotTheSame(inputEntries.get(1), duplicateInputEntries.get(1));
    assertThat(duplicateInputEntries).allSatisfy(unaryTests -> assertThat(unaryTests.getParent()).isEqualTo(duplicate));
    final List<LiteralExpression> duplicateOutputEntries = duplicate.getOutputEntry();
    assertThat(duplicateOutputEntries.size()).isEqualTo(2);
    assertLiteralExpressionText(duplicateOutputEntries.get(0), OUTPUT_CLAUSE_TEXT_1);
    assertLiteralExpressionText(duplicateOutputEntries.get(1), OUTPUT_CLAUSE_TEXT_2);
    assertLiteralExpressionInstancesAreNotTheSame(outputEntries.get(0), duplicateOutputEntries.get(0));
    assertLiteralExpressionInstancesAreNotTheSame(outputEntries.get(1), duplicateOutputEntries.get(1));
    assertThat(duplicateOutputEntries).allSatisfy(literalExpression -> assertThat(literalExpression.getParent()).isEqualTo(duplicate));
    final List<RuleAnnotationClauseText> duplicateRuleAnnotationClauses = duplicate.getAnnotationEntry();
    assertThat(duplicateRuleAnnotationClauses.size()).isEqualTo(2);
    assertAnnotationClauseText(duplicateRuleAnnotationClauses.get(0), RULE_ANNOTATION_CLAUSE_TEXT_1);
    assertAnnotationClauseText(duplicateRuleAnnotationClauses.get(1), RULE_ANNOTATION_CLAUSE_TEXT_2);
    assertRuleAnnotationClauseInstancesAreNotTheSame(annotationEntries.get(0), duplicateRuleAnnotationClauses.get(0));
    assertRuleAnnotationClauseInstancesAreNotTheSame(annotationEntries.get(1), duplicateRuleAnnotationClauses.get(1));
    assertThat(duplicateRuleAnnotationClauses).allSatisfy(ruleAnnotationClauseText -> assertThat(ruleAnnotationClauseText.getParent()).isEqualTo(duplicate));
    assertThat(duplicate.getParent()).isEqualTo(dtable);
}
Also used : 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)

Example 4 with LiteralExpression

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

the class ExpressionContainerGridTest method testSpyHasExpressionWithExpressionSet.

@Test
public void testSpyHasExpressionWithExpressionSet() {
    final HasExpression hasExpression = new HasExpression() {

        private Expression expression = new LiteralExpression();

        @Override
        public Expression getExpression() {
            return expression;
        }

        @Override
        public void setExpression(final Expression expression) {
            this.expression = expression;
        }

        @Override
        public DMNModelInstrumentedBase asDMNModelInstrumentedBase() {
            return null;
        }
    };
    grid.setExpression(NODE_UUID, hasExpression, Optional.of(hasName), false);
    final HasExpression spy = grid.spyHasExpression(hasExpression);
    spy.setExpression(null);
    assertThat(hasExpression.getExpression()).isNull();
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) 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) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Test(org.junit.Test)

Example 5 with LiteralExpression

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

the class ExpressionContainerGridTest method testSelectCellWithDomainObjectInStunnerGraph.

@Test
public void testSelectCellWithDomainObjectInStunnerGraph() {
    final int uiRowIndex = 0;
    final int uiColumnIndex = 1;
    final LiteralExpression domainObject = mock(LiteralExpression.class);
    when(hasExpression.asDMNModelInstrumentedBase()).thenReturn(domainObject);
    when(graph.nodes()).thenReturn(Collections.singletonList(node));
    final Definition definition = mock(Definition.class);
    when(node.getUUID()).thenReturn(NODE_UUID);
    when(node.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(domainObject);
    grid.setExpression(NODE_UUID, hasExpression, Optional.of(hasName), false);
    grid.selectCell(uiRowIndex, uiColumnIndex, false, true);
    verify(gridLayer).select(eq(grid));
    verify(refreshFormPropertiesEvent).fire(refreshFormPropertiesEventCaptor.capture());
    final RefreshFormPropertiesEvent refreshFormPropertiesEvent = refreshFormPropertiesEventCaptor.getValue();
    assertThat(refreshFormPropertiesEvent.getUuid()).isEqualTo(NODE_UUID);
    assertThat(refreshFormPropertiesEvent.getSession()).isEqualTo(session);
    verify(cellSelectionManager).selectCell(eq(uiRowIndex), eq(uiColumnIndex), eq(false), eq(true));
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) UndefinedExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionEditorDefinition) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) RefreshFormPropertiesEvent(org.kie.workbench.common.stunner.forms.client.event.RefreshFormPropertiesEvent) 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