use of org.kie.workbench.common.stunner.core.command.impl.AbstractCompositeCommand 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());
}
Aggregations