Search in sources :

Example 51 with DRGElement

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

the class DMNIncludedNodeFactoryTest method testMakeDMNIncludedModel.

@Test
public void testMakeDMNIncludedModel() {
    final DMNIncludedNodeFactory factory = mock(DMNIncludedNodeFactory.class);
    final String path = "path";
    final IncludedModel includedModel = mock(IncludedModel.class);
    final DRGElement drgElement = mock(DRGElement.class);
    final DRGElement elementWithNamespace = mock(DRGElement.class);
    doCallRealMethod().when(factory).makeDMNIncludeNode(path, includedModel, drgElement);
    when(factory.drgElementWithNamespace(drgElement, includedModel)).thenReturn(elementWithNamespace);
    final DMNIncludedNode includedNode = factory.makeDMNIncludeNode(path, includedModel, drgElement);
    verify(factory).drgElementWithNamespace(drgElement, includedModel);
    assertEquals(path, includedNode.getFileName());
    assertEquals(elementWithNamespace, includedNode.getDrgElement());
}
Also used : DMNIncludedNode(org.kie.workbench.common.dmn.api.editors.included.DMNIncludedNode) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 52 with DRGElement

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

the class DMNIncludedNodeFactoryTest method testDrgElementWithNamespace.

@Test
public void testDrgElementWithNamespace() {
    final DRGElement drgElement = mock(DRGElement.class, withSettings().extraInterfaces(HasVariable.class));
    final IncludedModel includedModel = mock(IncludedModel.class);
    final DMNIncludedNodeFactory factory = mock(DMNIncludedNodeFactory.class);
    final Id elementId = mock(Id.class);
    final String theId = "theId";
    final String theName = "theName";
    final String tType = "tType";
    final String namespaceUri = "namespaceUri";
    final String prefix = "prefix";
    final String modelName = "Model Name";
    final Name elementName = mock(Name.class);
    final IsInformationItem informationItem = mock(IsInformationItem.class);
    final QName qName = mock(QName.class);
    final Name createdName = mock(Name.class);
    final QName typeRef = mock(QName.class);
    when(includedModel.getModelName()).thenReturn(modelName);
    when(elementId.getValue()).thenReturn(theId);
    when(elementName.getValue()).thenReturn(theName);
    when(drgElement.getName()).thenReturn(elementName);
    when(drgElement.getId()).thenReturn(elementId);
    when(((HasVariable) drgElement).getVariable()).thenReturn(informationItem);
    when(qName.getLocalPart()).thenReturn(tType);
    when(informationItem.getTypeRef()).thenReturn(qName);
    when(qName.getPrefix()).thenReturn(prefix);
    when(qName.getNamespaceURI()).thenReturn(namespaceUri);
    when(factory.createName(drgElement, modelName)).thenReturn(createdName);
    when(factory.createTypeRef(modelName, qName)).thenReturn(typeRef);
    doCallRealMethod().when(factory).drgElementWithNamespace(drgElement, includedModel);
    factory.drgElementWithNamespace(drgElement, includedModel);
    verify(drgElement).setName(createdName);
    verify(drgElement).setAllowOnlyVisualChange(true);
    verify(factory).setVariable((HasVariable) drgElement, informationItem, typeRef);
}
Also used : HasVariable(org.kie.workbench.common.dmn.api.definition.HasVariable) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) IsInformationItem(org.kie.workbench.common.dmn.api.definition.model.IsInformationItem) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 53 with DRGElement

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

the class DMNMarshallerTest method testWithIncludedModelsWhenNodeParentIsDMNDiagram.

