Search in sources :

Example 6 with MagnetConnection

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

the class WiresConnectorViewTest method testConnectMagnetsByLocation.

@Test
public void testConnectMagnetsByLocation() {
    // Mocks for head stuff.
    IControlHandleList headControlHandleList = new ControlHandleList(mock(Shape.class));
    WiresMagnet headMagnet1 = mock(WiresMagnet.class);
    when(headMagnet1.getX()).thenReturn(10d);
    when(headMagnet1.getY()).thenReturn(20d);
    when(headMagnet1.getIndex()).thenReturn(0);
    IPrimitive ch1 = mock(IPrimitive.class);
    when(ch1.getLocation()).thenReturn(new Point2D(10d, 20d));
    when(headMagnet1.getControl()).thenReturn(ch1);
    WiresMagnet headMagnet2 = mock(WiresMagnet.class);
    when(headMagnet2.getX()).thenReturn(100d);
    when(headMagnet2.getY()).thenReturn(200d);
    IPrimitive ch2 = mock(IPrimitive.class);
    when(ch2.getLocation()).thenReturn(new Point2D(100d, 200d));
    when(headMagnet2.getControl()).thenReturn(ch2);
    headControlHandleList.add(headMagnet1);
    headControlHandleList.add(headMagnet2);
    MagnetManager.Magnets headMagnets = mock(MagnetManager.Magnets.class);
    when(headMagnets.getMagnets()).thenReturn(headControlHandleList);
    Point2D headAbs = new Point2D(0, 0);
    MagnetConnection headConnection = MagnetConnection.Builder.at(10, 20);
    // Mocks for head tail.
    IControlHandleList tailControlHandleList = new ControlHandleList(mock(Shape.class));
    WiresMagnet tailMagnet1 = mock(WiresMagnet.class);
    when(tailMagnet1.getX()).thenReturn(10d);
    when(tailMagnet1.getY()).thenReturn(20d);
    IPrimitive th1 = mock(IPrimitive.class);
    when(th1.getLocation()).thenReturn(new Point2D(10d, 20d));
    when(tailMagnet1.getControl()).thenReturn(th1);
    WiresMagnet tailMagnet2 = mock(WiresMagnet.class);
    when(tailMagnet2.getX()).thenReturn(100d);
    when(tailMagnet2.getY()).thenReturn(200d);
    when(tailMagnet2.getIndex()).thenReturn(2);
    IPrimitive th2 = mock(IPrimitive.class);
    when(th2.getLocation()).thenReturn(new Point2D(100d, 200d));
    when(tailMagnet2.getControl()).thenReturn(th2);
    tailControlHandleList.add(tailMagnet1);
    tailControlHandleList.add(tailMagnet2);
    MagnetManager.Magnets tailMagnets = mock(MagnetManager.Magnets.class);
    when(tailMagnets.getMagnets()).thenReturn(tailControlHandleList);
    Point2D tailAbs = new Point2D(0, 0);
    MagnetConnection tailConnection = MagnetConnection.Builder.at(100, 200);
    // Mocks both source/target actual connections.
    WiresConnection headWiresConnection = mock(WiresConnection.class);
    WiresConnection tailWiresConnection = mock(WiresConnection.class);
    tested.setHeadConnection(headWiresConnection);
    tested.setTailConnection(tailWiresConnection);
    // Perform the connection.
    tested.connect(headMagnets, headAbs, headConnection, tailMagnets, tailAbs, tailConnection);
    // Verify it sets the right magnets (closest to the location):
    verify(headWiresConnection, never()).setXOffset(anyDouble());
    verify(headWiresConnection, never()).setYOffset(anyDouble());
    verify(headWiresConnection, times(1)).setAutoConnection(eq(false));
    verify(headWiresConnection, times(1)).setMagnet(eq(headMagnet1));
    verify(tailWiresConnection, times(1)).setXOffset(eq(0d));
    verify(tailWiresConnection, times(1)).setYOffset(eq(0d));
    verify(tailWiresConnection, times(1)).setAutoConnection(eq(false));
    verify(tailWiresConnection, times(1)).setMagnet(eq(tailMagnet2));
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Shape(com.ait.lienzo.client.core.shape.Shape) Point2D(com.ait.lienzo.client.core.types.Point2D) WiresConnection(com.ait.lienzo.client.core.shape.wires.WiresConnection) MagnetManager(com.ait.lienzo.client.core.shape.wires.MagnetManager) IControlHandleList(com.ait.lienzo.client.core.shape.wires.IControlHandleList) ControlHandleList(com.ait.lienzo.client.core.shape.wires.ControlHandleList) IPrimitive(com.ait.lienzo.client.core.shape.IPrimitive) WiresMagnet(com.ait.lienzo.client.core.shape.wires.WiresMagnet) IControlHandleList(com.ait.lienzo.client.core.shape.wires.IControlHandleList) Test(org.junit.Test)

Example 7 with MagnetConnection

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

the class SetConnectionSourceNodeCommandTest method testExecuteOnlyConnectionsHasBeenChanged.

@Test
@SuppressWarnings("unchecked")
public void testExecuteOnlyConnectionsHasBeenChanged() {
    when(edge.getSourceNode()).thenReturn(node);
    MagnetConnection connection = MagnetConnection.Builder.at(MAGNETX, MAGNETY);
    tested = new SetConnectionSourceNodeCommand(node, edge, connection);
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    assertEquals(CommandResult.Type.INFO, result.getType());
    verify(ruleManager, never()).evaluate(eq(ruleSet), any(RuleEvaluationContext.class));
    verify(edgeContent, times(1)).setSourceConnection(eq(connection));
    verify(edgeContent, never()).setTargetConnection(any(Connection.class));
    assertEquals(sourceMagnet.get(), tested.lastConnection);
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) 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) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 8 with MagnetConnection

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

