Search in sources :

Example 1 with TFunctionDefinition

use of org.kie.dmn.model.v1_3.TFunctionDefinition in project kie-wb-common by kiegroup.

the class FunctionDefinitionPropertyConverterTest method doTestWBFromDMNWithContextEntry.

private void doTestWBFromDMNWithContextEntry(final FunctionKind kind, final String variableName, final Class<? extends IsLiteralExpression> literalExpressionClass) {
    final org.kie.dmn.model.api.FunctionDefinition dmn = new TFunctionDefinition();
    final org.kie.dmn.model.api.Context contextExpression = new TContext();
    final org.kie.dmn.model.api.ContextEntry contextEntry = new TContextEntry();
    final org.kie.dmn.model.api.InformationItem variable = new TInformationItem();
    variable.setName(variableName);
    contextEntry.setVariable(variable);
    contextEntry.setExpression(new TLiteralExpression());
    contextExpression.getContextEntry().add(contextEntry);
    dmn.setKind(kind);
    dmn.setExpression(contextExpression);
    final FunctionDefinition wb = FunctionDefinitionPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
    assertThat(wb.getExpression()).isInstanceOf(Context.class);
    assertThat(((Context) wb.getExpression()).getContextEntry().get(0).getExpression()).isInstanceOf(literalExpressionClass);
}
Also used : TContext(org.kie.dmn.model.v1_2.TContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) TFunctionDefinition(org.kie.dmn.model.v1_2.TFunctionDefinition) TContext(org.kie.dmn.model.v1_2.TContext) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) TFunctionDefinition(org.kie.dmn.model.v1_2.TFunctionDefinition) TContextEntry(org.kie.dmn.model.v1_2.TContextEntry)

Example 2 with TFunctionDefinition

use of org.kie.dmn.model.v1_3.TFunctionDefinition in project kie-wb-common by kiegroup.

the class FunctionDefinitionPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    final org.kie.dmn.model.api.FunctionDefinition dmn = new TFunctionDefinition();
    final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
    literalExpression.setId(EXPRESSION_UUID);
    dmn.setId(FUNCTION_DEFINITION_UUID);
    dmn.setDescription(FUNCTION_DEFINITION_DESCRIPTION);
    dmn.setTypeRef(new QName(FUNCTION_DEFINITION_QNAME_LOCALPART));
    dmn.setKind(FunctionKind.JAVA);
    dmn.setExpression(literalExpression);
    final FunctionDefinition wb = FunctionDefinitionPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
    assertThat(wb).isNotNull();
    assertThat(wb.getId()).isNotNull();
    assertThat(wb.getId().getValue()).isEqualTo(FUNCTION_DEFINITION_UUID);
    assertThat(wb.getDescription()).isNotNull();
    assertThat(wb.getDescription().getValue()).isEqualTo(FUNCTION_DEFINITION_DESCRIPTION);
    assertThat(wb.getTypeRef()).isNotNull();
    assertThat(wb.getTypeRef().getLocalPart()).isEqualTo(FUNCTION_DEFINITION_QNAME_LOCALPART);
    assertThat(wb.getKind()).isNotNull();
    assertThat(wb.getKind()).isEqualTo(FunctionDefinition.Kind.JAVA);
    assertThat(wb.getExpression()).isNotNull();
    assertThat(wb.getExpression().getId().getValue()).isEqualTo(EXPRESSION_UUID);
    verify(hasComponentWidthsConsumer).accept(eq(EXPRESSION_UUID), hasComponentWidthsCaptor.capture());
    final HasComponentWidths hasComponentWidths = hasComponentWidthsCaptor.getValue();
    assertThat(hasComponentWidths).isNotNull();
    assertThat(hasComponentWidths).isEqualTo(wb.getExpression());
}
Also used : TFunctionDefinition(org.kie.dmn.model.v1_2.TFunctionDefinition) QName(javax.xml.namespace.QName) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) TFunctionDefinition(org.kie.dmn.model.v1_2.TFunctionDefinition) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) Test(org.junit.Test)

Example 3 with TFunctionDefinition

use of org.kie.dmn.model.v1_3.TFunctionDefinition in project kie-wb-common by kiegroup.

the class BusinessKnowledgeModelConverterTest method testWBFromDMN.

