Search in sources :

Example 11 with TInformationItem

use of org.kie.dmn.model.v1_2.TInformationItem in project kie-wb-common by kiegroup.

the class RelationPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    final org.kie.dmn.model.api.Relation dmn = new TRelation();
    final org.kie.dmn.model.api.InformationItem informationItem = new TInformationItem();
    final org.kie.dmn.model.api.List list = new TList();
    final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
    literalExpression.setId(EXPRESSION_UUID);
    list.getExpression().add(literalExpression);
    dmn.setId(RELATION_UUID);
    dmn.setDescription(RELATION_DESCRIPTION);
    dmn.setTypeRef(new QName(RELATION_QNAME_LOCALPART));
    dmn.getColumn().add(informationItem);
    dmn.getRow().add(list);
    final Relation wb = RelationPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
    assertThat(wb).isNotNull();
    assertThat(wb.getId()).isNotNull();
    assertThat(wb.getId().getValue()).isEqualTo(RELATION_UUID);
    assertThat(wb.getDescription()).isNotNull();
    assertThat(wb.getDescription().getValue()).isEqualTo(RELATION_DESCRIPTION);
    assertThat(wb.getTypeRef()).isNotNull();
    assertThat(wb.getTypeRef().getLocalPart()).isEqualTo(RELATION_QNAME_LOCALPART);
    assertThat(wb.getColumn()).isNotNull();
    assertThat(wb.getColumn().size()).isEqualTo(1);
    assertThat(wb.getColumn().get(0)).isNotNull();
    assertThat(wb.getRow()).isNotNull();
    assertThat(wb.getRow().size()).isEqualTo(1);
    assertThat(wb.getRow().get(0)).isNotNull();
    assertThat(wb.getRow().get(0).getExpression()).isNotNull();
    assertThat(wb.getRow().get(0).getExpression().size()).isEqualTo(1);
    assertThat(wb.getRow().get(0).getExpression().get(0).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.getRow().get(0).getExpression().get(0).getExpression());
}
Also used : QName(javax.xml.namespace.QName) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) TList(org.kie.dmn.model.v1_2.TList) TRelation(org.kie.dmn.model.v1_2.TRelation) TRelation(org.kie.dmn.model.v1_2.TRelation) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) Test(org.junit.Test)

Example 12 with TInformationItem

use of org.kie.dmn.model.v1_2.TInformationItem in project kie-wb-common by kiegroup.

the class BindingPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    final org.kie.dmn.model.api.Binding dmn = new TBinding();
    final org.kie.dmn.model.api.InformationItem informationItem = new TInformationItem();
    dmn.setParameter(informationItem);
    final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
    literalExpression.setId(EXPRESSION_UUID);
    dmn.setExpression(literalExpression);
    final Binding wb = BindingPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
    assertThat(wb).isNotNull();
    assertThat(wb.getParameter()).isNotNull();
    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 : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) TBinding(org.kie.dmn.model.v1_2.TBinding) TBinding(org.kie.dmn.model.v1_2.TBinding) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) Test(org.junit.Test)

Example 13 with TInformationItem

use of org.kie.dmn.model.v1_2.TInformationItem in project kie-wb-common by kiegroup.

the class ContextEntryPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    final org.kie.dmn.model.api.ContextEntry dmn = new TContextEntry();
    final org.kie.dmn.model.api.InformationItem informationItem = new TInformationItem();
    dmn.setVariable(informationItem);
    final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
    literalExpression.setId(EXPRESSION_UUID);
    dmn.setExpression(literalExpression);
    final ContextEntry wb = ContextEntryPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
    assertThat(wb).isNotNull();
    assertThat(wb.getVariable()).isNotNull();
    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 : TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TContextEntry(org.kie.dmn.model.v1_2.TContextEntry) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) TContextEntry(org.kie.dmn.model.v1_2.TContextEntry) Test(org.junit.Test)

Example 14 with TInformationItem

use of org.kie.dmn.model.v1_2.TInformationItem in project kie-wb-common by kiegroup.

the class DMNMarshallerImportsHelperStandaloneImplTest method testGetDrgElementsWithNamespace.

