Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2018-04-23 19:36:28 +0000
committerNicolas FAUVERGUE2018-05-29 13:30:23 +0000
commite65c18ff964d6407a3c750de581984eafd9044ee (patch)
tree5cf684ab932e46d69000886d5e9bf624e605f49f /tests/junit/framework
parentc18fa4d3b4a2c896323a3be417f13c58541b2166 (diff)
downloadorg.eclipse.papyrus-e65c18ff964d6407a3c750de581984eafd9044ee.tar.gz
org.eclipse.papyrus-e65c18ff964d6407a3c750de581984eafd9044ee.tar.xz
org.eclipse.papyrus-e65c18ff964d6407a3c750de581984eafd9044ee.zip
Bug 533676: [Sequence Diagram] Validation should be triggered after
creation of CombinedFragment or InteractionOperand Add custom well-formedness rules to check that messages and execution specifications do not cross interaction operand boundaries. Ensure that re-sizing of an interaction operand triggers validation of that operand and the interaction fragments that it contains, plus any messages originating or terminating within it. Because the default operand of a new combined fragment is now resized upon creation, a new operand is likewise validated for its contents. Fix validation hook and diagnostician extension point schema definitions to match reality of the extension point implementations. Remove UI contributions for validation, to avoid workflow interrution. Validation framework is still slow, but less intrusive for the user. A preference may control the validation activation on user actions. Update the failing compilation on gmfdiag.common.tests. Add a preference to switch on or off the validation. Change-Id: Ic7d83eb18315ce714dc7c71bff38276f330ef260 Also-by: RĂ©mi Schnekenburger <rschnekenburger@eclipsesource.com> 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/src/org/eclipse/papyrus/junit/matchers/DiagramMatchers.java87
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java35
2 files changed, 112 insertions, 10 deletions
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 f46dd40d599..8267e6b3529 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
@@ -8,17 +8,27 @@
*
* Contributors:
* Christian W. Damus (CEA) - Initial API and implementation
- * Christian W. Damus - bug 533673
+ * Christian W. Damus - bugs 533673, 533676
*
*/
package org.eclipse.papyrus.junit.matchers;
+import static org.hamcrest.CoreMatchers.hasItem;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
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.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
+import org.eclipse.papyrus.infra.services.decoration.DecorationService;
+import org.eclipse.papyrus.infra.services.decoration.IDecorationService;
+import org.eclipse.papyrus.infra.services.decoration.util.IPapyrusDecoration;
+import org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
@@ -135,6 +145,81 @@ public class DiagramMatchers {
return viewThat(elementThat(elementMatcher));
}
+ /**
+ * Match an edit-part that has an {@linkplain IPapyrusMarker#SEVERITY_ERROR error}
+ * decoration having a message matching a given matcher.
+ *
+ * @param messageMatcher
+ * matcher for the decoration message
+ *
+ * @return the decoration matcher
+ *
+ * @since 2.2
+ *
+ * @see #hasDecorationThat(int, Matcher)
+ * @see IPapyrusMarker#SEVERITY_ERROR
+ */
+ public static Matcher<EditPart> hasErrorDecorationThat(Matcher<? super String> messageMatcher) {
+ return hasDecorationThat(IPapyrusMarker.SEVERITY_ERROR, messageMatcher);
+ }
+
+ /**
+ * Match an edit-part that has a decoration of a given severity having a message matching
+ * a given matcher.
+ *
+ * @param severity
+ * severity, as per the {@link IPapyrusMarker#SEVERITY} marker attribute values
+ * @param messageMatcher
+ * matcher for the decoration message
+ *
+ * @return the decoration matcher
+ *
+ * @since 2.2
+ */
+ public static Matcher<EditPart> hasDecorationThat(int severity, Matcher<? super String> messageMatcher) {
+
+ return new TypeSafeDiagnosingMatcher<EditPart>() {
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("has error decoration that ").appendDescriptionOf(messageMatcher);
+ }
+
+ @Override
+ protected boolean matchesSafely(EditPart item, Description mismatchDescription) {
+ IDecorationService service = null;
+ try {
+ // For some reason, the service is registered under the implementation class instead
+ // of the interface. For maximal compatibility, we try both
+ service = ServiceUtilsForEditPart.getInstance().getService(IDecorationService.class, item);
+ } catch (Exception e) {
+ try {
+ service = ServiceUtilsForEditPart.getInstance().getService(DecorationService.class, item);
+ } catch (Exception e2) {
+ // Will fail, below
+ }
+ }
+
+ if (service == null) {
+ mismatchDescription.appendText("no decoration service");
+ return false;
+ }
+
+ List<IPapyrusDecoration> decorations = service.getDecorations(item, false);
+ List<String> messages = decorations.stream()
+ .filter(d -> d.getPriority() == severity)
+ .map(IPapyrusDecoration::getMessage)
+ .collect(Collectors.toList());
+
+ Matcher<Iterable<? super String>> delegate = hasItem(messageMatcher);
+ boolean result = delegate.matches(messages);
+ if (!result) {
+ delegate.describeMismatch(messages, mismatchDescription);
+ }
+ return result;
+ }
+ };
+ }
+
//
// Nested types
//
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 d0f96b18492..818ac24103b 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
@@ -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, 533673, 533682
+ * Christian W. Damus - bugs 433206, 465416, 434983, 483721, 469188, 485220, 491542, 497865, 533673, 533682, 533676
* Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 521550
*****************************************************************************/
package org.eclipse.papyrus.junit.utils.rules;
@@ -39,8 +39,11 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
@@ -59,11 +62,11 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.emf.workspace.IWorkspaceCommandStack;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.RootEditPart;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
import org.eclipse.gef.ui.palette.PaletteViewer;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
-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;
@@ -1151,12 +1154,26 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
editPart.getViewer().getSelectionManager().deselect(editPart);
}
- public void move(EditPart editPart, Point newLocation) {
- execute(new ICommandProxy(new SetBoundsCommand(getEditingDomain(), "Move Node", editPart, newLocation)));
- }
-
- public void resize(EditPart editPart, Dimension newSize) {
- execute(new ICommandProxy(new SetBoundsCommand(getEditingDomain(), "Resize Node", editPart, newSize)));
+ public void move(GraphicalEditPart editPart, Point newLocation) {
+ ChangeBoundsRequest move = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
+ IFigure figure = editPart.getFigure();
+ Rectangle bounds = figure.getBounds();
+ move.setEditParts(editPart);
+ move.setConstrainedMove(false);
+ move.setMoveDelta(at(newLocation.x() - bounds.x(), newLocation.y() - bounds.y()));
+ execute(editPart.getCommand(move));
+ }
+
+ public void resize(GraphicalEditPart editPart, Dimension newSize) {
+ ChangeBoundsRequest resize = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE);
+ IFigure figure = editPart.getFigure();
+ Rectangle bounds = figure.getBounds();
+ resize.setEditParts(editPart);
+ resize.setResizeDirection(PositionConstants.SOUTH_WEST);
+ resize.setCenteredResize(false);
+ resize.setConstrainedResize(false);
+ resize.setSizeDelta(sized(newSize.width() - bounds.width(), newSize.height() - bounds.height()));
+ execute(editPart.getCommand(resize));
}
public void execute(org.eclipse.gef.commands.Command command) {

Back to the top