Search in sources :

Example 61 with LiteralExpression

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

the class ContextEntryPropertyConverterTest method testDMNFromWBWithNullWBExpression.

@Test
public void testDMNFromWBWithNullWBExpression() {
    final ContextEntry wb = new ContextEntry();
    final InformationItem informationItem = new InformationItem();
    wb.setVariable(informationItem);
    wb.setExpression(null);
    final org.kie.dmn.model.api.ContextEntry dmn = ContextEntryPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getVariable()).isNotNull();
    assertThat(dmn.getExpression()).isNotNull();
    assertThat(dmn.getExpression()).isInstanceOf(org.kie.dmn.model.api.LiteralExpression.class);
    final org.kie.dmn.model.api.LiteralExpression literalExpression = (org.kie.dmn.model.api.LiteralExpression) dmn.getExpression();
    assertThat(literalExpression.getText()).isEqualTo(ContextEntry.DEFAULT_EXPRESSION_VALUE);
}
Also used : TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) TContextEntry(org.kie.dmn.model.v1_2.TContextEntry) Test(org.junit.Test)

Example 62 with LiteralExpression

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

the class RelationEditorDefinition method enrich.

@Override
public void enrich(final Optional<String> nodeUUID, final HasExpression hasExpression, final Optional<Relation> expression) {
    expression.ifPresent(relation -> {
        final InformationItem column = new InformationItem();
        column.getName().setValue(RelationDefaultValueUtilities.getNewColumnName(relation));
        final org.kie.workbench.common.dmn.api.definition.model.List row = new org.kie.workbench.common.dmn.api.definition.model.List();
        final LiteralExpression literalExpression = new LiteralExpression();
        row.getExpression().add(HasExpression.wrap(relation, literalExpression));
        relation.getColumn().add(column);
        relation.getRow().add(row);
        // Setup parent relationships
        column.setParent(relation);
        row.setParent(relation);
        literalExpression.setParent(row);
    });
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem)

Example 63 with LiteralExpression

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

the class ContextPropertyConverterTest method testDMNFromWBWithDefault.

@Test
public void testDMNFromWBWithDefault() {
    final LiteralExpression defaultExpression = new LiteralExpression();
    defaultExpression.getId().setValue(DEFAULT_EXPRESSION_UUID);
    defaultExpression.getComponentWidths().set(0, 100.0);
    final Context wb = setupDMNFromWB(Optional.of(defaultExpression));
    final org.kie.dmn.model.api.Context dmn = ContextPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getContextEntry()).isNotNull();
    assertThat(dmn.getContextEntry().size()).isEqualTo(2);
    assertThat(dmn.getContextEntry().get(0)).isNotNull();
    assertThat(dmn.getContextEntry().get(0).getExpression().getId()).isEqualTo(EXPRESSION_UUID);
    assertThat(dmn.getContextEntry().get(1)).isNotNull();
    assertThat(dmn.getContextEntry().get(1).getExpression().getId()).isEqualTo(DEFAULT_EXPRESSION_UUID);
    verify(componentWidthsConsumer, times(2)).accept(componentWidthsCaptor.capture());
    final List<ComponentWidths> componentWidths = componentWidthsCaptor.getAllValues();
    assertThat(componentWidths).isNotNull();
    assertThat(componentWidths.size()).isEqualTo(2);
    assertThat(componentWidths.get(0).getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
    assertThat(componentWidths.get(0).getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
    assertThat(componentWidths.get(0).getWidths().get(0)).isEqualTo(200.0);
    assertThat(componentWidths.get(1).getDmnElementRef().getLocalPart()).isEqualTo(DEFAULT_EXPRESSION_UUID);
    assertThat(componentWidths.get(1).getWidths().size()).isEqualTo(defaultExpression.getRequiredComponentWidthCount());
    assertThat(componentWidths.get(1).getWidths().get(0)).isEqualTo(100.0);
}
Also used : TContext(org.kie.dmn.model.v1_2.TContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) Test(org.junit.Test)

Example 64 with LiteralExpression

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

the class ListPropertyConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final List wb = new List();
    final LiteralExpression literalExpression = new LiteralExpression();
    final HasExpression hasExpression = HasExpression.wrap(wb, literalExpression);
    literalExpression.getComponentWidths().set(0, 200.0);
    literalExpression.getId().setValue(EXPRESSION_UUID);
    wb.getId().setValue(LIST_UUID);
    wb.getDescription().setValue(LIST_DESCRIPTION);
    wb.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(org.kie.workbench.common.dmn.api.property.dmn.QName.NULL_NS_URI, LIST_QNAME_LOCALPART));
    wb.getExpression().add(hasExpression);
    final org.kie.dmn.model.api.List dmn = ListPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getId()).isNotNull();
    assertThat(dmn.getId()).isEqualTo(LIST_UUID);
    assertThat(dmn.getDescription()).isNotNull();
    assertThat(dmn.getDescription()).isEqualTo(LIST_DESCRIPTION);
    assertThat(dmn.getTypeRef()).isNotNull();
    assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(LIST_QNAME_LOCALPART);
    assertThat(dmn.getExpression()).isNotNull();
    assertThat(dmn.getExpression().size()).isEqualTo(1);
    assertThat(dmn.getExpression().get(0).getId()).isEqualTo(EXPRESSION_UUID);
    verify(componentWidthsConsumer).accept(componentWidthsCaptor.capture());
    final ComponentWidths componentWidths = componentWidthsCaptor.getValue();
    assertThat(componentWidths).isNotNull();
    assertThat(componentWidths.getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
    assertThat(componentWidths.getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
    assertThat(componentWidths.getWidths().get(0)).isEqualTo(200.0);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) List(org.kie.workbench.common.dmn.api.definition.model.List) TList(org.kie.dmn.model.v1_2.TList) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) Test(org.junit.Test)

