use of org.kie.workbench.common.stunner.core.client.command.CanvasCommand in project kie-wb-common by kiegroup.
the class LocationControlImplTest method testMove.
@Test
@SuppressWarnings("unchecked")
public void testMove() throws Exception {
final WiresShapeView wiresShape = mock(WiresShapeView.class);
final WiresShapeView childWiresShape = mock(WiresShapeView.class);
final MagnetManager.Magnets magnets = mock(MagnetManager.Magnets.class);
final WiresMagnet magnet = mock(WiresMagnet.class);
final WiresConnection connection = mock(WiresConnection.class);
final NFastArrayList<WiresConnection> connections = new NFastArrayList<>(connection);
final WiresConnector connector = mock(WiresConnector.class);
final String connectorUUID = UUID.uuid();
final NFastArrayList<WiresShape> children = new NFastArrayList<>(childWiresShape);
final Group connectorGroup = mock(Group.class);
final Edge connectorEdge = mock(Edge.class);
final com.ait.lienzo.client.core.types.Point2D controlPointLienzo = new com.ait.lienzo.client.core.types.Point2D(100, 100);
final Point2DArray controlPointsLienzo = new Point2DArray(controlPointLienzo);
final ViewConnector viewConnector = mock(ViewConnector.class);
Group parentGroup = mock(Group.class);
BoundingBox parentBB = new BoundingBox(0, 0, 200, 200);
MultiPath head = mock(MultiPath.class);
MultiPath tail = mock(MultiPath.class);
when(childWiresShape.getMagnets()).thenReturn(magnets);
when(childWiresShape.getParent()).thenReturn(wiresShape);
when(wiresShape.getGroup()).thenReturn(parentGroup);
when(parentGroup.getBoundingBox()).thenReturn(parentBB);
when(wiresShape.getX()).thenReturn(0d);
when(wiresShape.getY()).thenReturn(0d);
when(magnets.size()).thenReturn(1);
when(magnets.getMagnet(0)).thenReturn(magnet);
when(magnet.getConnectionsSize()).thenReturn(connections.size());
when(magnet.getConnections()).thenReturn(connections);
when(connection.getConnector()).thenReturn(connector);
when(connector.getGroup()).thenReturn(connectorGroup);
when(connectorGroup.uuid()).thenReturn(connectorUUID);
when(connector.getControlPoints()).thenReturn(controlPointsLienzo);
when(connector.getHead()).thenReturn(head);
when(connector.getTail()).thenReturn(tail);
when(head.getLocation()).thenReturn(new com.ait.lienzo.client.core.types.Point2D(1, 1));
when(tail.getLocation()).thenReturn(new com.ait.lienzo.client.core.types.Point2D(2, 2));
when(wiresShape.getChildShapes()).thenReturn(children);
when(shape.getShapeView()).thenReturn(wiresShape);
when(graphIndex.getEdge(connectorUUID)).thenReturn(connectorEdge);
when(connectorEdge.getContent()).thenReturn(viewConnector);
when(connectorGroup.getUserData()).thenReturn(new WiresUtils.UserData(connectorUUID, ""));
tested.init(canvasHandler);
tested.register(element);
Point2D location = new Point2D(45d, 65.5d);
tested.move(new Element[] { element }, new Point2D[] { location });
ArgumentCaptor<CanvasCommand> commandArgumentCaptor = forClass(CanvasCommand.class);
verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
ArgumentCaptor<ShapeLocationsChangedEvent> shapeLocationsChangedEventCaptor = forClass(ShapeLocationsChangedEvent.class);
verify(shapeLocationsChangedEvent, times(1)).fire(shapeLocationsChangedEventCaptor.capture());
assertTrue(shapeLocationsChangedEventCaptor.getValue() instanceof ShapeLocationsChangedEvent);
// assert parent node move
final CompositeCommand command = (CompositeCommand) commandArgumentCaptor.getValue();
UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) command.getCommands().get(0);
assertEquals(element, updateElementPositionCommand.getElement());
assertEquals(location, updateElementPositionCommand.getLocation());
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasCommand in project kie-wb-common by kiegroup.
the class LocationControlImplTest method testLocationAcceptor.
@Test
@SuppressWarnings("unchecked")
public void testLocationAcceptor() {
tested.init(canvasHandler);
tested.register(element);
ArgumentCaptor<ILocationAcceptor> locationAcceptorArgumentCaptor = ArgumentCaptor.forClass(ILocationAcceptor.class);
verify(wiresManager, times(1)).setLocationAcceptor(locationAcceptorArgumentCaptor.capture());
final ILocationAcceptor locationAcceptor = locationAcceptorArgumentCaptor.getValue();
final WiresShapeView wiresContainer = mock(WiresShapeView.class);
when(wiresContainer.getUUID()).thenReturn(ELEMENT_UUID);
final com.ait.lienzo.client.core.types.Point2D point = new com.ait.lienzo.client.core.types.Point2D(40d, 50d);
locationAcceptor.accept(new WiresContainer[] { wiresContainer }, new com.ait.lienzo.client.core.types.Point2D[] { point });
ArgumentCaptor<CanvasCommand> commandArgumentCaptor = forClass(CanvasCommand.class);
verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
final CompositeCommand command = (CompositeCommand) commandArgumentCaptor.getValue();
UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) command.getCommands().get(0);
assertEquals(element, updateElementPositionCommand.getElement());
assertEquals(new Point2D(40d, 50d), updateElementPositionCommand.getLocation());
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasCommand in project kie-wb-common by kiegroup.
the class ResizeControlImplTest method testResize.
@Test
@SuppressWarnings("unchecked")
public void testResize() {
tested.init(canvasHandler);
assertFalse(tested.isRegistered(element));
tested.register(element);
verify(shapeView, times(1)).supports(eq(ViewEventType.RESIZE));
ArgumentCaptor<ResizeHandler> resizeHandlerArgumentCaptor = ArgumentCaptor.forClass(ResizeHandler.class);
verify(shapeView, times(1)).addHandler(eq(ViewEventType.RESIZE), resizeHandlerArgumentCaptor.capture());
final CanvasCommand expectedCommand = mock(CanvasCommand.class);
doAnswer(invocationOnMock -> expectedCommand).when(canvasCommandFactory).resize(eq(element), any(BoundingBox.class));
ResizeHandler resizeHandler = resizeHandlerArgumentCaptor.getValue();
double x = 121.45d;
double y = 23.456d;
double width = 100d;
double height = 200d;
ResizeEvent event = new ResizeEvent(x, y, x, y, width, height);
resizeHandler.end(event);
ArgumentCaptor<CanvasCommand> commandArgumentCaptor = ArgumentCaptor.forClass(CanvasCommand.class);
verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
CanvasCommand command = commandArgumentCaptor.getValue();
assertNotNull(command);
assertEquals(expectedCommand, command);
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasCommand in project kie-wb-common by kiegroup.
the class NodeProxyTest method verifyCreateTargetNode.
@SuppressWarnings("all")
private void verifyCreateTargetNode(CanvasCommand<AbstractCanvasHandler> addConnectorCommand, CanvasCommand<AbstractCanvasHandler> addNodeCommand, CanvasCommand<AbstractCanvasHandler> setTargetNodeCommand) {
tested.init();
tested.start(1d, 2d);
verify(proxy, times(1)).start(eq(1d), eq(2d));
NodeShape targetNodeShape = view.getShapeBuilder().get();
assertEquals(targetShape, targetNodeShape);
ArgumentCaptor<Command> commandCaptor = ArgumentCaptor.forClass(Command.class);
verify(proxy, times(1)).execute(commandCaptor.capture());
DeferredCompositeCommand command = (DeferredCompositeCommand) commandCaptor.getValue();
List commands = command.getCommands();
assertEquals(3, command.size());
DeferredCommand c0 = (DeferredCommand) commands.get(0);
assertEquals(addNodeCommand, c0.getCommand());
DeferredCommand c1 = (DeferredCommand) commands.get(1);
assertEquals(addConnectorCommand, c1.getCommand());
DeferredCommand c2 = (DeferredCommand) commands.get(2);
assertEquals(setTargetNodeCommand, c2.getCommand());
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasCommand in project kie-wb-common by kiegroup.
the class DecisionTableGridTest method testSetTypeRefMultipleOutputClauses.
@Test
@SuppressWarnings("unchecked")
public void testSetTypeRefMultipleOutputClauses() {
setupGrid(makeHasNameForDecision(), 0);
final QName typeRef = new QName(QName.NULL_NS_URI, BuiltInType.DATE.getName());
final QName defaultTypeRef = new QName();
final Consumer<ValueAndDataTypeHeaderMetaData> test = (md) -> md.setTypeRef(typeRef);
addOutputClause(3);
final ArgumentCaptor<CanvasCommand> canvasCommandCaptor1 = ArgumentCaptor.forClass(CanvasCommand.class);
hasExpression.getVariable().setTypeRef(defaultTypeRef);
expression.get().getOutput().get(0).setTypeRef(defaultTypeRef);
assertHeaderMetaDataTest(0, 2, test, canvasCommandCaptor1, SetTypeRefCommand.class);
canvasCommandCaptor1.getValue().execute(canvasHandler);
assertThat(hasExpression.getVariable().getTypeRef()).isEqualTo(typeRef);
assertThat(expression.get().getOutput().get(0).getTypeRef()).isEqualTo(defaultTypeRef);
final ArgumentCaptor<CanvasCommand> canvasCommandCaptor2 = ArgumentCaptor.forClass(CanvasCommand.class);
hasExpression.getVariable().setTypeRef(defaultTypeRef);
expression.get().getOutput().get(0).setTypeRef(defaultTypeRef);
assertHeaderMetaDataTest(1, 2, test, canvasCommandCaptor2, SetTypeRefCommand.class);
canvasCommandCaptor2.getValue().execute(canvasHandler);
assertThat(hasExpression.getVariable().getTypeRef()).isEqualTo(defaultTypeRef);
assertThat(expression.get().getOutput().get(0).getTypeRef()).isEqualTo(typeRef);
final ArgumentCaptor<CanvasCommand> canvasCommandCaptor3 = ArgumentCaptor.forClass(CanvasCommand.class);
hasExpression.getVariable().setTypeRef(defaultTypeRef);
expression.get().getOutput().get(1).setTypeRef(defaultTypeRef);
assertHeaderMetaDataTest(0, 3, test, canvasCommandCaptor3, SetTypeRefCommand.class);
canvasCommandCaptor3.getValue().execute(canvasHandler);
assertThat(hasExpression.getVariable().getTypeRef()).isEqualTo(typeRef);
assertThat(expression.get().getOutput().get(1).getTypeRef()).isEqualTo(defaultTypeRef);
final ArgumentCaptor<CanvasCommand> canvasCommandCaptor4 = ArgumentCaptor.forClass(CanvasCommand.class);
hasExpression.getVariable().setTypeRef(defaultTypeRef);
expression.get().getOutput().get(1).setTypeRef(defaultTypeRef);
assertHeaderMetaDataTest(1, 3, test, canvasCommandCaptor4, SetTypeRefCommand.class);
canvasCommandCaptor4.getValue().execute(canvasHandler);
assertThat(hasExpression.getVariable().getTypeRef()).isEqualTo(defaultTypeRef);
assertThat(expression.get().getOutput().get(1).getTypeRef()).isEqualTo(typeRef);
}
Aggregations