Search in sources :

Example 51 with Edge

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

the class SetChildNodeCommandTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() {
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    assertEquals(CommandResult.Type.INFO, result.getType());
    assertFalse(parent.getOutEdges().isEmpty());
    assertFalse(candidate.getInEdges().isEmpty());
    Edge edge = (Edge) parent.getOutEdges().get(0);
    assertTrue(edge.getContent() instanceof Child);
    assertEquals(parent, edge.getSourceNode());
    assertEquals(candidate, edge.getTargetNode());
    verify(graphIndex, times(1)).addEdge(eq(edge));
    verify(graphIndex, times(0)).addNode(any(Node.class));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) Test(org.junit.Test)

Example 52 with Edge

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

the class SetConnectionTargetNodeCommandTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() {
    final List lastTargetInEdges = mock(List.class);
    final List sourceOutEdges = mock(List.class);
    final List targetInEdges = mock(List.class);
    when(source.getOutEdges()).thenReturn(sourceOutEdges);
    when(lastTargetNode.getInEdges()).thenReturn(lastTargetInEdges);
    when(node.getInEdges()).thenReturn(targetInEdges);
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class);
    verify(ruleManager, times(3)).evaluate(eq(ruleSet), contextCaptor.capture());
    final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues();
    assertEquals(3, contexts.size());
    verifyConnection((GraphConnectionContext) contexts.get(0), edge, source, node);
    verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(1), graph, lastTargetNode, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.DELETE));
    verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(2), graph, node, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.ADD));
    assertEquals(CommandResult.Type.INFO, result.getType());
    verify(lastTargetInEdges, times(1)).remove(eq(edge));
    verify(targetInEdges, times(1)).add(eq(edge));
    verify(edgeContent, times(1)).setTargetConnection(any(Connection.class));
    verify(edge, times(1)).setTargetNode(eq(node));
    verify(targetInEdges, times(0)).remove(any(Edge.class));
    verify(sourceOutEdges, times(0)).add(any(Edge.class));
    verify(graphIndex, times(0)).removeEdge(any(Edge.class));
    verify(graphIndex, times(0)).addEdge(any(Edge.class));
    verify(graphIndex, times(0)).addNode(any(Node.class));
    verify(graphIndex, times(0)).removeNode(any(Node.class));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) TestingGraphUtils.verifyConnection(org.kie.workbench.common.stunner.core.TestingGraphUtils.verifyConnection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) List(java.util.List) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 53 with Edge

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

the class SetParentNodeCommandTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() {
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    assertEquals(CommandResult.Type.INFO, result.getType());
    assertFalse(parent.getOutEdges().isEmpty());
    assertFalse(candidate.getInEdges().isEmpty());
    Edge edge = (Edge) parent.getOutEdges().get(0);
    assertTrue(edge.getContent() instanceof Parent);
    assertEquals(parent, edge.getSourceNode());
    assertEquals(candidate, edge.getTargetNode());
    verify(graphIndex, times(1)).addEdge(eq(edge));
    verify(graphIndex, times(0)).addNode(any(Node.class));
}
Also used : Parent(org.kie.workbench.common.stunner.core.graph.content.relationship.Parent) Node(org.kie.workbench.common.stunner.core.graph.Node) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) ContainmentRuleViolation(org.kie.workbench.common.stunner.core.rule.violations.ContainmentRuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 54 with Edge

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

the class GraphBoundsIndexerImplTest method testGetAreaAt.

@Test
public void testGetAreaAt() {
    Point2D position = GraphUtils.getPosition((View) graphInstanceParent.startNode.getContent());
    double[] size = GraphUtils.getNodeSize((View) graphInstanceParent.startNode.getContent());
    double getAtX = position.getX() + (size[0] / 2);
    double getAtY = position.getY() + (size[1] / 2);
    Node<View<?>, Edge> node = graphBoundsIndexerImpl.getAt(getAtX, getAtY, size[0], size[1], graphInstanceParent.parentNode);
    assertNotNull(node);
    Node<View<?>, Edge> nodeFreePosition = graphBoundsIndexerImpl.getAt(getAtX, getAtY + 400, size[0], size[1], graphInstanceParent.parentNode);
    assertNull(nodeFreePosition);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 55 with Edge

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

the class GraphBoundsIndexerImplTest method testGetAreaAtWithParent.

@Test
public void testGetAreaAtWithParent() {
    Point2D position = GraphUtils.getPosition((View) graphInstanceParent.startNode.getContent());
    double[] size = GraphUtils.getNodeSize((View) graphInstanceParent.startNode.getContent());
    double getAtX = position.getX() + (size[0] / 2);
    double getAtY = position.getY() + (size[1] / 2);
    Node<View<?>, Edge> node = graphBoundsIndexerImpl.getAt(getAtX, getAtY, size[0], size[1], graphInstanceParent.parentNode);
    assertNotNull(node);
    Node<View<?>, Edge> nodeAtFreePosition = graphBoundsIndexerImpl.getAt(getAtX, getAtY + 200, size[0], size[1], graphInstanceParent.parentNode);
    assertNull(nodeAtFreePosition);
}
Also used : Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Aggregations

Edge (org.kie.workbench.common.stunner.core.graph.Edge)154 View (org.kie.workbench.common.stunner.core.graph.content.view.View)101 Node (org.kie.workbench.common.stunner.core.graph.Node)84 Test (org.junit.Test)45 Documentation (org.kie.workbench.common.stunner.bpmn.definition.property.general.Documentation)30 Name (org.kie.workbench.common.stunner.bpmn.definition.property.general.Name)30 Graph (org.kie.workbench.common.stunner.core.graph.Graph)28 BPMNGeneralSet (org.kie.workbench.common.stunner.bpmn.definition.property.general.BPMNGeneralSet)25 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)25 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)19 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)19 List (java.util.List)17 EventPropertyReader (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.properties.EventPropertyReader)16 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)16 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)15 Element (org.kie.workbench.common.stunner.core.graph.Element)14 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)13 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)12 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)12 ArrayList (java.util.ArrayList)11