@Test
public void testWithIncludedModelsWhenNodeParentIsDMNDiagram() {
    final DMNMarshaller dmnMarshaller = spy(new DMNMarshaller());
    final Node node = mock(Node.class);
    final Definition nodeDefinition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    final Definitions definitionsStunnerPojo = mock(Definitions.class);
    final Import import1 = mock(Import.class);
    final Import import2 = mock(Import.class);
    final List<Import> diagramImports = new ArrayList<>(asList(import1, import2));
    final DMNDiagram nodeDiagram = mock(DMNDiagram.class);
    final Definitions nodeDiagramDefinitions = mock(Definitions.class);
    final List<Import> nodeDiagramImports = new ArrayList<>();
    when(node.getContent()).thenReturn(nodeDefinition);
    when(nodeDefinition.getDefinition()).thenReturn(drgElement);
    when(definitionsStunnerPojo.getImport()).thenReturn(diagramImports);
    when(drgElement.getParent()).thenReturn(nodeDiagram);
    when(nodeDiagram.getDefinitions()).thenReturn(nodeDiagramDefinitions);
    when(nodeDiagramDefinitions.getImport()).thenReturn(nodeDiagramImports);
    dmnMarshaller.withIncludedModels(node, definitionsStunnerPojo);
    assertEquals(2, nodeDiagramImports.size());
    assertTrue(nodeDiagramImports.contains(import1));
    assertTrue(nodeDiagramImports.contains(import2));
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Import(org.kie.workbench.common.dmn.api.definition.model.Import) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ArrayList(java.util.ArrayList) JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 54 with DRGElement

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

the class NodeConnectorTest method testConnectEdgeToNodesWhenDMNDIIsPresent.

@Test
public void testConnectEdgeToNodesWhenDMNDIIsPresent() {
    final JSIDMNEdge existingEdge = mock(JSIDMNEdge.class);
    final Definition definition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    final String id = "789";
    final String contentDefinitionId = "123";
    final List<NodeEntry> list = singletonList(nodeEntry);
    when(jsiDMNElementReference.getHref()).thenReturn("#123");
    when(jsiDMNElement.getId()).thenReturn(id);
    when(existingEdge.getDmnElementRef()).thenReturn(new QName("", id));
    when(definition.getDefinition()).thenReturn(drgElement);
    when(currentNode.getContent()).thenReturn(definition);
    when(drgElement.getContentDefinitionId()).thenReturn(contentDefinitionId);
    doReturn(true).when(nodeConnector).isEdgeConnectedWithNode(eq(existingEdge), eq(currentNode), eq(list));
    doReturn(Optional.of(requiredNode)).when(nodeConnector).getSourceNode(eq(existingEdge), any());
    doNothing().when(nodeConnector).connectWbEdge(any(), any(), any(), any(), any(), any());
    entriesById.put(contentDefinitionId, list);
    edges.add(existingEdge);
    isDMNDIPresent = true;
    nodeConnector.connectEdgeToNodes(connectorTypeId, jsiDMNElement, jsiDMNElementReference, entriesById, diagramId, edges, isDMNDIPresent, currentNode);
    verify(nodeConnector).connectWbEdge(eq(connectorTypeId), eq(diagramId), eq(currentNode), eq(requiredNode), eq(existingEdge), eq("789"));
    verify(nodeConnector).isEdgeConnectedWithNode(eq(existingEdge), eq(currentNode), eq(list));
}
Also used : QName(javax.xml.namespace.QName) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 55 with DRGElement

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

the class NodeConnectorTest method testConnectEdgeToNodesWhenDMNDIIsPresentAndNodeIsNotConnectedWithEdge.

@Test
public void testConnectEdgeToNodesWhenDMNDIIsPresentAndNodeIsNotConnectedWithEdge() {
    final JSIDMNEdge existingEdge = mock(JSIDMNEdge.class);
    final Definition definition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    final String id = "789";
    final String contentDefinitionId = "123";
    final List<NodeEntry> list = singletonList(nodeEntry);
    when(jsiDMNElementReference.getHref()).thenReturn("#123");
    when(jsiDMNElement.getId()).thenReturn(id);
    when(existingEdge.getDmnElementRef()).thenReturn(new QName("", id));
    when(definition.getDefinition()).thenReturn(drgElement);
    when(currentNode.getContent()).thenReturn(definition);
    when(drgElement.getContentDefinitionId()).thenReturn(contentDefinitionId);
    doReturn(false).when(nodeConnector).isEdgeConnectedWithNode(eq(existingEdge), eq(currentNode), eq(list));
    doReturn(Optional.of(requiredNode)).when(nodeConnector).getSourceNode(eq(existingEdge), any());
    doNothing().when(nodeConnector).connectWbEdge(any(), any(), any(), any(), any(), any());
    entriesById.put(contentDefinitionId, list);
    edges.add(existingEdge);
    isDMNDIPresent = true;
    nodeConnector.connectEdgeToNodes(connectorTypeId, jsiDMNElement, jsiDMNElementReference, entriesById, diagramId, edges, isDMNDIPresent, currentNode);
    verify(nodeConnector, never()).connectWbEdge(eq(connectorTypeId), eq(diagramId), eq(currentNode), eq(requiredNode), eq(existingEdge), eq("789"));
    verify(nodeConnector).isEdgeConnectedWithNode(eq(existingEdge), eq(currentNode), eq(list));
}
Also used : QName(javax.xml.namespace.QName) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Aggregations

DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)72 Test (org.junit.Test)45 Node (org.kie.workbench.common.stunner.core.graph.Node)27 ArrayList (java.util.ArrayList)25 Edge (org.kie.workbench.common.stunner.core.graph.Edge)17 View (org.kie.workbench.common.stunner.core.graph.content.view.View)17 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)16 List (java.util.List)15 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)15 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)15 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)15 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)14 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)13 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)10 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)9 Import (org.kie.workbench.common.dmn.api.definition.model.Import)9 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)8 KnowledgeRequirement (org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement)7 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)7 Optional (java.util.Optional)6