@Test
@SuppressWarnings("unchecked")
public void testWBFromDMN() {
    final Node<View<BusinessKnowledgeModel>, ?> factoryNode = new NodeImpl<>(UUID.uuid());
    final View<BusinessKnowledgeModel> view = new ViewImpl<>(new BusinessKnowledgeModel(), Bounds.create());
    factoryNode.setContent(view);
    when(factoryManager.newElement(Mockito.<String>any(), eq(getDefinitionId(BusinessKnowledgeModel.class)))).thenReturn(element);
    when(element.asNode()).thenReturn(factoryNode);
    final org.kie.dmn.model.api.BusinessKnowledgeModel dmn = new TBusinessKnowledgeModel();
    final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
    final org.kie.dmn.model.api.InformationItem informationItem = new TInformationItem();
    final org.kie.dmn.model.api.FunctionDefinition functionDefinition = new TFunctionDefinition();
    literalExpression.setId(EXPRESSION_UUID);
    functionDefinition.setExpression(literalExpression);
    functionDefinition.setId(FUNCTION_DEFINITION_UUID);
    dmn.setId(DECISION_UUID);
    dmn.setName(DECISION_NAME);
    dmn.setDescription(DECISION_DESCRIPTION);
    dmn.setVariable(informationItem);
    dmn.setEncapsulatedLogic(functionDefinition);
    final Node<View<BusinessKnowledgeModel>, ?> node = converter.nodeFromDMN(dmn, hasComponentWidthsConsumer);
    final BusinessKnowledgeModel wb = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node);
    assertThat(wb).isNotNull();
    assertThat(wb.getId()).isNotNull();
    assertThat(wb.getId().getValue()).isEqualTo(DECISION_UUID);
    assertThat(wb.getName()).isNotNull();
    assertThat(wb.getName().getValue()).isEqualTo(DECISION_NAME);
    assertThat(wb.getDescription()).isNotNull();
    assertThat(wb.getDescription().getValue()).isEqualTo(DECISION_DESCRIPTION);
    assertThat(wb.getVariable()).isNotNull();
    assertThat(wb.getVariable().getName().getValue()).isEqualTo(DECISION_NAME);
    assertThat(wb.getEncapsulatedLogic()).isNotNull();
    assertThat(wb.getEncapsulatedLogic().getExpression()).isNotNull();
    assertThat(wb.getEncapsulatedLogic().getExpression().getId().getValue()).isEqualTo(EXPRESSION_UUID);
    verify(hasComponentWidthsConsumer).accept(eq(EXPRESSION_UUID), hasComponentWidthsCaptor.capture());
    final HasComponentWidths hasComponentWidths0 = hasComponentWidthsCaptor.getValue();
    assertThat(hasComponentWidths0).isNotNull();
    assertThat(hasComponentWidths0).isEqualTo(wb.getEncapsulatedLogic().getExpression());
    verify(hasComponentWidthsConsumer).accept(eq(FUNCTION_DEFINITION_UUID), hasComponentWidthsCaptor.capture());
    final HasComponentWidths hasComponentWidths1 = hasComponentWidthsCaptor.getValue();
    assertThat(hasComponentWidths1).isNotNull();
    assertThat(hasComponentWidths1).isEqualTo(wb.getEncapsulatedLogic());
}
Also used : NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) TFunctionDefinition(org.kie.dmn.model.v1_2.TFunctionDefinition) View(org.kie.workbench.common.stunner.core.graph.content.view.View) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) TBusinessKnowledgeModel(org.kie.dmn.model.v1_2.TBusinessKnowledgeModel) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TBusinessKnowledgeModel(org.kie.dmn.model.v1_2.TBusinessKnowledgeModel) Test(org.junit.Test)

Aggregations

TFunctionDefinition (org.kie.dmn.model.v1_2.TFunctionDefinition)3 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)3 Test (org.junit.Test)2 TInformationItem (org.kie.dmn.model.v1_2.TInformationItem)2 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)2 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)2 QName (javax.xml.namespace.QName)1 TBusinessKnowledgeModel (org.kie.dmn.model.v1_2.TBusinessKnowledgeModel)1 TContext (org.kie.dmn.model.v1_2.TContext)1 TContextEntry (org.kie.dmn.model.v1_2.TContextEntry)1 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)1 Context (org.kie.workbench.common.dmn.api.definition.model.Context)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)1 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)1