Skip to content

Commit

Permalink
JBPM-8835 : Improve Performance of Copy / Paste, Dragging, Creating N…
Browse files Browse the repository at this point in the history
…odes, etc
  • Loading branch information
inodeman committed Nov 15, 2019
1 parent 425028e commit b55bcde
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
Expand Up @@ -15,6 +15,9 @@
*/
package org.kie.workbench.common.stunner.core.client.canvas;

import java.util.ArrayList;
import java.util.List;

import javax.enterprise.event.Event;

import org.junit.Before;
Expand All @@ -27,13 +30,15 @@
import org.kie.workbench.common.stunner.core.client.canvas.event.registration.CanvasElementRemovedEvent;
import org.kie.workbench.common.stunner.core.client.canvas.event.registration.CanvasElementUpdatedEvent;
import org.kie.workbench.common.stunner.core.client.canvas.event.registration.CanvasElementsClearEvent;
import org.kie.workbench.common.stunner.core.client.canvas.listener.CanvasElementListener;
import org.kie.workbench.common.stunner.core.client.command.CanvasCommandFactory;
import org.kie.workbench.common.stunner.core.client.command.QueueGraphExecutionContext;
import org.kie.workbench.common.stunner.core.client.shape.ElementShape;
import org.kie.workbench.common.stunner.core.client.shape.MutationContext;
import org.kie.workbench.common.stunner.core.graph.Edge;
import org.kie.workbench.common.stunner.core.graph.Element;
import org.kie.workbench.common.stunner.core.graph.Node;
import org.kie.workbench.common.stunner.core.graph.command.ContextualGraphCommandExecutionContext;
import org.kie.workbench.common.stunner.core.graph.processing.index.GraphIndexBuilder;
import org.kie.workbench.common.stunner.core.graph.processing.index.MutableIndex;
import org.kie.workbench.common.stunner.core.graph.util.GraphUtils;
Expand Down Expand Up @@ -89,6 +94,12 @@ public class BaseCanvasHandlerTest {
@Mock
private QueueGraphExecutionContext queueGraphExecutionContext;

@Mock
private ContextualGraphCommandExecutionContext contextualGraphExecutionContext;

@Mock
private CanvasElementListener updateListener;

@Before
public void setup() {
canvasHandler = new CanvasHandlerImpl(clientDefinitionManager,
Expand Down Expand Up @@ -159,5 +170,34 @@ public void checkApplyElementMutationNullQueue() {
verify(queueGraphExecutionContext, never()).addElement(candidate);
}

@Test
public void checkNotifyElementUpdatedOnNonQueuedContext() {
canvasHandler.addRegistrationListener(updateListener);
canvasHandler.setStaticContext(contextualGraphExecutionContext);
final ElementShape shape = mock(ElementShape.class);
final Element candidate = mock(Element.class);
final boolean applyPosition = true;
final boolean applyProperties = false;
final MutationContext mutationContext = mock(MutationContext.class);
canvasHandler.applyElementMutation(shape,
candidate,
applyPosition,
applyProperties,
mutationContext);

verify(shape, atLeastOnce()).applyPosition(any(), any());
verify(canvasElementUpdatedEvent, atLeastOnce()).fire(any());
verify(queueGraphExecutionContext, never()).addElement(candidate);
}

@Test
public void checkNotifyElementUpdatedAndListenerUpdated() {
canvasHandler.addRegistrationListener(updateListener);

final List<Element> updatedElements = new ArrayList<>();
updatedElements.add(mock(Element.class));

canvasHandler.doBatchUpdate(updatedElements);
verify(updateListener, times(1)).updateBatch(any());
}
}
Expand Up @@ -254,6 +254,18 @@ public void testOnCanvasBatchUpdateMultiple() {
// Render will be called
}

@Test
public void testOnCanvasBatchUpdateEmpty() {
handler.bind(session);
when(formRenderer.areLastPositionsSameForElement(any())).thenReturn(true);

final List<Element> queue = new ArrayList<>();

handler.getFormsCanvasListener().updateBatch(queue);

verify(formRenderer, never()).resetCache();
}

@Test
public void testOnCanvasBatchUpdateOne() {
handler.bind(session);
Expand Down

0 comments on commit b55bcde

Please sign in to comment.