use of org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand in project kie-wb-common by kiegroup.
the class LocationControlImplTest method testMove.
@Test
@SuppressWarnings("unchecked")
public void testMove() {
tested.enable(canvasHandler);
tested.register(element);
Point2D location = new Point2D(45d, 65.5d);
tested.move(new Element[] { element }, new Point2D[] { location });
ArgumentCaptor<CanvasCommand> commandArgumentCaptor = ArgumentCaptor.forClass(CanvasCommand.class);
verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
ArgumentCaptor<ShapeLocationsChangedEvent> shapeLocationsChangedEventCaptor = ArgumentCaptor.forClass(ShapeLocationsChangedEvent.class);
verify(shapeLocationsChangedEvent, times(1)).fire(shapeLocationsChangedEventCaptor.capture());
assertTrue(shapeLocationsChangedEventCaptor.getValue() instanceof ShapeLocationsChangedEvent);
final UpdateElementPositionCommand command = (UpdateElementPositionCommand) commandArgumentCaptor.getValue();
assertEquals(element, command.getElement());
assertEquals(location, command.getLocation());
}
use of org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand in project kie-wb-common by kiegroup.
the class LocationControlImplTest method testLocationAcceptor.
@Test
@SuppressWarnings("unchecked")
public void testLocationAcceptor() {
tested.enable(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 = ArgumentCaptor.forClass(CanvasCommand.class);
verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
final UpdateElementPositionCommand command = (UpdateElementPositionCommand) commandArgumentCaptor.getValue();
assertEquals(element, command.getElement());
assertEquals(new Point2D(40d, 50d), command.getLocation());
}
use of org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand 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());
}
use of org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand in project kie-wb-common by kiegroup.
the class ObserverBuilderControlTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
ServiceCallback<Node<View<Object>, Edge>> callback = (ServiceCallback<Node<View<Object>, Edge>>) (invocationOnMock.getArguments()[2]);
view = new ViewImpl<>(new Object(), new BoundsImpl(new BoundImpl(0.0, 0.0), new BoundImpl(10.0, 20.0)));
Node<View<Object>, Edge> item = new NodeImpl<>("UUID");
item.setContent(view);
callback.onSuccess(item);
return null;
}
}).when(clientFactoryServices).newElement(anyString(), anyString(), any(ServiceCallback.class));
when(graphBoundsIndexer.setRootUUID(anyString())).thenReturn(graphBoundsIndexer);
AdapterManager adapters = mock(AdapterManager.class);
DefinitionAdapter definitionAdapter = mock(DefinitionAdapter.class);
DefinitionSetRuleAdapter rulesAdapter = mock(DefinitionSetRuleAdapter.class);
when(definitionAdapter.getId(any())).thenReturn("Object");
when(rulesAdapter.getRuleSet(any())).thenReturn(mock(RuleSet.class));
when(adapters.forDefinition()).thenReturn(definitionAdapter);
when(adapters.forRules()).thenReturn(rulesAdapter);
when(clientDefinitionManager.adapters()).thenReturn(adapters);
when(clientDefinitionManager.definitionSets()).thenReturn(mock(TypeDefinitionSetRegistry.class));
when(canvasCommandFactory.addNode(any(Node.class), anyString())).thenAnswer(new Answer<Command>() {
@Override
public Command answer(InvocationOnMock invocationOnMock) {
Node node = (Node) invocationOnMock.getArguments()[0];
String uid = (String) invocationOnMock.getArguments()[1];
return new AddCanvasNodeCommand(node, uid);
}
});
when(canvasCommandFactory.updatePosition(any(Node.class), any(Point2D.class))).thenAnswer(new Answer<Command>() {
@Override
public Command answer(InvocationOnMock invocationOnMock) {
Node node = (Node) invocationOnMock.getArguments()[0];
Point2D location = (Point2D) invocationOnMock.getArguments()[1];
return new UpdateElementPositionCommand(node, location);
}
});
when(canvasCommandFactory.draw()).thenReturn(mock(CanvasCommand.class));
ShapeSet shapeSet = mock(ShapeSet.class);
ShapeFactory shapeFactory = mock(ShapeFactory.class);
when(shapeFactory.newShape(any())).thenReturn(mock(ElementShape.class));
when(shapeSet.getShapeFactory()).thenReturn(shapeFactory);
when(shapeManager.getShapeSet(anyString())).thenReturn(shapeSet);
when(shapeManager.getDefaultShapeSet(anyString())).thenReturn(shapeSet);
tested = new ObserverBuilderControl(clientDefinitionManager, clientFactoryServices, graphUtils, ruleManager, canvasCommandFactory, graphBoundsIndexer, canvasLayoutUtils, mock(Event.class));
Diagram diagram = mock(Diagram.class);
Metadata metadata = mock(Metadata.class);
when(metadata.getCanvasRootUUID()).thenReturn("ID");
when(diagram.getMetadata()).thenReturn(metadata);
MutableIndex index = mock(MutableIndex.class);
Graph graph = mock(Graph.class);
DefinitionSet graphContent = mock(DefinitionSet.class);
when(graphContent.getBounds()).thenReturn(new BoundsImpl(new BoundImpl(10d, 10d), new BoundImpl(100d, 100d)));
when(graph.getContent()).thenReturn(graphContent);
when(index.getGraph()).thenReturn(graph);
when(graphIndexBuilder.build(any(Graph.class))).thenReturn(index);
canvasHandler = new CanvasHandlerImpl(clientDefinitionManager, canvasCommandFactory, clientFactoryServices, ruleManager, graphUtils, graphIndexBuilder, shapeManager, mock(TextPropertyProviderFactory.class), mock(Event.class), null, null, null);
canvasHandler.handle(mock(AbstractCanvas.class));
canvasHandler.draw(diagram, mock(ParameterizedCommand.class));
when(diagram.getGraph()).thenReturn(graph);
when(graph.nodes()).thenReturn(Collections.emptyList());
CanvasCommandManager commandManager = mock(CanvasCommandManager.class);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Command command = (Command) invocationOnMock.getArguments()[1];
command.execute(invocationOnMock.getArguments()[0]);
return null;
}
}).when(commandManager).execute(any(), any(Command.class));
when(commandManagerProvider.getCommandManager()).thenReturn(commandManager);
tested.enable(canvasHandler);
tested.setCommandManagerProvider(commandManagerProvider);
}
use of org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand in project kie-wb-common by kiegroup.
the class CreateNodeActionTest method testAction.
@Test
@SuppressWarnings("unchecked")
public void testAction() {
when(canvasLayoutUtils.getNext(eq(canvasHandler), eq(element), eq(targetNode))).thenReturn(new Point2D(100d, 500d));
final MouseClickEvent event = mock(MouseClickEvent.class);
when(event.getX()).thenReturn(100d);
when(event.getY()).thenReturn(500d);
ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, NODE_UUID, event);
assertEquals(tested, cascade);
ArgumentCaptor<Command> commandArgumentCaptor = ArgumentCaptor.forClass(Command.class);
verify(sessionCommandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
DeferredCompositeCommand command = (DeferredCompositeCommand) commandArgumentCaptor.getValue();
DeferredCommand c0 = (DeferredCommand) command.getCommands().get(0);
DeferredCommand c1 = (DeferredCommand) command.getCommands().get(1);
DeferredCommand c2 = (DeferredCommand) command.getCommands().get(2);
DeferredCommand c3 = (DeferredCommand) command.getCommands().get(3);
AddNodeCommand addNodeCommand = (AddNodeCommand) c0.getCommand();
UpdateElementPositionCommand updateElementPositionCommand = (UpdateElementPositionCommand) c1.getCommand();
AddConnectorCommand addConnectorCommand = (AddConnectorCommand) c2.getCommand();
SetConnectionTargetNodeCommand setTargetNodeCommand = (SetConnectionTargetNodeCommand) c3.getCommand();
assertEquals(targetNode, addNodeCommand.getCandidate());
assertEquals("ss1", addNodeCommand.getShapeSetId());
assertEquals(edge, addConnectorCommand.getCandidate());
assertEquals(element, addConnectorCommand.getSource());
assertEquals("ss1", addConnectorCommand.getShapeSetId());
assertEquals(edge, setTargetNodeCommand.getEdge());
assertEquals(targetNode, setTargetNodeCommand.getNode());
assertEquals(targetNode, updateElementPositionCommand.getElement());
assertEquals(new Point2D(100d, 500d), updateElementPositionCommand.getLocation());
final ArgumentCaptor<CanvasSelectionEvent> eventArgumentCaptor = ArgumentCaptor.forClass(CanvasSelectionEvent.class);
verify(canvasElementSelectedEvent, times(1)).fire(eventArgumentCaptor.capture());
final CanvasSelectionEvent eCaptured = eventArgumentCaptor.getValue();
assertEquals(TARGET_NODE_UUID, eCaptured.getIdentifiers().iterator().next());
}
Aggregations