Search in sources :

Example 86 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class DecisionNavigatorItemFactoryTest method testMakeRootWhenDMNDiagramElementIsNotDRG.

@Test
public void testMakeRootWhenDMNDiagramElementIsNotDRG() {
    final Diagram stunnerDiagram = mock(Diagram.class);
    final Graph graph = mock(Graph.class);
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final String drdName = "DRD 1";
    final String dmnDiagramId = "0000";
    final DMNDiagramElement dmnDiagramElement = new DMNDiagramElement(new Id(dmnDiagramId), new Name(drdName));
    final DMNDiagramTuple diagramTuple = new DMNDiagramTuple(stunnerDiagram, dmnDiagramElement);
    when(stunnerDiagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(singletonList(node));
    when(node.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(new DMNDiagram());
    when(baseItemFactory.getLabel(node)).thenReturn("diagram-name");
    final DecisionNavigatorItem decisionNavigatorItem = factory.makeRoot(diagramTuple);
    assertEquals(drdName, decisionNavigatorItem.getLabel());
    assertEquals(dmnDiagramId, decisionNavigatorItem.getUUID());
    assertEquals(ROOT, decisionNavigatorItem.getType());
    assertNull(decisionNavigatorItem.getParentUUID());
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DecisionNavigatorItem(org.kie.workbench.common.dmn.client.docks.navigator.DecisionNavigatorItem) DMNDiagramTuple(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramTuple) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 87 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class DecisionNavigatorItemFactoryTest method testGetOnRemove.

@Test
public void testGetOnRemove() {
    final DMNDiagramElement drgDiagramElement = new DMNDiagramElement();
    final DMNDiagramElement drd1DiagramElement = new DMNDiagramElement();
    final DMNDiagramElement drd2DiagramElement = new DMNDiagramElement();
    final DMNDiagramElement drgElement = mock(DMNDiagramElement.class);
    final Graph drgGraph = mock(Graph.class);
    final Diagram drgDiagram = mock(Diagram.class);
    final DecisionNavigatorItem item = mock(DecisionNavigatorItem.class);
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final DMNDiagram dmnDiagram = mock(DMNDiagram.class);
    final Definitions dmnDefinitions = mock(Definitions.class);
    final List<DMNDiagramElement> diagramElements = new ArrayList<>(asList(drgDiagramElement, drd1DiagramElement, drd2DiagramElement));
    final Iterable nodes = singletonList(node);
    when(dmnDiagramsSession.getDRGDiagramElement()).thenReturn(drgElement);
    when(dmnDiagramsSession.getDRGDiagram()).thenReturn(drgDiagram);
    when(drgDiagram.getGraph()).thenReturn(drgGraph);
    when(drgGraph.nodes()).thenReturn(nodes);
    when(node.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(dmnDiagram);
    when(dmnDiagram.getDefinitions()).thenReturn(dmnDefinitions);
    when(dmnDefinitions.getDiagramElements()).thenReturn(diagramElements);
    factory.getOnRemove(drd1DiagramElement).accept(item);
    verify(dmnDiagramsSession).remove(drd1DiagramElement);
    verify(selectedEvent).fire(diagramSelectedArgumentCaptor.capture());
    assertEquals(drgElement, diagramSelectedArgumentCaptor.getValue().getDiagramElement());
    assertEquals(2, diagramElements.size());
    assertTrue(diagramElements.contains(drgDiagramElement));
    assertFalse(diagramElements.contains(drd1DiagramElement));
    assertTrue(diagramElements.contains(drd2DiagramElement));
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DecisionNavigatorItem(org.kie.workbench.common.dmn.client.docks.navigator.DecisionNavigatorItem) Node(org.kie.workbench.common.stunner.core.graph.Node) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) ArrayList(java.util.ArrayList) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Test(org.junit.Test)

Example 88 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class DecisionNavigatorItemFactoryTest method testMakeRootWhenDMNDiagramElementIsDRG.

@Test
public void testMakeRootWhenDMNDiagramElementIsDRG() {
    final Diagram stunnerDiagram = mock(Diagram.class);
    final Graph graph = mock(Graph.class);
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final String dmnDiagramId = "0000";
    final String dmnModelName = "diagram-name";
    final DMNDiagramElement dmnDiagramElement = new DMNDiagramElement(new Id(dmnDiagramId), new Name("DRG"));
    final DMNDiagramTuple diagramTuple = new DMNDiagramTuple(stunnerDiagram, dmnDiagramElement);
    when(stunnerDiagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(singletonList(node));
    when(node.getContent()).thenReturn(definition);
    when(definition.getDefinition()).thenReturn(new DMNDiagram());
    when(baseItemFactory.getLabel(node)).thenReturn(dmnModelName);
    final DecisionNavigatorItem decisionNavigatorItem = factory.makeRoot(diagramTuple);
    assertEquals(dmnModelName, decisionNavigatorItem.getLabel());
    assertEquals(dmnDiagramId, decisionNavigatorItem.getUUID());
    assertEquals(ROOT, decisionNavigatorItem.getType());
    assertNull(decisionNavigatorItem.getParentUUID());
}
Also used : DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DecisionNavigatorItem(org.kie.workbench.common.dmn.client.docks.navigator.DecisionNavigatorItem) DMNDiagramTuple(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramTuple) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 89 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class DMNElementsSynchronizerTest method testSynchronizeFromNode.

@Test
public void testSynchronizeFromNode() {
    final Node node = mock(Node.class);
    final Optional<Node> optional = Optional.of(node);
    final Definition definition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    doNothing().when(synchronizer).synchronizeElementsFrom(drgElement);
    when(definition.getDefinition()).thenReturn(drgElement);
    when(node.getContent()).thenReturn(definition);
    synchronizer.synchronizeFromNode(optional);
    verify(synchronizer).synchronizeElementsFrom(drgElement);
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Example 90 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class DMNElementsSynchronizerTest method testGetDRGElementFromContentDefinition.

@Test
public void testGetDRGElementFromContentDefinition() {
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final DRGElement drgElement = mock(DRGElement.class);
    when(definition.getDefinition()).thenReturn(drgElement);
    when(node.getContent()).thenReturn(definition);
    final DRGElement actual = synchronizer.getDRGElementFromContentDefinition(node);
    assertEquals(drgElement, actual);
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Test(org.junit.Test)

Aggregations

Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)111 Node (org.kie.workbench.common.stunner.core.graph.Node)61 Test (org.junit.Test)46 Element (org.kie.workbench.common.stunner.core.graph.Element)31 Edge (org.kie.workbench.common.stunner.core.graph.Edge)25 Graph (org.kie.workbench.common.stunner.core.graph.Graph)20 ArrayList (java.util.ArrayList)16 Optional (java.util.Optional)14 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)14 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)14 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)14 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)11 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)10 List (java.util.List)9 Before (org.junit.Before)9 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)9 HasContentDefinitionId (org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId)9 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)9 Stream (java.util.stream.Stream)8