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());
}
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);
}
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));
}
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));
}
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));
}
Aggregations