@Test
public void testGetDrgElementsWithNamespace() {
    final Definitions definitions = mock(Definitions.class);
    final Import anImport = mock(Import.class);
    final TDecision drgElement1 = new TDecision();
    final TInputData drgElement2 = new TInputData();
    final TDecisionService drgElement3 = new TDecisionService();
    final InformationItem informationItem1 = new TInformationItem();
    final InformationItem informationItem2 = new TInformationItem();
    final InformationItem informationItem3 = new TInformationItem();
    final List<DRGElement> drgElements = asList(drgElement1, drgElement2, drgElement3);
    final String namespace = "http://github.com/kiegroup/_something";
    final String builtInTypeNumber = BuiltInType.NUMBER.getName();
    when(anImport.getName()).thenReturn("model");
    when(anImport.getNamespace()).thenReturn(namespace);
    informationItem1.setTypeRef(new QName(XMLConstants.NULL_NS_URI, "tUUID", XMLConstants.DEFAULT_NS_PREFIX));
    informationItem2.setTypeRef(new QName(XMLConstants.NULL_NS_URI, "tAge", XMLConstants.DEFAULT_NS_PREFIX));
    informationItem3.setTypeRef(new QName(XMLConstants.NULL_NS_URI, builtInTypeNumber, XMLConstants.DEFAULT_NS_PREFIX));
    drgElement1.setId("0000-1111");
    drgElement2.setId("2222-3333");
    drgElement3.setId("4444-5555");
    drgElement1.setName("Decision");
    drgElement2.setName("Input Data");
    drgElement3.setName("Decision Service");
    drgElement1.setVariable(informationItem1);
    drgElement2.setVariable(informationItem2);
    drgElement3.setVariable(informationItem3);
    when(definitions.getDrgElement()).thenReturn(drgElements);
    final List<DRGElement> elements = helper.getDrgElementsWithNamespace(definitions, anImport);
    assertEquals(3, elements.size());
    final TDecision element1 = (TDecision) elements.get(0);
    assertEquals("0000-1111", element1.getId());
    assertEquals("model.Decision", element1.getName());
    assertEquals("model.tUUID", element1.getVariable().getTypeRef().getLocalPart());
    assertEquals(namespace, getNamespace(element1));
    final TInputData element2 = (TInputData) elements.get(1);
    assertEquals("2222-3333", element2.getId());
    assertEquals("model.Input Data", element2.getName());
    assertEquals("model.tAge", element2.getVariable().getTypeRef().getLocalPart());
    assertEquals(namespace, getNamespace(element2));
    final TDecisionService element3 = (TDecisionService) elements.get(2);
    assertEquals("4444-5555", element3.getId());
    assertEquals("model.Decision Service", element3.getName());
    assertEquals(builtInTypeNumber, element3.getVariable().getTypeRef().getLocalPart());
    assertEquals(namespace, getNamespace(element3));
}
Also used : TInputData(org.kie.dmn.model.v1_2.TInputData) Import(org.kie.dmn.model.api.Import) TDecisionService(org.kie.dmn.model.v1_2.TDecisionService) QName(javax.xml.namespace.QName) Definitions(org.kie.dmn.model.api.Definitions) TDecision(org.kie.dmn.model.v1_2.TDecision) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) InformationItem(org.kie.dmn.model.api.InformationItem) DRGElement(org.kie.dmn.model.api.DRGElement) Test(org.junit.Test)

Example 15 with TInformationItem

use of org.kie.dmn.model.v1_2.TInformationItem 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

TInformationItem (org.kie.dmn.model.v1_2.TInformationItem)14 Test (org.junit.Test)9 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)7 QName (javax.xml.namespace.QName)5 InformationItem (org.kie.dmn.model.api.InformationItem)5 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)4 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)4 TDecision (org.kie.dmn.model.v1_2.TDecision)3 TInputData (org.kie.dmn.model.v1_2.TInputData)3 DRGElement (org.kie.dmn.model.api.DRGElement)2 TContextEntry (org.kie.dmn.model.v1_2.TContextEntry)2 TDecisionService (org.kie.dmn.model.v1_2.TDecisionService)2 TFunctionDefinition (org.kie.dmn.model.v1_2.TFunctionDefinition)2 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)2 LinkedHashSet (java.util.LinkedHashSet)1 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)1 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)1 DecisionServiceNode (org.kie.dmn.api.core.ast.DecisionServiceNode)1