Example 65 with LiteralExpression

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

the class RelationPropertyConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final Relation wb = new Relation();
    final InformationItem informationItem = new InformationItem();
    final List list = new List();
    final LiteralExpression literalExpression = new LiteralExpression();
    final HasExpression hasExpression = HasExpression.wrap(wb, literalExpression);
    literalExpression.getComponentWidths().set(0, 200.0);
    literalExpression.getId().setValue(EXPRESSION_UUID);
    list.getExpression().add(hasExpression);
    wb.getId().setValue(RELATION_UUID);
    wb.getDescription().setValue(RELATION_DESCRIPTION);
    wb.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(org.kie.workbench.common.dmn.api.property.dmn.QName.NULL_NS_URI, RELATION_QNAME_LOCALPART));
    wb.getColumn().add(informationItem);
    wb.getRow().add(list);
    final org.kie.dmn.model.api.Relation dmn = RelationPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getId()).isNotNull();
    assertThat(dmn.getId()).isEqualTo(RELATION_UUID);
    assertThat(dmn.getDescription()).isNotNull();
    assertThat(dmn.getDescription()).isEqualTo(RELATION_DESCRIPTION);
    assertThat(dmn.getTypeRef()).isNotNull();
    assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(RELATION_QNAME_LOCALPART);
    assertThat(dmn.getColumn()).isNotNull();
    assertThat(dmn.getColumn().size()).isEqualTo(1);
    assertThat(dmn.getColumn().get(0)).isNotNull();
    assertThat(dmn.getRow()).isNotNull();
    assertThat(dmn.getRow().size()).isEqualTo(1);
    assertThat(dmn.getRow().get(0)).isNotNull();
    assertThat(dmn.getRow().get(0).getExpression()).isNotNull();
    assertThat(dmn.getRow().get(0).getExpression().size()).isEqualTo(1);
    assertThat(dmn.getRow().get(0).getExpression().get(0).getId()).isEqualTo(EXPRESSION_UUID);
    verify(componentWidthsConsumer).accept(componentWidthsCaptor.capture());
    final ComponentWidths componentWidths = componentWidthsCaptor.getValue();
    assertThat(componentWidths).isNotNull();
    assertThat(componentWidths.getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
    assertThat(componentWidths.getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
    assertThat(componentWidths.getWidths().get(0)).isEqualTo(200.0);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TRelation(org.kie.dmn.model.v1_2.TRelation) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) List(org.kie.workbench.common.dmn.api.definition.model.List) TList(org.kie.dmn.model.v1_2.TList) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) 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