Search in sources :

Example 21 with LiteralExpression

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

the class FunctionDefinitionPropertyConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final FunctionDefinition wb = new FunctionDefinition();
    final LiteralExpression literalExpression = new LiteralExpression();
    literalExpression.getComponentWidths().set(0, 200.0);
    literalExpression.getId().setValue(EXPRESSION_UUID);
    wb.getId().setValue(FUNCTION_DEFINITION_UUID);
    wb.getDescription().setValue(FUNCTION_DEFINITION_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, FUNCTION_DEFINITION_QNAME_LOCALPART));
    wb.setKind(FunctionDefinition.Kind.JAVA);
    wb.setExpression(literalExpression);
    final org.kie.dmn.model.api.FunctionDefinition dmn = FunctionDefinitionPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getId()).isNotNull();
    assertThat(dmn.getId()).isEqualTo(FUNCTION_DEFINITION_UUID);
    assertThat(dmn.getDescription()).isNotNull();
    assertThat(dmn.getDescription()).isEqualTo(FUNCTION_DEFINITION_DESCRIPTION);
    assertThat(dmn.getTypeRef()).isNotNull();
    assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(FUNCTION_DEFINITION_QNAME_LOCALPART);
    assertThat(dmn.getKind()).isNotNull();
    assertThat(dmn.getKind()).isEqualTo(FunctionKind.JAVA);
    assertThat(dmn.getExpression()).isNotNull();
    assertThat(dmn.getExpression().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 : TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) TFunctionDefinition(org.kie.dmn.model.v1_2.TFunctionDefinition) 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 22 with LiteralExpression

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

the class InvocationPropertyConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final Invocation wb = new Invocation();
    final LiteralExpression literalExpression = new LiteralExpression();
    literalExpression.getComponentWidths().set(0, 200.0);
    literalExpression.getId().setValue(EXPRESSION_UUID);
    wb.getId().setValue(INVOCATION_UUID);
    wb.getDescription().setValue(INVOCATION_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, INVOCATION_QNAME_LOCALPART));
    wb.setExpression(literalExpression);
    final org.kie.dmn.model.api.Invocation dmn = InvocationPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getId()).isNotNull();
    assertThat(dmn.getId()).isEqualTo(INVOCATION_UUID);
    assertThat(dmn.getDescription()).isNotNull();
    assertThat(dmn.getDescription()).isEqualTo(INVOCATION_DESCRIPTION);
    assertThat(dmn.getTypeRef()).isNotNull();
    assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(INVOCATION_QNAME_LOCALPART);
    assertThat(dmn.getExpression()).isNotNull();
    assertThat(dmn.getExpression().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 : TInvocation(org.kie.dmn.model.v1_2.TInvocation) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) 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 23 with LiteralExpression

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

the class ContextEntryPropertyConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final ContextEntry wb = new ContextEntry();
    final InformationItem informationItem = new InformationItem();
    wb.setVariable(informationItem);
    final LiteralExpression literalExpression = new LiteralExpression();
    literalExpression.getComponentWidths().set(0, 200.0);
    literalExpression.getId().setValue(EXPRESSION_UUID);
    wb.setExpression(literalExpression);
    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().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 : 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) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) TContextEntry(org.kie.dmn.model.v1_2.TContextEntry) Test(org.junit.Test)

Example 24 with LiteralExpression

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

the class ExpressionPropertyConverterTest method testDMNFromWB_LiteralExpressionConversion.

@Test
public void testDMNFromWB_LiteralExpressionConversion() {
    final LiteralExpression wb = new LiteralExpression();
    final List<Double> wbComponentWidths = wb.getComponentWidths();
    wbComponentWidths.set(0, 200.0);
    wb.getId().setValue(EXPRESSION_UUID);
    assertDMNFromWBConversion(wb, TLiteralExpression.class, 200.0);
}
Also used : TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Test(org.junit.Test)

Example 25 with LiteralExpression

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

the class AddOutputClauseCommandTest method testGraphCommandExecute.

@Test
public void testGraphCommandExecute() throws Exception {
    makeCommand(DecisionTableUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT);
    dtable.getRule().add(new DecisionRule());
    dtable.getRule().add(new DecisionRule());
    assertEquals(0, dtable.getOutput().size());
    final Command<GraphCommandExecutionContext, RuleViolation> graphCommand = command.newGraphCommand(canvasHandler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, graphCommand.execute(graphCommandExecutionContext));
    // one new output column
    assertEquals(1, dtable.getOutput().size());
    assertEquals(DecisionTableDefaultValueUtilities.OUTPUT_CLAUSE_PREFIX + "1", dtable.getOutput().get(0).getName());
    // first rule
    final List<LiteralExpression> outputEntriesRuleOne = dtable.getRule().get(0).getOutputEntry();
    assertEquals(1, outputEntriesRuleOne.size());
    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(1, outputEntriesRuleTwo.size());
    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 : 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) 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