use of org.kie.dmn.model.v1_1.TBusinessKnowledgeModel 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());
}
Aggregations