use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class ProjectMessagesListenerTest method testFireNotificationInfo.
@Test
public void testFireNotificationInfo() {
NotificationContext context = new NotificationContext.Builder().build("test", "test", "test");
Command<?, CanvasViolation> source = mock(Command.class);
CommandNotification commandNotification = CommandNotification.Builder.build(context, source, Notification.Type.INFO, "message");
projectMessagesListener.fireNotification(commandNotification);
ArgumentCaptor<PublishMessagesEvent> eventCaptor = ArgumentCaptor.forClass(PublishMessagesEvent.class);
verify(publishMessagesEvent, times(1)).fire(eventCaptor.capture());
final List<SystemMessage> messagesToPublish = eventCaptor.getValue().getMessagesToPublish();
assertEquals(messagesToPublish.size(), 1);
SystemMessage message = messagesToPublish.get(0);
assertEquals(message.getText(), "message");
assertEquals(message.getLevel(), Level.INFO);
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class ProjectMessagesListenerTest method testFireNotificationWarning.
@Test
public void testFireNotificationWarning() {
NotificationContext context = new NotificationContext.Builder().build("test", "test", "test");
Command<?, CanvasViolation> source = mock(Command.class);
CommandNotification commandNotification = CommandNotification.Builder.build(context, source, Notification.Type.WARNING, "message");
projectMessagesListener.fireNotification(commandNotification);
ArgumentCaptor<PublishMessagesEvent> eventCaptor = ArgumentCaptor.forClass(PublishMessagesEvent.class);
verify(publishMessagesEvent, times(1)).fire(eventCaptor.capture());
final List<SystemMessage> messagesToPublish = eventCaptor.getValue().getMessagesToPublish();
assertEquals(messagesToPublish.size(), 1);
SystemMessage message = messagesToPublish.get(0);
assertEquals(message.getText(), "message");
assertEquals(message.getLevel(), Level.WARNING);
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class AddCanvasNodeCommandTest method testExecuteAndSetViewBounds.
@Test
@SuppressWarnings("unchecked")
public void testExecuteAndSetViewBounds() {
when(content.getBounds()).thenReturn(BoundsImpl.build(0d, 0d, 0d, 0d));
final CommandResult<CanvasViolation> result = tested.execute(canvasHandler);
assertNotEquals(CommandResult.Type.ERROR, result.getType());
verify(canvasHandler, times(1)).register(eq(SHAPE_SET_ID), eq(candidate));
verify(canvasHandler, times(1)).applyElementMutation(eq(candidate), any(MutationContext.class));
final ArgumentCaptor<Bounds> boundsArgumentCaptor = ArgumentCaptor.forClass(Bounds.class);
verify(content, times(1)).setBounds(boundsArgumentCaptor.capture());
final BoundsImpl bounds = (BoundsImpl) boundsArgumentCaptor.getValue();
assertEquals(0d, bounds.getX(), 0d);
assertEquals(0d, bounds.getY(), 0d);
assertEquals(50d, bounds.getWidth(), 0d);
assertEquals(50d, bounds.getHeight(), 0d);
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class SetCanvasConnectionCommandTest method testExecuteAndUpdateMagnetLocations.
@Test
@SuppressWarnings("unchecked")
public void testExecuteAndUpdateMagnetLocations() {
final MagnetConnection sourceConnection = new MagnetConnection.Builder().magnet(0).build();
final MagnetConnection targetConnection = new MagnetConnection.Builder().magnet(0).build();
when(edgeContent.getSourceConnection()).thenReturn(Optional.of(sourceConnection));
when(edgeContent.getTargetConnection()).thenReturn(Optional.of(targetConnection));
final CommandResult<CanvasViolation> result = tested.execute(canvasHandler);
assertNotEquals(CommandResult.Type.ERROR, result.getType());
verify(edgeShape, times(1)).applyConnections(eq(edge), eq(sourceShapeView), eq(targetShapeView), any(MutationContext.class));
verify(canvasHandler, times(1)).notifyCanvasElementUpdated(eq(source));
verify(canvasHandler, times(1)).notifyCanvasElementUpdated(eq(target));
assertEquals(5d, sourceConnection.getLocation().getX(), 0d);
assertEquals(5d, sourceConnection.getLocation().getY(), 0d);
assertEquals(10d, targetConnection.getLocation().getX(), 0d);
assertEquals(10d, targetConnection.getLocation().getY(), 0d);
}
use of org.kie.workbench.common.stunner.core.client.command.CanvasViolation in project kie-wb-common by kiegroup.
the class ResizeControlImpl method registerResizeHandlers.
@SuppressWarnings("unchecked")
private void registerResizeHandlers(final Element element, final Shape<?> shape) {
if (shape.getShapeView() instanceof HasEventHandlers) {
final HasEventHandlers hasEventHandlers = (HasEventHandlers) shape.getShapeView();
final ResizeHandler resizeHandler = new ResizeHandler() {
@Override
public void start(final ResizeEvent event) {
}
@Override
public void handle(final ResizeEvent event) {
}
@Override
public void end(final ResizeEvent event) {
LOGGER.log(Level.FINE, "Shape [" + element.getUUID() + "] resized to size {" + event.getWidth() + ", " + event.getHeight() + "] " + "& Coordinates [" + event.getX() + ", " + event.getY() + "]");
final Shape shape = canvasHandler.getCanvas().getShape(element.getUUID());
final double x = shape.getShapeView().getShapeX();
final double y = shape.getShapeView().getShapeY();
final CommandResult<CanvasViolation> result = doResize(element, x + event.getX(), y + event.getY(), event.getWidth(), event.getHeight());
if (CommandUtils.isError(result)) {
LOGGER.log(Level.WARNING, "Command failed at resize end [result=" + result + "]");
}
}
};
hasEventHandlers.addHandler(ViewEventType.RESIZE, resizeHandler);
registerHandler(element.getUUID(), resizeHandler);
}
}
Aggregations