Search in sources :

Example 1 with UpdateElementPropertyCommand

use of org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand in project kie-wb-common by kiegroup.

the class ResizeControlImplTest method testResize.

@Test
@SuppressWarnings("unchecked")
public void testResize() {
    when(commandManager.execute(eq(canvasHandler), any(Command.class))).thenReturn(CanvasCommandResultBuilder.SUCCESS);
    tested.enable(canvasHandler);
    assertFalse(tested.isRegistered(element));
    tested.register(element);
    verify(shapeEventHandler, times(1)).supports(eq(ViewEventType.RESIZE));
    final ArgumentCaptor<ResizeHandler> resizeHandlerArgumentCaptor = ArgumentCaptor.forClass(ResizeHandler.class);
    verify(shapeEventHandler, times(1)).addHandler(eq(ViewEventType.RESIZE), resizeHandlerArgumentCaptor.capture());
    final ResizeHandler resizeHandler = resizeHandlerArgumentCaptor.getValue();
    final double x = 121.45d;
    final double y = 23.456d;
    final double width = 100d;
    final double height = 200d;
    final ResizeEvent event = new ResizeEvent(x, y, x, y, width, height);
    resizeHandler.end(event);
    final ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
    verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
    final Command command = commandArgumentCaptor.getValue();
    assertNotNull(command);
    assertTrue(command instanceof AbstractCompositeCommand);
    final List commands = ((AbstractCompositeCommand) command).getCommands();
    assertNotNull(commands);
    assertEquals(4, commands.size());
    assertTrue(commands.get(0) instanceof UpdateElementPositionCommand);
    final UpdateElementPositionCommand positionCommand = (UpdateElementPositionCommand) commands.get(0);
    assertEquals(element, positionCommand.getElement());
    assertEquals(new Point2D(x, y), positionCommand.getLocation());
    assertTrue(commands.get(1) instanceof UpdateElementPropertyCommand);
    final UpdateElementPropertyCommand wPropertyCommand = (UpdateElementPropertyCommand) commands.get(1);
    assertEquals(element, wPropertyCommand.getElement());
    assertEquals(W_PROPERTY_ID, wPropertyCommand.getPropertyId());
    assertEquals(width, wPropertyCommand.getValue());
    assertTrue(commands.get(2) instanceof UpdateElementPropertyCommand);
    final UpdateElementPropertyCommand hPropertyCommand = (UpdateElementPropertyCommand) commands.get(2);
    assertEquals(element, hPropertyCommand.getElement());
    assertEquals(H_PROPERTY_ID, hPropertyCommand.getPropertyId());
    assertEquals(height, hPropertyCommand.getValue());
    assertTrue(commands.get(3) instanceof UpdateElementPropertyCommand);
    final UpdateElementPropertyCommand rPropertyCommand = (UpdateElementPropertyCommand) commands.get(3);
    assertEquals(element, rPropertyCommand.getElement());
    assertEquals(R_PROPERTY_ID, rPropertyCommand.getPropertyId());
    assertEquals(50d, rPropertyCommand.getValue());
}
Also used : UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) AbstractCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.AbstractCompositeCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Command(org.kie.workbench.common.stunner.core.command.Command) AbstractCompositeCommand(org.kie.workbench.common.stunner.core.command.impl.AbstractCompositeCommand) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ResizeHandler(org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeHandler) List(java.util.List) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) ResizeEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeEvent) Test(org.junit.Test)

Aggregations

List (java.util.List)1 Test (org.junit.Test)1 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)1 UpdateElementPropertyCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand)1 ResizeEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeEvent)1 ResizeHandler (org.kie.workbench.common.stunner.core.client.shape.view.event.ResizeHandler)1 Command (org.kie.workbench.common.stunner.core.command.Command)1 AbstractCompositeCommand (org.kie.workbench.common.stunner.core.command.impl.AbstractCompositeCommand)1 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)1