From e06a54bbd7c60b9c867089063bb7f9a977b57440 Mon Sep 17 00:00:00 2001 From: Camille Letavernier Date: Wed, 8 Aug 2018 13:19:12 +0200 Subject: Bug 536631: [Sequence Diagram] Support DurationConstraint/Observation as a Connection between two events Bug 537561: [Sequence Diagram] Support GeneralOrdering as a Connection between two events - Add tests Change-Id: Ibfc943b7658839334c8fd67243053c702312423d Signed-off-by: Camille Letavernier --- .../META-INF/MANIFEST.MF | 1 + .../junit/utils/rules/PapyrusEditorFixture.java | 107 ++++ .../resource/bugs/bug536631-durationLinks.di | 2 + .../resource/bugs/bug536631-durationLinks.notation | 607 +++++++++++++++++++++ .../resource/bugs/bug536631-durationLinks.uml | 112 ++++ .../bugs/bug536631-durationLinksCreation.di | 2 + .../bugs/bug536631-durationLinksCreation.notation | 116 ++++ .../bugs/bug536631-durationLinksCreation.uml | 32 ++ .../bug/AbstractOccurrenceLinkCreationTest.java | 311 +++++++++++ .../tests/bug/AbstractOccurrenceLinkTest.java | 285 ++++++++++ .../uml/diagram/sequence/tests/bug/BugTests.java | 6 + .../tests/bug/DurationConstraintCreationTest.java | 43 ++ .../tests/bug/DurationObservationCreationTest.java | 43 ++ .../tests/bug/GeneralOrderingCreationTest.java | 43 ++ .../tests/bug/TestDurationConstraintDisplay.java | 72 +++ .../tests/bug/TestDurationObservationDisplay.java | 73 +++ .../tests/bug/TestGeneralOrderingDisplay.java | 65 +++ 17 files changed, 1920 insertions(+) create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinks.di create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinks.notation create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinks.uml create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinksCreation.di create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinksCreation.notation create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinksCreation.uml create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/AbstractOccurrenceLinkCreationTest.java create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/AbstractOccurrenceLinkTest.java create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/DurationConstraintCreationTest.java create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/DurationObservationCreationTest.java create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/GeneralOrderingCreationTest.java create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestDurationConstraintDisplay.java create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestDurationObservationDisplay.java create mode 100644 tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestGeneralOrderingDisplay.java diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/META-INF/MANIFEST.MF index c4d23b7344f..7ed919715fb 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/META-INF/MANIFEST.MF +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence/META-INF/MANIFEST.MF @@ -1,5 +1,6 @@ Manifest-Version: 1.0 Export-Package: org.eclipse.papyrus.uml.diagram.sequence, + org.eclipse.papyrus.uml.diagram.sequence.anchors, org.eclipse.papyrus.uml.diagram.sequence.edit.parts, org.eclipse.papyrus.uml.diagram.sequence.edit.policies, org.eclipse.papyrus.uml.diagram.sequence.figures, 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 2da1d3f6513..baf98f408ba 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 @@ -12,6 +12,7 @@ * Christian W. Damus (CEA) - Initial API and implementation * Christian W. Damus - bugs 433206, 465416, 434983, 483721, 469188, 485220, 491542, 497865, 533673, 533682, 533676, 533679 * Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 521550 + * EclipseSource - Bug 536631 *****************************************************************************/ package org.eclipse.papyrus.junit.utils.rules; @@ -26,6 +27,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Objects; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -70,7 +72,11 @@ import org.eclipse.gef.GraphicalEditPart; import org.eclipse.gef.Request; import org.eclipse.gef.RequestConstants; import org.eclipse.gef.RootEditPart; +import org.eclipse.gef.Tool; +import org.eclipse.gef.palette.PaletteRoot; +import org.eclipse.gef.palette.ToolEntry; import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gef.ui.palette.PaletteViewer; import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint; import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; @@ -79,6 +85,7 @@ 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.IDiagramGraphicalViewer; 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.CreateViewRequest.ViewDescriptor; @@ -100,7 +107,10 @@ import org.eclipse.papyrus.infra.core.services.ServiceException; import org.eclipse.papyrus.infra.core.services.ServicesRegistry; import org.eclipse.papyrus.infra.core.utils.ServiceUtils; import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel; +import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeConnectionTool; +import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeConnectionTool.CreateAspectUnspecifiedTypeConnectionRequest; import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeCreationTool; +import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.PaletteUtil; import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramEditPartsUtil; import org.eclipse.papyrus.infra.nattable.common.editor.AbstractEMFNattableEditor; import org.eclipse.papyrus.infra.nattable.common.modelresource.PapyrusNattableModel; @@ -138,6 +148,7 @@ import org.eclipse.ui.part.IPage; import org.eclipse.uml2.uml.NamedElement; import org.eclipse.uml2.uml.Package; import org.eclipse.uml2.uml.UMLPackage; +import org.junit.Assert; import org.junit.runner.Description; import org.osgi.framework.Bundle; import org.osgi.framework.FrameworkUtil; @@ -1715,4 +1726,100 @@ public class PapyrusEditorFixture extends AbstractModelFixture + * Return the Papyrus {@link CreateRequest} associated with the given palette tool. + *

+ *

+ * Note that this method is designed to work exclusively with Papyrus' AspectUnspecified tools and requests + *

