use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class ObserverBuilderControlTest method testUpdateEncapsulatedLogicFromDefinition.
@Test
public void testUpdateEncapsulatedLogicFromDefinition() {
final Element element = mock(Element.class);
final View elementContent = mock(View.class);
final BusinessKnowledgeModel newBusinessKnowledgeModel = mock(BusinessKnowledgeModel.class);
final BusinessKnowledgeModel businessKnowledgeModel = mock(BusinessKnowledgeModel.class);
final FunctionDefinition functionDefinition = mock(FunctionDefinition.class);
when(element.getContent()).thenReturn(elementContent);
when(elementContent.getDefinition()).thenReturn(newBusinessKnowledgeModel);
when(businessKnowledgeModel.getEncapsulatedLogic()).thenReturn(functionDefinition);
when(newBusinessKnowledgeModel.getName()).thenReturn(new Name());
when(businessKnowledgeModel.getName()).thenReturn(new Name());
when(newBusinessKnowledgeModel.getId()).thenReturn(new Id());
when(businessKnowledgeModel.getId()).thenReturn(new Id());
observerBuilderControl.updateElementFromDefinition(element, businessKnowledgeModel);
verify(newBusinessKnowledgeModel).setEncapsulatedLogic(functionDefinition);
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition in project kie-wb-common by kiegroup.
the class BusinessKnowledgeModelConverterTest method testDMNFromWB.
@Test
public void testDMNFromWB() {
final BusinessKnowledgeModel wb = new BusinessKnowledgeModel();
final LiteralExpression literalExpression = new LiteralExpression();
final InformationItemPrimary informationItem = new InformationItemPrimary();
final FunctionDefinition functionDefinition = new FunctionDefinition();
literalExpression.getComponentWidths().set(0, 200.0);
literalExpression.getId().setValue(EXPRESSION_UUID);
functionDefinition.getComponentWidths().set(0, 200.0);
functionDefinition.setExpression(literalExpression);
functionDefinition.getId().setValue(FUNCTION_DEFINITION_UUID);
wb.getId().setValue(DECISION_UUID);
wb.getName().setValue(DECISION_NAME);
wb.getDescription().setValue(DECISION_DESCRIPTION);
wb.setVariable(informationItem);
wb.setEncapsulatedLogic(functionDefinition);
final Node<View<BusinessKnowledgeModel>, ?> node = new NodeImpl<>(UUID.uuid());
final View<BusinessKnowledgeModel> view = new ViewImpl<>(wb, Bounds.create());
node.setContent(view);
final org.kie.dmn.model.api.BusinessKnowledgeModel dmn = converter.dmnFromNode(node, componentWidthsConsumer);
assertThat(dmn).isNotNull();
assertThat(dmn.getId()).isNotNull();
assertThat(dmn.getId()).isEqualTo(DECISION_UUID);
assertThat(dmn.getName()).isNotNull();
assertThat(dmn.getName()).isEqualTo(DECISION_NAME);
assertThat(dmn.getDescription()).isNotNull();
assertThat(dmn.getDescription()).isEqualTo(DECISION_DESCRIPTION);
assertThat(dmn.getVariable()).isNotNull();
assertThat(dmn.getVariable().getName()).isEqualTo(DECISION_NAME);
assertThat(dmn.getEncapsulatedLogic()).isNotNull();
assertThat(dmn.getEncapsulatedLogic().getExpression()).isNotNull();
assertThat(dmn.getEncapsulatedLogic().getExpression().getId()).isEqualTo(EXPRESSION_UUID);
verify(componentWidthsConsumer, times(2)).accept(componentWidthsCaptor.capture());
final List<ComponentWidths> componentWidths = componentWidthsCaptor.getAllValues();
assertThat(componentWidths).isNotNull();
assertThat(componentWidths).hasSize(2);
final ComponentWidths componentWidths0 = componentWidths.get(0);
assertThat(componentWidths0.getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
assertThat(componentWidths0.getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
assertThat(componentWidths0.getWidths().get(0)).isEqualTo(200.0);
final ComponentWidths componentWidths1 = componentWidths.get(1);
assertThat(componentWidths1.getDmnElementRef().getLocalPart()).isEqualTo(FUNCTION_DEFINITION_UUID);
assertThat(componentWidths1.getWidths().size()).isEqualTo(functionDefinition.getRequiredComponentWidthCount());
assertThat(componentWidths1.getWidths().get(0)).isEqualTo(200.0);
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition 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());
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition 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);
}
use of org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition 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);
}
Aggregations