Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2018-04-19 09:56:54 -0400
committerChristian W. Damus2018-04-25 09:44:17 -0400
commitfa3a1409f7f679d42834a4e89e1d22dd9c115ebe (patch)
treee89f6aac840c72506c453bbced6bfe810dc02a5b /tests/junit/framework
parentc1206346c848bb4316a8fbfe0d4e788d7f8004eb (diff)
downloadorg.eclipse.papyrus-fa3a1409f7f679d42834a4e89e1d22dd9c115ebe.tar.gz
org.eclipse.papyrus-fa3a1409f7f679d42834a4e89e1d22dd9c115ebe.tar.xz
org.eclipse.papyrus-fa3a1409f7f679d42834a4e89e1d22dd9c115ebe.zip
Bug 533673: [Sequence Diagram] CombinedFragment should be created with one InteractionOperand
Add an edit-helper advice to resize the default operand of a new combined fragment to fill the available space in the combined fragment. As this needs to use the edit-part controlling the operand's presentation to obtain a command that resizes the operand and captures the interaction fragments within its bounds, the execution of this advice command is deferred and captured back into the original context for undo/redo. Change-Id: Ifebab84b5b2181bea36d1cd60bf1f9f61adc4fe3 Signed-off-by: Christian W. Damus <give.a.damus@gmail.com>
Diffstat (limited to 'tests/junit/framework')
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF2
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/pom.xml2
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/DiagramMatchers.java94
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java128
4 files changed, 217 insertions, 9 deletions
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF b/tests/junit/framework/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF
index ae9fb6a3aea..4aa07cbba3d 100644
--- a/tests/junit/framework/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF
+++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF
@@ -18,7 +18,7 @@ Export-Package: org.eclipse.papyrus.junit.matchers,
org.eclipse.papyrus.junit.utils.tests
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
-Bundle-Version: 2.1.100.qualifier
+Bundle-Version: 2.2.0.qualifier
Bundle-Name: %Bundle-Name
Bundle-ManifestVersion: 2
Bundle-Activator: org.eclipse.papyrus.junit.utils.Activator
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/pom.xml b/tests/junit/framework/org.eclipse.papyrus.junit.utils/pom.xml
index fc9d6273c58..6fe2b567abc 100644
--- a/tests/junit/framework/org.eclipse.papyrus.junit.utils/pom.xml
+++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/pom.xml
@@ -7,6 +7,6 @@
</parent>
<groupId>org.eclipse.papyrus</groupId>
<artifactId>org.eclipse.papyrus.junit.utils</artifactId>
- <version>2.1.100-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/DiagramMatchers.java b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/DiagramMatchers.java
index b78720e078a..f46dd40d599 100644
--- a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/DiagramMatchers.java
+++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/DiagramMatchers.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014 CEA and others.
+ * Copyright (c) 2014, 2018 CEA, 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
@@ -8,17 +8,21 @@
*
* Contributors:
* Christian W. Damus (CEA) - Initial API and implementation
+ * Christian W. Damus - bug 533673
*
*/
package org.eclipse.papyrus.junit.matchers;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.ui.palette.PaletteViewer;
+import org.eclipse.gmf.runtime.notation.View;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
/**
@@ -51,6 +55,86 @@ public class DiagramMatchers {
return new DrawerExpansion(viewer, false);
}
+ /**
+ * Match an edit-part by some condition of its notation view.
+ *
+ * @param viewMatcher
+ * view matcher condition
+ *
+ * @since 2.2
+ */
+ public static Matcher<EditPart> viewThat(Matcher<? super View> viewMatcher) {
+ return new TypeSafeDiagnosingMatcher<EditPart>() {
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("view that ").appendDescriptionOf(viewMatcher);
+ }
+
+ @Override
+ protected boolean matchesSafely(EditPart item, Description mismatchDescription) {
+ boolean result = false;
+
+ if (!(item.getModel() instanceof View)) {
+ mismatchDescription.appendText("edit-part model is not a notation view");
+ } else {
+ View view = (View) item.getModel();
+ result = viewMatcher.matches(view);
+ if (!result) {
+ viewMatcher.describeMismatch(view, mismatchDescription);
+ }
+ }
+
+ return result;
+ }
+ };
+ }
+
+ /**
+ * Match a notation view by some condition of its semantic element.
+ *
+ * @param elementMatcher
+ * element matcher condition
+ *
+ * @since 2.2
+ */
+ public static Matcher<View> elementThat(Matcher<? super EObject> elementMatcher) {
+ return new TypeSafeDiagnosingMatcher<View>() {
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("element that ").appendDescriptionOf(elementMatcher);
+ }
+
+ @Override
+ protected boolean matchesSafely(View item, Description mismatchDescription) {
+ boolean result = false;
+
+ EObject element = item.getElement();
+ if (element == null) {
+ mismatchDescription.appendText("view has no semantic element");
+ } else {
+ result = elementMatcher.matches(element);
+ if (!result) {
+ elementMatcher.describeMismatch(element, mismatchDescription);
+ }
+ }
+
+ return result;
+ }
+ };
+ }
+
+ /**
+ * Match an edit-part by some condition of its semantic element.
+ *
+ * @param elementMatcher
+ * element matcher condition
+ *
+ * @since 2.2
+ */
+ public static Matcher<EditPart> semanticThat(Matcher<? super EObject> elementMatcher) {
+ return viewThat(elementThat(elementMatcher));
+ }
+
//
// Nested types
//
@@ -63,12 +147,14 @@ public class DiagramMatchers {
super();
}
+ @Override
public void describeTo(Description description) {
description.appendText("edit-part is selected");
}
+ @Override
public boolean matches(Object item) {
- return (item instanceof EditPart) && isSelected((EditPart)item);
+ return (item instanceof EditPart) && isSelected((EditPart) item);
}
boolean isSelected(EditPart editPart) {
@@ -88,13 +174,15 @@ public class DiagramMatchers {
this.expanded = expanded;
}
+ @Override
public void describeTo(Description description) {
description.appendText("drawer is ");
description.appendText(expanded ? "expanded" : "collapsed");
}
+ @Override
public boolean matches(Object item) {
- return (item instanceof PaletteDrawer) && (isExpanded((PaletteDrawer)item) == expanded);
+ return (item instanceof PaletteDrawer) && (isExpanded((PaletteDrawer) item) == expanded);
}
boolean isExpanded(PaletteDrawer drawer) {
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 a061a4b3240..4a972e13e7e 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
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2014, 2017 CEA, Christian W. Damus, and others.
+ * Copyright (c) 2014, 2018 CEA, 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
@@ -8,7 +8,7 @@
*
* Contributors:
* Christian W. Damus (CEA) - Initial API and implementation
- * Christian W. Damus - bugs 433206, 465416, 434983, 483721, 469188, 485220, 491542, 497865
+ * Christian W. Damus - bugs 433206, 465416, 434983, 483721, 469188, 485220, 491542, 497865, 533673
* Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 521550
*****************************************************************************/
package org.eclipse.papyrus.junit.utils.rules;
@@ -23,6 +23,10 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.eclipse.core.commands.operations.IOperationHistory;
import org.eclipse.core.commands.operations.IOperationHistoryListener;
@@ -64,10 +68,16 @@ import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IDiagramPreferenceSupport;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeCompartmentEditPart;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette;
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
@@ -122,6 +132,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
/**
@@ -430,7 +441,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
List<IMultiDiagramEditor> result = Lists.newArrayList();
for (Resource resource : initModelResources(description)) {
- if(resource.getURI().fileExtension().equals(UmlModel.UML_FILE_EXTENSION)){
+ if (resource.getURI().fileExtension().equals(UmlModel.UML_FILE_EXTENSION)) {
IFile papyrusModel = getProject().getFile(resource.getURI().trimFileExtension().appendFileExtension(DiModel.DI_FILE_EXTENSION));
modelFiles.put(description, papyrusModel);
result.add(open(papyrusModel));
@@ -927,6 +938,51 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
return findEditPart(diagram, modelElement);
}
+ /**
+ * Get the shape compartment of an edit-part. Fails if the edit-part has no
+ * shape compartment.
+ *
+ * @param shapeEditPart
+ * a shape edit part
+ * @return its shape compartment
+ *
+ * @since 2.2
+ */
+ public EditPart getShapeCompartment(EditPart shapeEditPart) {
+ return stream(shapeEditPart.getChildren(), EditPart.class)
+ .filter(ShapeCompartmentEditPart.class::isInstance)
+ .findFirst().orElseGet(failOnAbsence("No shape compartment"));
+ }
+
+ /**
+ * Obtain a typed stream over a raw-typed collection from a legacy pre-generics API
+ * such as GEF.
+ *
+ * @param rawCollection
+ * a raw-typed collection
+ * @param type
+ * the expected element type of the collection
+ * @return the typed stream
+ */
+ private static <T> Stream<T> stream(@SuppressWarnings("rawtypes") Collection rawCollection, Class<T> type) {
+ return ((Collection<?>) rawCollection).stream()
+ .filter(type::isInstance).map(type::cast);
+ }
+
+ /**
+ * Obtain a fake supplier that just fails the test with the given {@code message}
+ * instead of supplying a result.
+ *
+ * @param message
+ * the failure message
+ * @return the fake supplier
+ */
+ private static <T> Supplier<T> failOnAbsence(String message) {
+ return () -> {
+ fail(message);
+ return null;
+ };
+ }
/**
* Find orphan edit part with a type.
@@ -1104,6 +1160,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
}
public void execute(org.eclipse.gef.commands.Command command) {
+ assertThat("No command", command, notNullValue());
assertThat("Command not executable", command.canExecute(), is(true));
getActiveDiagramEditor().getDiagramEditDomain().getDiagramCommandStack().execute(command);
flushDisplayEvents();
@@ -1154,7 +1211,7 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
public void flushDisplayEvents() {
for (;;) {
try {
- if (Display.getCurrent()!=null && !Display.getCurrent().readAndDispatch()) {
+ if (Display.getCurrent() != null && !Display.getCurrent().readAndDispatch()) {
break;
}
} catch (Exception e) {
@@ -1412,4 +1469,67 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
}
});
}
+
+ /**
+ * Create a new shape in the {@code parent}. Fails if the shape cannot be created or
+ * cannot be found in the diagram after creation.
+ *
+ * @param parent
+ * the parent edit-part in which to create a shape
+ * @param type
+ * the type of shape to create
+ * @param location
+ * the location (mouse pointer) at which to create the shape
+ * @param size
+ * the size of the shape to create
+ * @return the newly created shape edit-part
+ *
+ * @since 2.2
+ */
+ public EditPart createShape(EditPart parent, IElementType type, Point location, Dimension size) {
+ CreateViewRequest request = CreateViewRequestFactory.getCreateShapeRequest(type, ((IGraphicalEditPart) parent).getDiagramPreferencesHint());
+
+ // Collect existing children
+ Set<EditPart> initialChildren = stream(parent.getChildren(), EditPart.class).collect(Collectors.toSet());
+ request.setLocation(location);
+ request.setSize(size);
+ org.eclipse.gef.commands.Command command = parent.getCommand(request);
+ execute(command);
+
+ // Find the new edit-part
+ Set<EditPart> children = stream(parent.getChildren(), EditPart.class).collect(Collectors.toSet());
+ return Sets.difference(children, initialChildren).stream()
+ .filter(ep -> ep.getModel() instanceof Shape)
+ .findAny().orElseGet(failOnAbsence("Could not find new shape edit-part"));
+ }
+
+ /**
+ * Create a point location (useful as a static import for test readability).
+ *
+ * @param x
+ * the x co├Ârdinate
+ * @param y
+ * the y co├Ârdinate
+ * @return the point
+ *
+ * @since 2.2
+ */
+ public static Point at(int x, int y) {
+ return new Point(x, y);
+ }
+
+ /**
+ * Create a size dimension (useful as a static import for test readability).
+ *
+ * @param width
+ * the size width
+ * @param height
+ * the the size height
+ * @return the size
+ *
+ * @since 2.2
+ */
+ public static Dimension sized(int width, int height) {
+ return new Dimension(width, height);
+ }
}

Back to the top