+ * + * @param tool + * @return + * @throws Exception + * + * @see AspectUnspecifiedTypeCreationTool + * @see AspectUnspecifiedTypeConnectionTool + * @see AspectUnspecifiedTypeConnectionTool.CreateAspectUnspecifiedTypeConnectionRequest + * @see AspectUnspecifiedTypeCreationTool.CreateAspectUnspecifiedTypeRequest + */ + public Request getAspectUnspecifiedCreateRequest(final Tool tool) throws Exception { + final IDiagramGraphicalViewer viewer = getActiveDiagramEditor().getDiagramGraphicalViewer(); + + AtomicReference exception = new AtomicReference<>(); + Display.getDefault().syncExec(new Runnable() { + + @Override + public void run() { + try { + tool.setViewer(viewer); + } catch (Exception ex) { + exception.set(ex); + } + } + }); + if (exception.get() != null) { + throw exception.get(); + } + + if (tool instanceof AspectUnspecifiedTypeCreationTool) { + AspectUnspecifiedTypeCreationTool creationTool = (AspectUnspecifiedTypeCreationTool) tool; + return creationTool.createCreateRequest(); + } else if (tool instanceof AspectUnspecifiedTypeConnectionTool) { + AspectUnspecifiedTypeConnectionTool connectionTool = (AspectUnspecifiedTypeConnectionTool) tool; + return connectionTool.new CreateAspectUnspecifiedTypeConnectionRequest(connectionTool.getElementTypes(), false, getPreferencesHint()); + } + + throw new Exception("Unexpected kind of creation tool."); + } + + /** + *

+ * Return the Palette Tool with the given toolId from the current active diagram editor + *

+ * + * @param paletteToolId + * @return + */ + public Tool getPaletteTool(String paletteToolId) { + PaletteRoot paletteRoot = getActiveDiagramEditor().getDiagramGraphicalViewer().getEditDomain().getPaletteViewer().getPaletteRoot(); + List allToolEntries = PaletteUtil.getAllToolEntries(paletteRoot); + return allToolEntries.stream().filter(entry -> entry.getId().equals(paletteToolId)).findAny().map(ToolEntry::createTool).orElse(null); + } + + /** + * Create a Link, using the given PaletteToolID (Which should match an {@link AspectUnspecifiedTypeConnectionTool}), + * from the given source to the given target edit part. + * + * @param paletteToolId + * The ID of the palette tool to use to create a new link. It should correspond to an {@link AspectUnspecifiedTypeConnectionTool}. + * @param sourceEditPart + * The edit part that is the source for the new link + * @param targetEditPart + * The edit part that is the target for the new link + * @param sourceLocation + * The location at which the connection source is created + * @param targetLocation + * The location at which the connection target is created + */ + public void createLink(String paletteToolId, EditPart sourceEditPart, EditPart targetEditPart, Point sourceLocation, Point targetLocation) throws Exception { + Tool tool = getPaletteTool(paletteToolId); + Assert.assertNotNull("The requested tool (" + paletteToolId + ")wasn't found in the current active diagram", tool); + CreateAspectUnspecifiedTypeConnectionRequest request = (CreateAspectUnspecifiedTypeConnectionRequest) getAspectUnspecifiedCreateRequest(tool); + + request.setLocation(sourceLocation); + request.setSourceEditPart(sourceEditPart); + request.setType(RequestConstants.REQ_CONNECTION_START); + org.eclipse.gef.commands.Command sourceCommand = sourceEditPart.getCommand(request); // Initialize the source + Assert.assertTrue("Impossible to create the requested connection (" + paletteToolId + ") on the requested source (" + sourceEditPart + ")", sourceCommand != null && sourceCommand.canExecute()); + + request.setTargetEditPart(targetEditPart); + request.setType(RequestConstants.REQ_CONNECTION_END); + request.setLocation(targetLocation); + + org.eclipse.gef.commands.Command completeCommand = targetEditPart.getCommand(request); + execute(completeCommand); + } } diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinks.di b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinks.di new file mode 100644 index 00000000000..8c549eecdc6 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinks.di @@ -0,0 +1,2 @@ + + diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinks.notation b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinks.notation new file mode 100644 index 00000000000..05d3f46800f --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinks.notation @@ -0,0 +1,607 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinks.uml b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinks.uml new file mode 100644 index 00000000000..14b9ea2f875 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinks.uml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinksCreation.di b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinksCreation.di new file mode 100644 index 00000000000..8c549eecdc6 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinksCreation.di @@ -0,0 +1,2 @@ + + diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinksCreation.notation b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinksCreation.notation new file mode 100644 index 00000000000..b6533625ca4 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinksCreation.notation @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinksCreation.uml b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinksCreation.uml new file mode 100644 index 00000000000..0a7cdae9ea9 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/resource/bugs/bug536631-durationLinksCreation.uml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/AbstractOccurrenceLinkCreationTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/AbstractOccurrenceLinkCreationTest.java new file mode 100644 index 00000000000..391e0904c4b --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/AbstractOccurrenceLinkCreationTest.java @@ -0,0 +1,311 @@ +/***************************************************************************** + * Copyright (c) 2018 CEA LIST, EclipseSource 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: + * EclipseSource - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.sequence.tests.bug; + +import java.util.Random; +import java.util.Set; + +import org.eclipse.draw2d.Connection; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.PolylineConnection; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest; +import org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.CenterAnchor; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.ConnectionSourceAnchor; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.ConnectionTargetAnchor; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.NodeBottomAnchor; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.NodeTopAnchor; +import org.eclipse.uml2.uml.ActionExecutionSpecification; +import org.eclipse.uml2.uml.BehaviorExecutionSpecification; +import org.eclipse.uml2.uml.DestructionOccurrenceSpecification; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Message; +import org.eclipse.uml2.uml.NamedElement; +import org.hamcrest.core.IsInstanceOf; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public abstract class AbstractOccurrenceLinkCreationTest extends AbstractPapyrusTest { + + @Rule + public final PapyrusEditorFixture editor = new PapyrusEditorFixture(); + + IGraphicalEditPart exec1, exec2, exec3, destruction1, destruction2; + ConnectionNodeEditPart message3, message4; + ConnectionNodeEditPart[] links; + + private Class umlClass; + + private String paletteToolId; + + private Class figureClass; + + public AbstractOccurrenceLinkCreationTest(Class umlClass, String paletteToolId, Class figureClass) { + this.umlClass = umlClass; + this.paletteToolId = paletteToolId; + this.figureClass = figureClass; + } + + @Before + public void getElements() { + exec1 = (IGraphicalEditPart) editor.findEditPart("ActionExecutionSpecification1", ActionExecutionSpecification.class); + exec2 = (IGraphicalEditPart) editor.findEditPart("BehaviorExecutionSpecification2", BehaviorExecutionSpecification.class); + exec3 = (IGraphicalEditPart) editor.findEditPart("ActionExecutionSpecification3", ActionExecutionSpecification.class); + destruction1 = (IGraphicalEditPart) editor.findEditPart("Message1ReceiveDestroyEvent", DestructionOccurrenceSpecification.class); + destruction2 = (IGraphicalEditPart) editor.findEditPart("Message2ReceiveDestroyEvent", DestructionOccurrenceSpecification.class); + + message3 = (ConnectionNodeEditPart) editor.findEditPart("Message3", Message.class); + message4 = (ConnectionNodeEditPart) editor.findEditPart("Message4", Message.class); + } + + @Test + public void testLinkCreationOnMessageSourceToTarget() throws Exception { + editor.getActiveDiagramEditor().getDiagramGraphicalViewer().reveal(message4); + + Point message3Source = findSourcePoint(message3); + Point message4Target = findTargetPoint(message4); + + editor.createLink(paletteToolId, message3, message4, message3Source, message4Target); + + Message umlMessage3 = (Message) EMFHelper.getEObject(message3); + Message umlMessage4 = (Message) EMFHelper.getEObject(message4); + + // There's no T in the model before we create the link, so just find the only one + Set allInstances = EMFHelper.allInstances(umlMessage3.eResource(), umlClass); + T newLink = allInstances.iterator().next(); + + EditPart newLinkEditPart = editor.findEditPart(newLink); + Assert.assertThat(newLinkEditPart, IsInstanceOf.instanceOf(ConnectionNodeEditPart.class)); + ConnectionNodeEditPart newConnection = (ConnectionNodeEditPart) newLinkEditPart; + + Element source = getSemanticSource(newLink); + Element target = getSemanticTarget(newLink); + + Assert.assertEquals(umlMessage3.getSendEvent(), source); + Assert.assertEquals(umlMessage4.getReceiveEvent(), target); + Assert.assertThat(newConnection.getConnectionFigure(), IsInstanceOf.instanceOf(figureClass)); + Assert.assertThat(newConnection.getConnectionFigure().getSourceAnchor(), IsInstanceOf.instanceOf(ConnectionSourceAnchor.class)); + Assert.assertThat(newConnection.getConnectionFigure().getTargetAnchor(), IsInstanceOf.instanceOf(ConnectionTargetAnchor.class)); + } + + @Test + public void testLinkCreationOnMessageTargetToSource() throws Exception { + editor.getActiveDiagramEditor().getDiagramGraphicalViewer().reveal(message4); + + Point message3Target = findTargetPoint(message3); + Point message4Source = findSourcePoint(message4); + + editor.createLink(paletteToolId, message3, message4, message3Target, message4Source); + + Message umlMessage3 = (Message) EMFHelper.getEObject(message3); + Message umlMessage4 = (Message) EMFHelper.getEObject(message4); + + // There's no T in the model before we create the link, so just find the only one + Set allInstances = EMFHelper.allInstances(umlMessage3.eResource(), umlClass); + T newLink = allInstances.iterator().next(); + + EditPart newLinkEditPart = editor.findEditPart(newLink); + Assert.assertThat(newLinkEditPart, IsInstanceOf.instanceOf(ConnectionNodeEditPart.class)); + ConnectionNodeEditPart newConnection = (ConnectionNodeEditPart) newLinkEditPart; + + Element source = getSemanticSource(newLink); + Element target = getSemanticTarget(newLink); + + Assert.assertEquals(umlMessage3.getReceiveEvent(), source); + Assert.assertEquals(umlMessage4.getSendEvent(), target); + Assert.assertThat(newConnection.getConnectionFigure(), IsInstanceOf.instanceOf(figureClass)); + Assert.assertThat(newConnection.getConnectionFigure().getSourceAnchor(), IsInstanceOf.instanceOf(ConnectionTargetAnchor.class)); + Assert.assertThat(newConnection.getConnectionFigure().getTargetAnchor(), IsInstanceOf.instanceOf(ConnectionSourceAnchor.class)); + } + + @Test + public void testLinkCreationOnExecSpecStartToFinish() throws Exception { + editor.getActiveDiagramEditor().getDiagramGraphicalViewer().reveal(exec2); + + Point exec1Start = findStartPoint(exec1); + Point exec2Finish = findFinishPoint(exec2); + + editor.createLink(paletteToolId, exec1, exec2, exec1Start, exec2Finish); + + ActionExecutionSpecification umlExec1 = (ActionExecutionSpecification) EMFHelper.getEObject(exec1); + BehaviorExecutionSpecification umlExec2 = (BehaviorExecutionSpecification) EMFHelper.getEObject(exec2); + + // There's no T in the model before we create the link, so just find the only one + Set allInstances = EMFHelper.allInstances(umlExec1.eResource(), umlClass); + T newLink = allInstances.iterator().next(); + + EditPart newLinkEditPart = editor.findEditPart(newLink); + Assert.assertThat(newLinkEditPart, IsInstanceOf.instanceOf(ConnectionNodeEditPart.class)); + ConnectionNodeEditPart newConnection = (ConnectionNodeEditPart) newLinkEditPart; + + Element source = getSemanticSource(newLink); + Element target = getSemanticTarget(newLink); + + Assert.assertEquals(umlExec1.getStart(), source); + Assert.assertEquals(umlExec2.getFinish(), target); + Assert.assertThat(newConnection.getConnectionFigure(), IsInstanceOf.instanceOf(figureClass)); + Assert.assertThat(newConnection.getConnectionFigure().getSourceAnchor(), IsInstanceOf.instanceOf(NodeTopAnchor.class)); + Assert.assertThat(newConnection.getConnectionFigure().getTargetAnchor(), IsInstanceOf.instanceOf(NodeBottomAnchor.class)); + } + + @Test + public void testLinkCreationOnExecSpecFinishToStart() throws Exception { + editor.getActiveDiagramEditor().getDiagramGraphicalViewer().reveal(exec3); + + Point exec1Finish = findFinishPoint(exec1); + Point exec3Start = findStartPoint(exec3); + + editor.createLink(paletteToolId, exec1, exec3, exec1Finish, exec3Start); + + ActionExecutionSpecification umlExec1 = (ActionExecutionSpecification) EMFHelper.getEObject(exec1); + ActionExecutionSpecification umlExec3 = (ActionExecutionSpecification) EMFHelper.getEObject(exec3); + + // There's no T in the model before we create the link, so just find the only one + Set allInstances = EMFHelper.allInstances(umlExec1.eResource(), umlClass); + T newLink = allInstances.iterator().next(); + + EditPart newLinkEditPart = editor.findEditPart(newLink); + Assert.assertThat(newLinkEditPart, IsInstanceOf.instanceOf(ConnectionNodeEditPart.class)); + ConnectionNodeEditPart newConnection = (ConnectionNodeEditPart) newLinkEditPart; + + Element source = getSemanticSource(newLink); + Element target = getSemanticTarget(newLink); + + Assert.assertEquals(umlExec1.getFinish(), source); + Assert.assertEquals(umlExec3.getStart(), target); + Assert.assertThat(newConnection.getConnectionFigure(), IsInstanceOf.instanceOf(figureClass)); + Assert.assertThat(newConnection.getConnectionFigure().getSourceAnchor(), IsInstanceOf.instanceOf(NodeBottomAnchor.class)); + Assert.assertThat(newConnection.getConnectionFigure().getTargetAnchor(), IsInstanceOf.instanceOf(NodeTopAnchor.class)); + } + + @Test + public void testLinkCreationOnDestruction() throws Exception { + editor.getActiveDiagramEditor().getDiagramGraphicalViewer().reveal(destruction2); + + Point destruction1Any = findAnyPoint(destruction1); + Point destruction2Any = findAnyPoint(destruction2); + + editor.createLink(paletteToolId, destruction1, destruction2, destruction1Any, destruction2Any); + + DestructionOccurrenceSpecification umlDest1 = (DestructionOccurrenceSpecification) EMFHelper.getEObject(destruction1); + DestructionOccurrenceSpecification umlDest2 = (DestructionOccurrenceSpecification) EMFHelper.getEObject(destruction2); + + // There's no T in the model before we create the link, so just find the only one + Set allInstances = EMFHelper.allInstances(umlDest1.eResource(), umlClass); + T newLink = allInstances.iterator().next(); + + EditPart newLinkEditPart = editor.findEditPart(newLink); + Assert.assertThat(newLinkEditPart, IsInstanceOf.instanceOf(ConnectionNodeEditPart.class)); + ConnectionNodeEditPart newConnection = (ConnectionNodeEditPart) newLinkEditPart; + + Element source = getSemanticSource(newLink); + Element target = getSemanticTarget(newLink); + + Assert.assertEquals(umlDest1, source); + Assert.assertEquals(umlDest2, target); + Assert.assertThat(newConnection.getConnectionFigure(), IsInstanceOf.instanceOf(figureClass)); + Assert.assertThat(newConnection.getConnectionFigure().getSourceAnchor(), IsInstanceOf.instanceOf(CenterAnchor.class)); + Assert.assertThat(newConnection.getConnectionFigure().getTargetAnchor(), IsInstanceOf.instanceOf(CenterAnchor.class)); + } + + protected abstract Element getSemanticSource(T link); + + protected abstract Element getSemanticTarget(T link); + + private Point findSourcePoint(ConnectionNodeEditPart editPart) { + PolylineConnection connection = (PolylineConnection) editPart.getConnectionFigure(); + Point start = connection.getStart().getCopy(); + Point end = connection.getEnd().getCopy(); + + connection.translateToAbsolute(start); + connection.translateToAbsolute(end); + + // Messages are straight lines, so just shift the X/Y slightly towards the source side + int newX = (int) (0.75 * start.x() + 0.25 * end.x()); + int newY = (int) (0.75 * start.y() + 0.25 * end.y()); + + return new Point(newX, newY); + } + + private Point findTargetPoint(ConnectionNodeEditPart editPart) { + PolylineConnection connection = (PolylineConnection) editPart.getConnectionFigure(); + Point end = connection.getEnd().getCopy(); + Point start = connection.getStart().getCopy(); + + connection.translateToAbsolute(start); + connection.translateToAbsolute(end); + + // Messages are straight lines, so just shift the X/Y slightly towards the target side + int newX = (int) (0.75 * end.x() + 0.25 * start.x()); + int newY = (int) (0.75 * end.y() + 0.25 * start.y()); + + return new Point(newX, newY); + } + + private Point findStartPoint(IGraphicalEditPart editPart) { + IFigure figure = editPart.getFigure(); + Rectangle bounds = figure.getBounds(); + + Point top = bounds.getTop().getCopy(); + Point bottom = bounds.getBottom().getCopy(); + figure.translateToAbsolute(top); + figure.translateToAbsolute(bottom); + + int newX = top.x() + 7; // Slightly shift to the right (arbitrary small value) + int newY = (int) (0.75 * top.y() + 0.25 * bottom.y()); // Shift to the bottom (We just need to be on the upper half of the ExecSpec to target the start event) + + return new Point(newX, newY); + } + + private Point findFinishPoint(IGraphicalEditPart editPart) { + IFigure figure = editPart.getFigure(); + Rectangle bounds = figure.getBounds(); + + Point top = bounds.getTop().getCopy(); + Point bottom = bounds.getBottom().getCopy(); + figure.translateToAbsolute(top); + figure.translateToAbsolute(bottom); + + int newX = bottom.x() - 4; // Slightly shift to the left (arbitrary value between -10 and 10) + int newY = (int) (0.25 * top.y() + 0.75 * bottom.y()); // Shift to the top (We just need to be on the lower half of the ExecSpec to target the finish event) + + return new Point(newX, newY); + } + + private Point findAnyPoint(IGraphicalEditPart editPart) { + IFigure figure = editPart.getFigure(); + Rectangle bounds = figure.getBounds(); + + Point topLeft = bounds.getTopLeft().getCopy(); + Point bottomRight = bounds.getBottomRight().getCopy(); + + Random r = new Random(); + int x = topLeft.x() + r.nextInt(bottomRight.x() - topLeft.x()); + int y = topLeft.y() + r.nextInt(bottomRight.y() - topLeft.y()); + + return new Point(x, y); + } + + + +} + diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/AbstractOccurrenceLinkTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/AbstractOccurrenceLinkTest.java new file mode 100644 index 00000000000..17e396563ed --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/AbstractOccurrenceLinkTest.java @@ -0,0 +1,285 @@ +/***************************************************************************** + * Copyright (c) 2018 CEA LIST, EclipseSource 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: + * EclipseSource - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.sequence.tests.bug; + +import java.util.Arrays; + +import org.eclipse.draw2d.Connection; +import org.eclipse.draw2d.ConnectionAnchor; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.PolylineConnection; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.requests.ChangeBoundsRequest; +import org.eclipse.gef.requests.ReconnectRequest; +import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest; +import org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.CenterAnchor; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.ConnectionSourceAnchor; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.ConnectionTargetAnchor; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.NodeBottomAnchor; +import org.eclipse.papyrus.uml.diagram.sequence.anchors.NodeTopAnchor; +import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.UpdateWeakReferenceForExecSpecEditPolicy; +import org.eclipse.uml2.uml.ActionExecutionSpecification; +import org.eclipse.uml2.uml.DestructionOccurrenceSpecification; +import org.eclipse.uml2.uml.Lifeline; +import org.eclipse.uml2.uml.Message; +import org.eclipse.uml2.uml.NamedElement; +import org.eclipse.uml2.uml.OccurrenceSpecification; +import org.hamcrest.core.IsEqual; +import org.hamcrest.core.IsInstanceOf; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + *

+ * Base test class for DurationLinks (DurationConstraint and DurationObservation) and GeneralOrdering + *

+ *

+ * These links are really similar in that they use the same Anchors representing + * {@link OccurrenceSpecification}s, thus mostly behave the same. The only differences + * are semantic, and they use a different figure. + *

+ */ +public abstract class AbstractOccurrenceLinkTest extends AbstractPapyrusTest { + + @Rule + public final PapyrusEditorFixture editor = new PapyrusEditorFixture(); + + IGraphicalEditPart lifeline1, lifeline3, exec1, exec3, destruction; + ConnectionNodeEditPart message1, message4; + ConnectionNodeEditPart[] links; + + private String[] linkNames; + + private Class umlClass; + + private Class connectionFigure; + + public AbstractOccurrenceLinkTest(String[] linkNames, Class umlClass, Class connectionFigure) { + Assert.assertTrue("Test setup error: there should be at least 7 links defined for this test class", linkNames.length >= 7); + this.linkNames = linkNames; + this.umlClass = umlClass; + this.connectionFigure = connectionFigure; + } + + @Before + public void getElements() { + lifeline1 = (IGraphicalEditPart) editor.findEditPart("Lifeline1", Lifeline.class); + lifeline3 = (IGraphicalEditPart) editor.findEditPart("Lifeline3", Lifeline.class); + exec1 = (IGraphicalEditPart) editor.findEditPart("ActionExecutionSpecification1", ActionExecutionSpecification.class); + exec3 = (IGraphicalEditPart) editor.findEditPart("ActionExecutionSpecification3", ActionExecutionSpecification.class); + destruction = (IGraphicalEditPart) editor.findEditPart("Message5ReceiveDestroyEvent", DestructionOccurrenceSpecification.class); + + message1 = (ConnectionNodeEditPart) editor.findEditPart("Message1", Message.class); + message4 = (ConnectionNodeEditPart) editor.findEditPart("Message4", Message.class); + + links = Arrays.stream(linkNames).map(name -> editor.findEditPart(name, umlClass)) + .map(ConnectionNodeEditPart.class::cast) + .toArray(ConnectionNodeEditPart[]::new); + } + + @Test + public void testLinksAnchors() { + checkFixedAnchors(links[0], NodeTopAnchor.class, NodeTopAnchor.class); + checkFixedAnchors(links[1], ConnectionSourceAnchor.class, ConnectionTargetAnchor.class); + checkFixedAnchors(links[2], NodeTopAnchor.class, ConnectionTargetAnchor.class); + checkFixedAnchors(links[3], NodeBottomAnchor.class, NodeBottomAnchor.class); + checkFixedAnchors(links[4], ConnectionTargetAnchor.class, ConnectionSourceAnchor.class); + checkFixedAnchors(links[5], ConnectionSourceAnchor.class, CenterAnchor.class); + checkFixedAnchors(links[6], NodeBottomAnchor.class, ConnectionTargetAnchor.class); + } + + @Test + public void testLinksDisplay() { + for (ConnectionNodeEditPart link : links) { + Assert.assertThat(link.getFigure(), IsInstanceOf.instanceOf(connectionFigure)); + } + + // Check the initial anchors. Note that this test is fragile, since the anchors + // depend on the start/finish position of ExecSpecs, Messages and the position of + // destruction events. + // If any of these elements change, the assertions will fail, even if the Link + // anchor itself is correct. + // Anchors are aligned on the grid (Or in the middle of two points on the grid, e.g. for the X location + // on an ExecutionSpecification). + // It seems that message anchors are not always perfectly aligned on the grid (Values "301", "401") + checkPosition(links[0], 130, 100, 410, 160); + checkPosition(links[1], 140, 180, 400, 180); + checkPosition(links[2], 420, 180, 140, 240); + checkPosition(links[3], 420, 280, 410, 301); + checkPosition(links[4], 410, 340, 410, 400); + checkPosition(links[5], 410, 400, 690, 500); + checkPosition(links[6], 130, 401, 410, 580); + } + + @Test + public void testAnchorUpdateOnMessages() { + // Move a message + ReconnectRequest request = new ReconnectRequest(RequestConstants.REQ_RECONNECT_SOURCE); + request.setConnectionEditPart(message1); + + Point sourceLocation = ((PolylineConnection) message1.getConnectionFigure()).getStart().getCopy(); + sourceLocation.setY(sourceLocation.y() - 40); + // sourceLocation.setX(sourceLocation.x() + 3); // Move slightly to the right, to make sure we hover the lifeline and not the exec spec + request.setLocation(sourceLocation); + + EditPart targetEditPart = lifeline1.getTargetEditPart(request); + request.setTargetEditPart(targetEditPart); + + editor.execute(targetEditPart.getCommand(request)); + + // Check that the duration link follows + /** + * FIXME: newStartX should be 140, but the Message Reconnect is incorrect, and the DurationLink simply follows + * The Message Start Anchor is moved to the left side of the ExecSpec, instead of the right side. + * When the MessageReconnect bug is fixed, this should be changed back to 140 + */ + int newStartX = 120; + checkPosition(links[1], newStartX, 140, 400, 180); + } + + @Test + public void testAnchorUpdateOnExecSpec() { + // Move an ExecutionSpecification + ChangeBoundsRequest request = new ChangeBoundsRequest(RequestConstants.REQ_MOVE); + request.setEditParts(exec1); + request.setMoveDelta(new Point(0, 40)); + + Point center = exec1.getFigure().getBounds().getCenter().getCopy(); + center.setY(center.y() + 40); + request.setLocation(center); // Probably doesn't matter + + // By default, messages located below an ExecSpec will move with it. We don't want that here. + disableMoveMessages(request, exec1); + + EditPart targetPart = exec1.getTargetEditPart(request); + editor.execute(targetPart.getCommand(request)); + + // Check that the duration links (1 and 7) follow + checkPosition(links[0], 130, 140, 410, 160); + checkPosition(links[6], 130, 440, 410, 580); + } + + private void disableMoveMessages(ChangeBoundsRequest request, IGraphicalEditPart editPart) { + // Unfortunately, there is no request constant to specify this; this is done via a Keyboard + // listener installed on a specific EditPolicy, so we have to fake the Shift key-press + EditPolicy editPolicy = editPart.getEditPolicy(UpdateWeakReferenceForExecSpecEditPolicy.UDPATE_WEAK_REFERENCE_FOR_EXECSPEC); + ((UpdateWeakReferenceForExecSpecEditPolicy) editPolicy).setKeyPressState(true); + } + + @Test + public void testAnchorUpdateOnDestruction() { + // Move a DestructionOccurrence. Note: it's currently not possible to move the Destruction directly, + // so we move the lifeline horizontally instead. + ChangeBoundsRequest request = new ChangeBoundsRequest(RequestConstants.REQ_MOVE); + request.setEditParts(lifeline3); // Lifeline3 owns a DestructionOccurrenceSpecification + request.setMoveDelta(new Point(120, 0)); + + Point center = lifeline3.getFigure().getBounds().getCenter().getCopy(); + center.setX(center.x() + 120); + request.setLocation(center); // Probably doesn't matter + + EditPart targetPart = lifeline3.getTargetEditPart(request); + editor.execute(targetPart.getCommand(request)); + + // Check that the duration link follows + checkPosition(links[5], 410, 400, 810, 500); + } + + @Test + @SuppressWarnings("unchecked") + public void testLinkDisappearOnSemanticChange() { + T link = (T) EMFHelper.getEObject(links[0]); + + // First change doesn't change source/target; the link should remain + doUnrelatedChange(link); + Assert.assertTrue("The edit part for " + linkNames[0] + " should still be active", links[0].isActive()); + + // Second change modifies the target; the link should be deleted + doChangeTarget(link); + checkDeleted(links[0]); + } + + /** + * Execute a semantic change on the given link that doesn't affect + * its source or target + * + * @param linkToChange + */ + protected abstract void doUnrelatedChange(T linkToChange); + + /** + * Execute a semantic change on the given link that modifies its target + * + * @param linkToChange + */ + protected abstract void doChangeTarget(T linkToChange); + + @Test + public void testLinkDisappearOnAnchorageChange() { + editor.delete(message1); + checkDeleted(links[1]); + + editor.delete(exec3); + checkDeleted(links[2]); + checkDeleted(links[3]); + + editor.delete(destruction); + checkDeleted(links[5]); + checkDeleted(links[4]); // This is indirect: the deletion of the Destruction removes the Delete Message as well, on which link5 is anchored + + // Other durations are still present & active + Assert.assertTrue(linkNames[0] + " should still be active", links[0].isActive()); + Assert.assertTrue(linkNames[6] + " should still be active", links[6].isActive()); + } + + private static void checkDeleted(EditPart editPart) { + Assert.assertFalse("The edit part should be destroyed", editPart.isActive()); + View view = (View) editPart.getModel(); + Assert.assertNull("The edit part's view should no longer be contained in the model", view.eContainer()); + } + + private static void checkPosition(ConnectionNodeEditPart connection, int startX, int startY, int endX, int endY) { + PolylineConnection polyline = (PolylineConnection) connection.getConnectionFigure(); + int[] expected = new int[] { startX, startY, endX, endY }; + + Point start = absolute(polyline, polyline.getStart()); + Point end = absolute(polyline, polyline.getEnd()); + int[] actual = new int[] { start.x(), start.y(), end.x(), end.y() }; + + Assert.assertThat(actual, IsEqual.equalTo(expected)); + } + + private static Point absolute(IFigure reference, Point pointInReference) { + Point result = pointInReference.getCopy(); + reference.translateToAbsolute(result); + return result; + } + + private static void checkFixedAnchors(ConnectionNodeEditPart connection, Class sourceAnchor, Class targetAnchor) { + String connectionName = ((NamedElement) EMFHelper.getEObject(connection)).getName(); + + Assert.assertThat("Invalid source anchor for " + connectionName, connection.getConnectionFigure().getSourceAnchor(), IsInstanceOf.instanceOf(sourceAnchor)); + Assert.assertThat("Invalid target anchor for " + connectionName, connection.getConnectionFigure().getTargetAnchor(), IsInstanceOf.instanceOf(targetAnchor)); + } +} diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/BugTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/BugTests.java index 33c4a3fa01b..b46ee3d313a 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/BugTests.java +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/BugTests.java @@ -41,6 +41,12 @@ import org.junit.runners.Suite.SuiteClasses; TestCFOperandsCoveredNodes.class, TestCFOperandsSemanticCoverage.class, TestCFOperandsReorder.class, + TestDurationConstraintDisplay.class, + TestDurationObservationDisplay.class, + TestGeneralOrderingDisplay.class, + DurationConstraintCreationTest.class, + DurationObservationCreationTest.class, + GeneralOrderingCreationTest.class, }) public class BugTests { diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/DurationConstraintCreationTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/DurationConstraintCreationTest.java new file mode 100644 index 00000000000..7415acafe78 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/DurationConstraintCreationTest.java @@ -0,0 +1,43 @@ +/***************************************************************************** + * Copyright (c) 2018 CEA LIST, EclipseSource 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: + * EclipseSource - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.sequence.tests.bug; + +import org.eclipse.papyrus.junit.utils.rules.ActiveDiagram; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.papyrus.uml.diagram.sequence.figures.DurationLinkFigure; +import org.eclipse.uml2.uml.DurationConstraint; +import org.eclipse.uml2.uml.Element; + +/** + * Creation test for DurationConstraintLinks + */ +@PluginResource({ "resource/bugs/bug536631-durationLinksCreation.di", "resource/bugs/style.css" }) +@ActiveDiagram("durationLinksCreation") +public class DurationConstraintCreationTest extends AbstractOccurrenceLinkCreationTest { + + public DurationConstraintCreationTest() { + super(DurationConstraint.class, "createDurationConstraintEdgeTool", DurationLinkFigure.class); + } + + @Override + protected Element getSemanticSource(DurationConstraint link) { + return link.getConstrainedElements().get(0); + } + + @Override + protected Element getSemanticTarget(DurationConstraint link) { + return link.getConstrainedElements().size() > 1 ? link.getConstrainedElements().get(1) : link.getConstrainedElements().get(0); + } + +} diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/DurationObservationCreationTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/DurationObservationCreationTest.java new file mode 100644 index 00000000000..59ac3a0cc1b --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/DurationObservationCreationTest.java @@ -0,0 +1,43 @@ +/***************************************************************************** + * Copyright (c) 2018 CEA LIST, EclipseSource 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: + * EclipseSource - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.sequence.tests.bug; + +import org.eclipse.papyrus.junit.utils.rules.ActiveDiagram; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.papyrus.uml.diagram.sequence.figures.DurationLinkFigure; +import org.eclipse.uml2.uml.DurationObservation; +import org.eclipse.uml2.uml.Element; + +/** + * Creation test for DurationObservationLinks + */ +@PluginResource({ "resource/bugs/bug536631-durationLinksCreation.di", "resource/bugs/style.css" }) +@ActiveDiagram("durationLinksCreation") +public class DurationObservationCreationTest extends AbstractOccurrenceLinkCreationTest { + + public DurationObservationCreationTest() { + super(DurationObservation.class, "createDurationObservationEdgeTool", DurationLinkFigure.class); + } + + @Override + protected Element getSemanticSource(DurationObservation link) { + return link.getEvents().get(0); + } + + @Override + protected Element getSemanticTarget(DurationObservation link) { + return link.getEvents().size() > 1 ? link.getEvents().get(1) : link.getEvents().get(0); + } + +} diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/GeneralOrderingCreationTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/GeneralOrderingCreationTest.java new file mode 100644 index 00000000000..262d07caa04 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/GeneralOrderingCreationTest.java @@ -0,0 +1,43 @@ +/***************************************************************************** + * Copyright (c) 2018 CEA LIST, EclipseSource 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: + * EclipseSource - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.sequence.tests.bug; + +import org.eclipse.papyrus.junit.utils.rules.ActiveDiagram; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.papyrus.uml.diagram.sequence.figures.GeneralOrderingDescriptor; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.GeneralOrdering; + +/** + * Creation test for GeneralOrdering Links + */ +@PluginResource({ "resource/bugs/bug536631-durationLinksCreation.di", "resource/bugs/style.css" }) +@ActiveDiagram("durationLinksCreation") +public class GeneralOrderingCreationTest extends AbstractOccurrenceLinkCreationTest { + + public GeneralOrderingCreationTest() { + super(GeneralOrdering.class, "createGeneralOrdering8CreationTool", GeneralOrderingDescriptor.class); + } + + @Override + protected Element getSemanticSource(GeneralOrdering link) { + return link.getBefore(); + } + + @Override + protected Element getSemanticTarget(GeneralOrdering link) { + return link.getAfter(); + } + +} diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestDurationConstraintDisplay.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestDurationConstraintDisplay.java new file mode 100644 index 00000000000..fb12695f6e4 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestDurationConstraintDisplay.java @@ -0,0 +1,72 @@ +/***************************************************************************** + * Copyright (c) 2018 CEA LIST, EclipseSource 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: + * EclipseSource - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.sequence.tests.bug; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; +import org.eclipse.papyrus.junit.utils.rules.ActiveDiagram; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.papyrus.uml.diagram.sequence.figures.DurationLinkFigure; +import org.eclipse.uml2.uml.DurationConstraint; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.UMLPackage.Literals; + +/** + * Test class to verify that DurationConstraint links are properly displayed, and properly + * react to changes in the diagram around them (Visual or semantic). + */ +@PluginResource({ "resource/bugs/bug536631-durationLinks.di", "resource/bugs/style.css" }) +@ActiveDiagram("durationConstraintsLinksTest") +public class TestDurationConstraintDisplay extends AbstractOccurrenceLinkTest { + + public TestDurationConstraintDisplay() { + super(new String[] { + "DurationConstraint1", + "DurationConstraint2", + "DurationConstraint3", + "DurationConstraint4", + "DurationConstraint5", + "DurationConstraint6", + "DurationConstraint7", + }, DurationConstraint.class, DurationLinkFigure.class); + } + + @Override + protected void doUnrelatedChange(DurationConstraint linkToChange) { + DurationConstraint duration2 = (DurationConstraint) EMFHelper.getEObject(links[1]); + + List values = new ArrayList<>(linkToChange.getConstrainedElements()); + values.add(duration2.getConstrainedElements().get(1)); + + IElementEditService provider = ElementEditServiceUtils.getCommandProvider(linkToChange); + SetRequest request = new SetRequest(linkToChange, Literals.CONSTRAINT__CONSTRAINED_ELEMENT, values); + editor.execute(provider.getEditCommand(request)); + } + + @Override + protected void doChangeTarget(DurationConstraint linkToChange) { + List values = new ArrayList<>(linkToChange.getConstrainedElements()); + values.remove(1); + + IElementEditService provider = ElementEditServiceUtils.getCommandProvider(linkToChange); + SetRequest request = new SetRequest(linkToChange, Literals.CONSTRAINT__CONSTRAINED_ELEMENT, values); + editor.execute(provider.getEditCommand(request)); + } + +} diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestDurationObservationDisplay.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestDurationObservationDisplay.java new file mode 100644 index 00000000000..3c2fdc08be2 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestDurationObservationDisplay.java @@ -0,0 +1,73 @@ +/***************************************************************************** + * Copyright (c) 2018 CEA LIST, EclipseSource 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: + * EclipseSource - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.sequence.tests.bug; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; +import org.eclipse.papyrus.junit.utils.rules.ActiveDiagram; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.papyrus.uml.diagram.sequence.figures.DurationLinkFigure; +import org.eclipse.uml2.uml.DurationObservation; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.UMLPackage.Literals; + +/** + * Test class to verify that DurationObservation links are properly displayed, and properly + * react to changes in the diagram around them (Visual or semantic). + */ +@PluginResource({ "resource/bugs/bug536631-durationLinks.di", "resource/bugs/style.css" }) +@ActiveDiagram("durationObservationsLinksTest") +public class TestDurationObservationDisplay extends AbstractOccurrenceLinkTest { + + public TestDurationObservationDisplay() { + super(new String[] { + "DurationObservation1", + "DurationObservation2", + "DurationObservation3", + "DurationObservation4", + "DurationObservation5", + "DurationObservation6", + "DurationObservation7" + }, DurationObservation.class, + DurationLinkFigure.class); + } + + @Override + protected void doUnrelatedChange(DurationObservation linkToChange) { + DurationObservation duration2 = (DurationObservation) EMFHelper.getEObject(links[1]); + + List values = new ArrayList<>(linkToChange.getEvents()); + values.add(duration2.getEvents().get(1)); + + IElementEditService provider = ElementEditServiceUtils.getCommandProvider(linkToChange); + SetRequest request = new SetRequest(linkToChange, Literals.DURATION_OBSERVATION__EVENT, values); + editor.execute(provider.getEditCommand(request)); + } + + @Override + protected void doChangeTarget(DurationObservation linkToChange) { + List values = new ArrayList<>(linkToChange.getEvents()); + values.remove(1); + + IElementEditService provider = ElementEditServiceUtils.getCommandProvider(linkToChange); + SetRequest request = new SetRequest(linkToChange, Literals.DURATION_OBSERVATION__EVENT, values); + editor.execute(provider.getEditCommand(request)); + } + +} diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestGeneralOrderingDisplay.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestGeneralOrderingDisplay.java new file mode 100644 index 00000000000..8c836a832d2 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/TestGeneralOrderingDisplay.java @@ -0,0 +1,65 @@ +/***************************************************************************** + * Copyright (c) 2018 CEA LIST, EclipseSource 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: + * EclipseSource - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.uml.diagram.sequence.tests.bug; + +import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; +import org.eclipse.papyrus.junit.utils.rules.ActiveDiagram; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.papyrus.uml.diagram.sequence.figures.GeneralOrderingDescriptor; +import org.eclipse.uml2.uml.GeneralOrdering; +import org.eclipse.uml2.uml.UMLPackage.Literals; + +/** + * Test class to verify that DurationObservation links are properly displayed, and properly + * react to changes in the diagram around them (Visual or semantic). + */ +@PluginResource({ "resource/bugs/bug536631-durationLinks.di", "resource/bugs/style.css" }) +@ActiveDiagram("generalOrderingLinksTest") +public class TestGeneralOrderingDisplay extends AbstractOccurrenceLinkTest { + + public TestGeneralOrderingDisplay() { + super(new String[] { + "GeneralOrdering1", + "GeneralOrdering2", + "GeneralOrdering3", + "GeneralOrdering4", + "GeneralOrdering5", + "GeneralOrdering6", + "GeneralOrdering7" + }, GeneralOrdering.class, + GeneralOrderingDescriptor.class); + } + + @Override + protected void doUnrelatedChange(GeneralOrdering linkToChange) { + // Rename the GeneralOrdering (This part of the test doesn't make much sense for GO; it + // was mostly designed for DurationLinks, which use a generic list to hold their source/target) + IElementEditService provider = ElementEditServiceUtils.getCommandProvider(linkToChange); + SetRequest request = new SetRequest(linkToChange, Literals.NAMED_ELEMENT__NAME, linkToChange.getName() + "Renamed"); + editor.execute(provider.getEditCommand(request)); + } + + @Override + protected void doChangeTarget(GeneralOrdering linkToChange) { + GeneralOrdering ordering2 = (GeneralOrdering) EMFHelper.getEObject(links[1]); + + IElementEditService provider = ElementEditServiceUtils.getCommandProvider(linkToChange); + SetRequest request = new SetRequest(linkToChange, Literals.GENERAL_ORDERING__AFTER, ordering2.getAfter()); + editor.execute(provider.getEditCommand(request)); + } + +} -- cgit v1.2.3