Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2018-05-28 17:20:18 -0400
committerNicolas FAUVERGUE2018-07-06 09:07:17 -0400
commit9b246674d8dd9c872601384f0324ef48f65369c5 (patch)
tree1f4c2db90ceaa5e3169c02fd553c148477ffe609 /tests/junit/framework
parent76d3f999219aa04592ebfcaf3e70ca149840ac63 (diff)
downloadorg.eclipse.papyrus-9b246674d8dd9c872601384f0324ef48f65369c5.tar.gz
org.eclipse.papyrus-9b246674d8dd9c872601384f0324ef48f65369c5.tar.xz
org.eclipse.papyrus-9b246674d8dd9c872601384f0324ef48f65369c5.zip
Bug 533675: [Sequence Diagram] CombinedFragment can be created in any
case in the diagram Test creation of combined fragments - covering nothing at all (in blank space) - partially covering a message - within another combined fragment Also, update the tests for bug 535097 to use the editor fixture to create interaction operands by automation of the creation tool, to better simulate user interaction. This requires explicitly disabling snap to grid (which is on by default in Photon) so that the mouse pointer can be placed as precisely as is required by the tests. Change-Id: Ic68e6c49746d63dc3e7c93ad92bd89ab68937614 Signed-off-by: Christian W. Damus <give.a.damus@gmail.com> Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr>
Diffstat (limited to 'tests/junit/framework')
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/CommandUtils.java208
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java45
2 files changed, 249 insertions, 4 deletions
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/CommandUtils.java b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/CommandUtils.java
new file mode 100644
index 00000000000..0538434b44b
--- /dev/null
+++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/CommandUtils.java
@@ -0,0 +1,208 @@
+/*****************************************************************************
+ * Copyright (c) 2018 Christian W. Damus and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.junit.utils;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.operations.ICompositeOperation;
+import org.eclipse.core.commands.operations.IUndoableOperation;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CompoundCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.core.command.ICompositeCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.papyrus.infra.emf.gmf.command.ICommandWrapper;
+
+import com.google.common.base.Strings;
+
+/**
+ * Utilities for testing and debugging commands.
+ */
+public class CommandUtils {
+
+ /**
+ * Not instantiable by clients.
+ */
+ private CommandUtils() {
+ super();
+ }
+
+ /**
+ * Dump a {@code command} structure to standard error.
+ *
+ * @param command
+ * a command to dump
+ */
+ public static void dump(Object command) {
+ dump(command, System.err, 0);
+ }
+
+ /**
+ * Dump a {@code command} structure.
+ *
+ * @param command
+ * a command to dump
+ * @param sink
+ * where to dump it
+ */
+ public static void dump(Object command, Appendable sink) {
+ dump(command, sink, 0);
+ }
+
+ static Object unwrap(Object command) {
+ if (command instanceof ICommandProxy) {
+ return ((ICommandProxy) command).getICommand();
+ } else if (command instanceof CommandProxy) {
+ return ((CommandProxy) command).getCommand();
+ } else if (command instanceof ICommandWrapper<?>) {
+ return ((ICommandWrapper<?>) command).getWrappedCommand();
+ } else {
+ return command;
+ }
+ }
+
+ static void append(CharSequence text, Appendable sink) {
+ try {
+ sink.append(text);
+ } catch (IOException e) {
+ // best effort
+ }
+ }
+
+ static void appendln(CharSequence text, Appendable sink) {
+ try {
+ sink.append(text).append(System.lineSeparator());
+ } catch (IOException e) {
+ // best effort
+ }
+ }
+
+ static void appendln(Appendable sink) {
+ try {
+ sink.append(System.lineSeparator());
+ } catch (IOException e) {
+ // best effort
+ }
+ }
+
+ static void dumpKind(Object command, Appendable sink, int depth) {
+ String kind;
+ if (command instanceof Command) {
+ kind = command instanceof CompoundCommand ? "EMF*" : "EMF";
+ } else if (command instanceof org.eclipse.gef.commands.Command) {
+ kind = command instanceof org.eclipse.gef.commands.CompoundCommand ? "GEF*" : "GEF";
+ } else if (command instanceof ICommand) {
+ kind = command instanceof ICompositeCommand ? "GMF*" : "GMF";
+ } else if (command instanceof IUndoableOperation) {
+ kind = command instanceof ICompositeOperation ? "UOP*" : "UOP";
+ } else {
+ kind = "UNK";
+ }
+
+ StringBuilder buf = new StringBuilder(45);
+ buf.append(Strings.padEnd(kind, 5, ' '));
+ buf.append(Strings.repeat(" ", depth));
+
+ String className = command.getClass().getName();
+ buf.append(className.substring(className.lastIndexOf('.') + 1));
+ buf.append(": ");
+
+ append(buf, sink);
+ }
+
+ static void dump(Object command, Appendable sink, int depth) {
+ Object unwrapped = unwrap(command);
+ if (unwrapped != command) {
+ dump(unwrapped, sink, depth);
+ return;
+ }
+
+ dumpKind(command, sink, depth);
+
+ if (command instanceof Command) {
+ dump0((Command) command, sink, depth);
+ } else if (command instanceof org.eclipse.gef.commands.Command) {
+ dump0((org.eclipse.gef.commands.Command) command, sink, depth);
+ } else if (command instanceof ICommand) {
+ dump0((ICommand) command, sink, depth);
+ } else if (command instanceof IUndoableOperation) {
+ dump0((IUndoableOperation) command, sink, depth);
+ } else {
+ appendln("<unknown>", sink);
+ }
+ }
+
+ static void dump0(org.eclipse.gef.commands.Command command, Appendable sink, int depth) {
+ appendln(command.getLabel(), sink);
+
+ if (command instanceof org.eclipse.gef.commands.CompoundCommand) {
+ int nextDepth = depth + 1;
+ org.eclipse.gef.commands.CompoundCommand compound = (org.eclipse.gef.commands.CompoundCommand) command;
+ ((List<?>) compound.getCommands()).stream().forEach(c -> dump(c, sink, nextDepth));
+ }
+ }
+
+ static void dump0(Command command, Appendable sink, int depth) {
+ appendln(command.getLabel(), sink);
+
+ if (command instanceof CompoundCommand) {
+ int nextDepth = depth + 1;
+ CompoundCommand compound = (CompoundCommand) command;
+ compound.getCommandList().stream().forEach(c -> dump(c, sink, nextDepth));
+ }
+ }
+
+ static void dump0(ICommand command, Appendable sink, int depth) {
+ appendln(command.getLabel(), sink);
+
+ if (command instanceof ICompositeCommand) {
+ int nextDepth = depth + 1;
+ ICompositeCommand compound = (ICompositeCommand) command;
+ ((Iterator<?>) compound.iterator()).forEachRemaining(c -> dump(c, sink, nextDepth));
+ }
+ }
+
+ static void dump0(IUndoableOperation command, Appendable sink, int depth) {
+ appendln(command.getLabel(), sink);
+
+ if (command instanceof ICompositeOperation) {
+ int nextDepth = depth + 1;
+ Collection<?> children = Collections.emptyList();
+
+ try {
+ Field childrenField = command.getClass().getDeclaredField("children"); //$NON-NLS-1$
+ Object childrenValue = childrenField.get(command);
+ if (childrenValue != null) {
+ children = (childrenValue instanceof Collection<?>)
+ ? (Collection<?>) childrenValue
+ : (childrenValue.getClass().isArray())
+ ? Arrays.asList((Object[]) childrenValue)
+ : Collections.singleton(childrenValue);
+ }
+ } catch (Exception e) {
+ // best effort
+ }
+
+ children.forEach(c -> dump(c, sink, nextDepth));
+ }
+ }
+
+}
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
index 55abac19b7b..2d43a7db213 100644
--- a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
+++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
@@ -108,6 +108,7 @@ import org.eclipse.papyrus.infra.tools.util.PlatformHelper;
import org.eclipse.papyrus.infra.tools.util.TypeUtils;
import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor;
import org.eclipse.papyrus.junit.matchers.CommandMatchers;
+import org.eclipse.papyrus.junit.utils.CommandUtils;
import org.eclipse.papyrus.junit.utils.EditorUtils;
import org.eclipse.papyrus.junit.utils.JUnitUtils;
import org.eclipse.papyrus.junit.utils.tests.AbstractEditorTest;
@@ -152,6 +153,7 @@ import com.google.common.collect.Lists;
* completion of the test.
*/
public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEditingDomain> {
+ private static boolean DUMP_COMMANDS = Boolean.getBoolean("dump.commands"); //$NON-NLS-1$
private final Collection<IEditorPart> editorsToClose = Lists.newArrayList();
@@ -279,6 +281,11 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
operationHistoryIntegrityListener = new IOperationHistoryListener() {
@Override
public void historyNotification(OperationHistoryEvent event) {
+ if (DUMP_COMMANDS && (event.getEventType() == OperationHistoryEvent.ABOUT_TO_EXECUTE)) {
+ System.err.println(">> Executing command"); //$NON-NLS-1$
+ CommandUtils.dump(event.getOperation());
+ System.err.println();
+ }
if ((event.getEventType() == OperationHistoryEvent.DONE) && (activeDiagramEditor != null)) {
IUndoContext diagramContext = activeDiagramEditor.getDiagramEditDomain().getDiagramCommandStack().getUndoContext();
if (diagramContext != null) {
@@ -1513,7 +1520,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
*
* @since 2.2
*/
- public EditPart createShape(EditPart parent, IElementType type, Point location, Dimension size) {
+ public IGraphicalEditPart createShape(EditPart parent, IElementType type, Point location, Dimension size) {
CreateViewRequest request = CreateViewRequestFactory.getCreateShapeRequest(type, ((IGraphicalEditPart) parent).getDiagramPreferencesHint());
request.setLocation(location);
@@ -1527,12 +1534,12 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
return getNewEditPart(parent, request.getViewDescriptors());
}
- private EditPart getNewEditPart(EditPart context, Collection<? extends ViewDescriptor> viewDescriptors) {
+ private IGraphicalEditPart getNewEditPart(EditPart context, Collection<? extends ViewDescriptor> viewDescriptors) {
return viewDescriptors.stream()
.map(desc -> desc.getAdapter(View.class)).map(View.class::cast)
.filter(Objects::nonNull)
.map(view -> DiagramEditPartsUtil.getEditPartFromView(view, context))
- .filter(Objects::nonNull)
+ .filter(IGraphicalEditPart.class::isInstance).map(IGraphicalEditPart.class::cast)
.findAny().orElseGet(failOnAbsence("Could not find newly created edit-part"));
}
@@ -1551,7 +1558,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
*
* @since 2.2
*/
- public EditPart createShape(IElementType type, Point location, Dimension size) {
+ public IGraphicalEditPart createShape(IElementType type, Point location, Dimension size) {
class MyTool extends AspectUnspecifiedTypeCreationTool {
private Collection<? extends ViewDescriptor> results = Collections.emptyList();
@@ -1640,6 +1647,36 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
}
/**
+ * Convert a point that is relative to the given part to a point relative to the
+ * current viewport (taking zoom and scroll into account). This can be used to get
+ * a "Mouse Location" to configure requests. Useful as a static import for test
+ * readability
+ *
+ * @param x
+ * the relative x coördinate
+ * @param y
+ * the relative y coördinate
+ * @param relativeTo
+ * the edit-part in which coördinate space the {@code x} and {@code y}
+ * are specified
+ * @return the point in absolute mouse-pointer coördinates
+ *
+ * @since 2.2
+ */
+ public static Point at(int x, int y, IGraphicalEditPart relativeTo) {
+ Point at = new Point(x, y);
+
+ IFigure figure = relativeTo.getContentPane();
+ Point layoutOrigin = figure.getClientArea().getLocation();
+
+ at.performTranslate(layoutOrigin.x, layoutOrigin.y);
+ figure.translateToParent(at);
+ figure.translateToAbsolute(at);
+
+ return at;
+ }
+
+ /**
* Create a size dimension (useful as a static import for test readability).
*
* @param width

Back to the top