the class WiresConnectorViewTest method testConnectMagnets.

@Test
public void testConnectMagnets() {
    MagnetManager.Magnets headMagnets = mock(MagnetManager.Magnets.class);
    WiresMagnet headMagnet = mock(WiresMagnet.class);
    when(headMagnets.getMagnet(eq(3))).thenReturn(headMagnet);
    when(headMagnet.getIndex()).thenReturn(3);
    Point2D headPoint = new Point2D(10, 20);
    MagnetConnection headConnection = new MagnetConnection.Builder().atX(10).atY(20).magnet(3).build();
    MagnetManager.Magnets tailMagnets = mock(MagnetManager.Magnets.class);
    WiresMagnet tailMagnet = mock(WiresMagnet.class);
    when(tailMagnets.getMagnet(eq(7))).thenReturn(tailMagnet);
    when(tailMagnet.getIndex()).thenReturn(7);
    Point2D tailPoint = new Point2D(100, 200);
    MagnetConnection tailConnection = new MagnetConnection.Builder().atX(100).atY(200).magnet(7).auto(true).build();
    WiresConnection headWiresConnection = mock(WiresConnection.class);
    WiresConnection tailWiresConnection = mock(WiresConnection.class);
    tested.setHeadConnection(headWiresConnection);
    tested.setTailConnection(tailWiresConnection);
    tested.connect(headMagnets, headPoint, headConnection, tailMagnets, tailPoint, tailConnection);
    verify(headWiresConnection, times(1)).setXOffset(eq(0d));
    verify(headWiresConnection, times(1)).setYOffset(eq(0d));
    verify(headWiresConnection, times(1)).setAutoConnection(eq(false));
    verify(headWiresConnection, times(1)).setMagnet(eq(headMagnet));
    verify(tailWiresConnection, times(1)).setXOffset(eq(0d));
    verify(tailWiresConnection, times(1)).setYOffset(eq(0d));
    verify(tailWiresConnection, times(1)).setAutoConnection(eq(true));
    verify(tailWiresConnection, times(1)).setMagnet(eq(tailMagnet));
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) Point2D(com.ait.lienzo.client.core.types.Point2D) WiresConnection(com.ait.lienzo.client.core.shape.wires.WiresConnection) MagnetManager(com.ait.lienzo.client.core.shape.wires.MagnetManager) WiresMagnet(com.ait.lienzo.client.core.shape.wires.WiresMagnet) Test(org.junit.Test)

Aggregations

MagnetConnection (org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection)8 Test (org.junit.Test)6 WiresConnection (com.ait.lienzo.client.core.shape.wires.WiresConnection)3 WiresMagnet (com.ait.lienzo.client.core.shape.wires.WiresMagnet)3 MagnetManager (com.ait.lienzo.client.core.shape.wires.MagnetManager)2 Point2D (com.ait.lienzo.client.core.types.Point2D)2 TestingGraphUtils.verifyConnection (org.kie.workbench.common.stunner.core.TestingGraphUtils.verifyConnection)2 Connection (org.kie.workbench.common.stunner.core.graph.content.view.Connection)2 RuleEvaluationContext (org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext)2 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)2 IPrimitive (com.ait.lienzo.client.core.shape.IPrimitive)1 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)1 Shape (com.ait.lienzo.client.core.shape.Shape)1 ControlHandleList (com.ait.lienzo.client.core.shape.wires.ControlHandleList)1 IControlHandleList (com.ait.lienzo.client.core.shape.wires.IControlHandleList)1 OptionalInt (java.util.OptionalInt)1 WiresConnectorView (org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView)1 WiresShapeView (org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView)1 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)1 DragProxyCallback (org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback)1