Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorcletavernie2013-04-29 05:06:04 -0400
committercletavernie2013-04-29 05:06:04 -0400
commit3dd746d03f9c8434a6c3725cd63b1cb7b1e9f9b7 (patch)
tree23dfed4b043619638b897dd1a6a7fd5b80bb6c1b /tests
parent6dfdfb1a408bea78711ad1ccdcc081b722155ee6 (diff)
downloadorg.eclipse.papyrus-3dd746d03f9c8434a6c3725cd63b1cb7b1e9f9b7.tar.gz
org.eclipse.papyrus-3dd746d03f9c8434a6c3725cd63b1cb7b1e9f9b7.tar.xz
org.eclipse.papyrus-3dd746d03f9c8434a6c3725cd63b1cb7b1e9f9b7.zip
402980: [Sequence Diagram] Develop JUnit tests for new bugs and features
https://bugs.eclipse.org/bugs/show_bug.cgi?id=402980
Diffstat (limited to 'tests')
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/AbstractNodeTest.java221
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestDurationConstraint_402967.java463
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestExecutionSpecificationPosition_395462.java1
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGraphicalGate_389531.java843
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGuardVisibility_402966.java76
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestMessageCreateWithLifeline_403134.java48
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestTooltip_402964.java353
7 files changed, 1934 insertions, 71 deletions
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/AbstractNodeTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/AbstractNodeTest.java
index d0c810e3346..d3f089a1879 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/AbstractNodeTest.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/AbstractNodeTest.java
@@ -13,33 +13,55 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.tests.bug.m7;
+import java.util.Collections;
import java.util.List;
+import java.util.Map.Entry;
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.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef.requests.ReconnectRequest;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
+import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.commands.ICreationCommand;
import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
import org.eclipse.papyrus.uml.diagram.sequence.tests.canonical.CreateSequenceDiagramCommand;
import org.eclipse.papyrus.uml.diagram.sequence.tests.canonical.TestTopNode;
+import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceRequestConstant;
+import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceUtil;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.intro.IIntroManager;
import org.eclipse.ui.intro.IIntroPart;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.OccurrenceSpecification;
+import org.eclipse.uml2.uml.UMLPackage;
/**
* @author Jin Liu (jin.liu@soyatec.com)
@@ -87,6 +109,20 @@ public abstract class AbstractNodeTest extends TestTopNode {
Display.getDefault().syncExec(runnable);
}
+ protected EditPart createNode(IElementType type, EditPartViewer viewer, Point location, Dimension size) {
+ assertNotNull(type);
+ assertNotNull(viewer);
+ assertNotNull(location);
+ CreateViewRequest createReq = CreateViewRequestFactory.getCreateShapeRequest(type, getRootEditPart().getDiagramPreferencesHint());
+ createReq.setLocation(location);
+ createReq.setSize(size);
+ EditPart parentEditPart = viewer.findObjectAtExcluding(location, Collections.emptySet(), getTargetingConditional(createReq));
+ assertNotNull("Could not create " + type + " at " + location, parentEditPart);
+ EditPart targetEditPart = parentEditPart.getTargetEditPart(createReq);
+ assertNotNull("Could not create " + type + " at " + location, targetEditPart);
+ return createNode(type, targetEditPart, location, size);
+ }
+
protected EditPart createNode(IElementType type, EditPart parentPart, Point location, Dimension size) {
//CREATION
CreateViewRequest createReq = CreateViewRequestFactory.getCreateShapeRequest(type, getRootEditPart().getDiagramPreferencesHint());
@@ -145,4 +181,187 @@ public abstract class AbstractNodeTest extends TestTopNode {
waitForComplete();
assertTrue(RESIZE + TEST_THE_REDO, after.equals(getAbsoluteBounds(op)));
}
+
+ protected Command createSetCommand(TransactionalEditingDomain editingDomain, EObject eObject, EStructuralFeature feature, Object value) {
+ if(editingDomain == null || eObject == null || feature == null) {
+ return null;
+ }
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(eObject);
+ SetRequest request = new SetRequest(editingDomain, eObject, feature, value);
+ ICommand editCommand = provider.getEditCommand(request);
+ if(editCommand == null) {
+ return null;
+ }
+ return new ICommandProxy(editCommand);
+ }
+
+ protected void updateValue(TransactionalEditingDomain editingDomain, EObject eObject, EStructuralFeature feature, Object value) {
+ Command setCommand = createSetCommand(editingDomain, eObject, feature, value);
+ assertNotNull("Update Value: ", setCommand);
+ assertTrue("Executable to set value:", setCommand.canExecute());
+ getDiagramCommandStack().execute(setCommand);
+ waitForComplete();
+ assertEquals(value, eObject.eGet(feature));
+ }
+
+ protected void changeName(TransactionalEditingDomain editingDomain, NamedElement element, final String newName) {
+ Command command = createSetCommand(editingDomain, element, UMLPackage.Literals.NAMED_ELEMENT__NAME, newName);
+ assertNotNull(COMMAND_NULL, command);
+ assertTrue(command.canExecute());
+ getDiagramCommandStack().execute(command);
+ waitForComplete();
+ }
+
+ protected EditPart createLink(IElementType elementType, EditPartViewer currentViewer, Point startLocation, Point endLocation) {
+ assertNotNull("IElementType is null: ", elementType);
+ assertNotNull("EditPartViewer is null: ", currentViewer);
+ assertNotNull("Start Location is null: ", startLocation);
+ assertNotNull("End Location is null: ", endLocation);
+ CreateConnectionViewRequest request = CreateViewRequestFactory.getCreateConnectionRequest(elementType, ((IGraphicalEditPart)getDiagramEditPart()).getDiagramPreferencesHint());
+ request.setLocation(startLocation);
+ request.setType(RequestConstants.REQ_CONNECTION_START);
+ EditPart sourceEditPart = currentViewer.findObjectAtExcluding(startLocation, Collections.emptySet(), getTargetingConditional(request));
+ request.setTargetEditPart(sourceEditPart);
+ request.setSourceEditPart(sourceEditPart);
+ sourceEditPart.getCommand(request);
+ request.setLocation(endLocation);
+ request.setType(RequestConstants.REQ_CONNECTION_END);
+ EditPart targetEditPart = currentViewer.findObjectAtExcluding(endLocation, Collections.emptySet(), getTargetingConditional(request));;
+ return createLink(elementType, currentViewer, startLocation, sourceEditPart, endLocation, targetEditPart);
+ }
+
+ protected EditPart createLink(IElementType elementType, EditPartViewer currentViewer, Point startLocation, EditPart sourceEditPart, Point endLocation, EditPart targetEditPart) {
+ assertNotNull("IElementType is null: ", elementType);
+ assertNotNull("EditPartViewer is null: ", currentViewer);
+ assertNotNull("Start Location is null: ", startLocation);
+ assertNotNull("End Location is null: ", endLocation);
+ assertNotNull("SourceEditPart is null: ", sourceEditPart);
+ assertNotNull("TargetEditPart is null: ", targetEditPart);
+ CreateConnectionViewRequest request = CreateViewRequestFactory.getCreateConnectionRequest(elementType, ((IGraphicalEditPart)getDiagramEditPart()).getDiagramPreferencesHint());
+ assertNotNull("Can not create link with " + elementType, request);
+ request.setLocation(startLocation);
+ request.setType(RequestConstants.REQ_CONNECTION_START);
+ // sourceEditPart = currentViewer.findObjectAtExcluding(startLocation, Collections.emptySet(), getTargetingConditional(request));
+ assertNotNull("Can not find connecting source at " + startLocation, sourceEditPart);
+ request.setSourceEditPart(sourceEditPart);
+ request.setTargetEditPart(sourceEditPart);
+ request.getExtendedData().put(SequenceRequestConstant.SOURCE_MODEL_CONTAINER, SequenceUtil.findInteractionFragmentContainerAt(startLocation, sourceEditPart));
+ Command command = null;
+ if(UMLElementTypes.GeneralOrdering_4012 == elementType) {
+ LifelineEditPart lifelinePart = sourceEditPart instanceof ConnectionEditPart ? SequenceUtil.getParentLifelinePart(((ConnectionEditPart)sourceEditPart).getSource()) : SequenceUtil.getParentLifelinePart(sourceEditPart);
+ assertNotNull(lifelinePart);
+ Entry<Point, List<OccurrenceSpecification>> eventAndLocation = SequenceUtil.findNearestEvent(request.getLocation(), lifelinePart);
+ // find an event near enough to create the constraint or observation
+ List<OccurrenceSpecification> events = Collections.emptyList();
+ Point location = null;
+ if(eventAndLocation != null) {
+ location = eventAndLocation.getKey();
+ events = eventAndLocation.getValue();
+ }
+ request.getExtendedData().put(SequenceRequestConstant.NEAREST_OCCURRENCE_SPECIFICATION, events);
+ request.getExtendedData().put(SequenceRequestConstant.OCCURRENCE_SPECIFICATION_LOCATION, location);
+ if(location != null) {
+ request.setLocation(location);
+ }
+ request.setSourceEditPart(lifelinePart);
+ request.setTargetEditPart(lifelinePart);
+ command = lifelinePart.getCommand(request);
+ } else {
+ sourceEditPart.showTargetFeedback(request);
+ command = sourceEditPart.getCommand(request);
+ sourceEditPart.eraseSourceFeedback(request);
+ }
+ assertNotNull(COMMAND_NULL, command);
+ //connect...
+ request.setLocation(endLocation);
+ request.setType(RequestConstants.REQ_CONNECTION_END);
+ // targetEditPart = currentViewer.findObjectAtExcluding(endLocation, Collections.emptySet(), getTargetingConditional(request));
+ assertNotNull("Can not find connecting end at " + endLocation, targetEditPart);
+ request.setTargetEditPart(targetEditPart);
+ request.getExtendedData().put(SequenceRequestConstant.TARGET_MODEL_CONTAINER, SequenceUtil.findInteractionFragmentContainerAt(endLocation, targetEditPart));
+ if(UMLElementTypes.GeneralOrdering_4012 == elementType) {
+ LifelineEditPart lifelinePart = targetEditPart instanceof ConnectionEditPart ? SequenceUtil.getParentLifelinePart(((ConnectionEditPart)targetEditPart).getTarget()) : SequenceUtil.getParentLifelinePart(targetEditPart);
+ assertNotNull(lifelinePart);
+ Entry<Point, List<OccurrenceSpecification>> eventAndLocation = SequenceUtil.findNearestEvent(request.getLocation(), lifelinePart);
+ // find an event near enough to create the constraint or observation
+ List<OccurrenceSpecification> events = Collections.emptyList();
+ Point location = null;
+ if(eventAndLocation != null) {
+ location = eventAndLocation.getKey();
+ events = eventAndLocation.getValue();
+ }
+ request.getExtendedData().put(SequenceRequestConstant.NEAREST_OCCURRENCE_SPECIFICATION_2, events);
+ request.getExtendedData().put(SequenceRequestConstant.OCCURRENCE_SPECIFICATION_LOCATION_2, location);
+ if(location != null) {
+ request.setLocation(location);
+ }
+ request.setTargetEditPart(lifelinePart);
+ command = lifelinePart.getCommand(request);
+ } else {
+ targetEditPart.showTargetFeedback(request);
+ command = targetEditPart.getCommand(request);
+ targetEditPart.eraseSourceFeedback(request);
+ }
+ assertNotNull(COMMAND_NULL, command);
+ assertTrue("Executable of connection command", command.canExecute());
+ getDiagramCommandStack().execute(command);
+ waitForComplete();
+ //check result
+ View view = (View)request.getConnectionViewDescriptor().getAdapter(View.class);
+ assertNotNull("view not found", view);
+ return (EditPart)currentViewer.getEditPartRegistry().get(view);
+ }
+
+ protected EditPartViewer.Conditional getTargetingConditional(final Request req) {
+ return new EditPartViewer.Conditional() {
+
+ public boolean evaluate(EditPart editpart) {
+ return editpart.getTargetEditPart(req) != null;
+ }
+ };
+ }
+
+ protected void reconnectSource(ConnectionEditPart conn, EditPart newSource, Point newSourceLocation) {
+ assertNotNull("reconnect connection", conn);
+ assertNotNull("reconnect source", newSource);
+ ReconnectRequest request = new ReconnectRequest(RequestConstants.REQ_RECONNECT_SOURCE) {
+
+ @Override
+ public boolean isMovingStartAnchor() {
+ return true;
+ }
+ };
+ request.setConnectionEditPart(conn);
+ request.setTargetEditPart(newSource);
+ request.setLocation(newSourceLocation);
+ Command command = newSource.getCommand(request);
+ assertNotNull("reconnect command", command);
+ assertTrue("reconnect command executable", command.canExecute());
+ getDiagramCommandStack().execute(command);
+ waitForComplete();
+ }
+
+ protected void reconnectTarget(ConnectionEditPart conn, EditPart newTarget, Point newTargetLocation) {
+ assertNotNull("reconnect connection", conn);
+ assertNotNull("reconnect source", newTarget);
+ ReconnectRequest request = new ReconnectRequest(RequestConstants.REQ_RECONNECT_TARGET) {
+
+ @Override
+ public boolean isMovingStartAnchor() {
+ return false;
+ }
+ };
+ request.setConnectionEditPart(conn);
+ request.setTargetEditPart(newTarget);
+ request.setLocation(newTargetLocation);
+ newTarget.showSourceFeedback(request);
+ newTarget.showTargetFeedback(request);
+ Command command = newTarget.getCommand(request);
+ newTarget.eraseSourceFeedback(request);
+ newTarget.eraseTargetFeedback(request);
+ assertNotNull("reconnect command", command);
+ assertTrue("reconnect command executable", command.canExecute());
+ getDiagramCommandStack().execute(command);
+ waitForComplete();
+ }
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestDurationConstraint_402967.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestDurationConstraint_402967.java
new file mode 100644
index 00000000000..618fb4707fe
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestDurationConstraint_402967.java
@@ -0,0 +1,463 @@
+package org.eclipse.papyrus.uml.diagram.sequence.tests.bug.m7;
+
+import java.util.Collections;
+
+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.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef.requests.DirectEditRequest;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
+import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractExecutionSpecificationEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CommentAnnotatedElementEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.DurationConstraintEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.DurationConstraintLabelEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.ExecutionSpecificationEndEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageEndEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.tools.utils.ValueSpecificationUtil;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Widget;
+import org.eclipse.uml2.uml.DurationConstraint;
+import org.eclipse.uml2.uml.Interval;
+import org.eclipse.uml2.uml.MessageEnd;
+import org.eclipse.uml2.uml.OccurrenceSpecification;
+import org.eclipse.uml2.uml.ValueSpecification;
+import org.junit.Test;
+
+public class TestDurationConstraint_402967 extends AbstractNodeTest {
+ public static final String REQ_ANNOTATED_LINK_END = "annotated link end";
+
+ public static final String REQ_ANNOTATED_LINK_START = "annotated link start";
+
+ private static final String MOVE = "Move";
+
+ private static final String EDIT = "Edit: ";
+
+ private static final String SEP = "..";
+
+ @Test
+ public void testDurationCreation() {
+ DurationConstraintEditPart dc = (DurationConstraintEditPart)createNode(UMLElementTypes.DurationConstraint_3021, getRootEditPart(), new Point(400, 200), null);
+ assertNotNull(dc);
+ assertTrue(CREATION + TEST_THE_EXECUTION, getRootEditPart().getChildren().size() == 1);
+
+ // undo
+ assertTrue(CREATION + TEST_THE_UNDO, getDiagramCommandStack().canUndo());
+ getEMFCommandStack().undo();
+ assertTrue(CREATION + TEST_THE_UNDO, getRootEditPart().getChildren().size() == 0);
+
+ // redo
+ assertTrue(CREATION + TEST_THE_REDO, getDiagramCommandStack().canRedo());
+ getEMFCommandStack().redo();
+ assertTrue(CREATION + TEST_THE_REDO, getRootEditPart().getChildren().size() == 1);
+ }
+
+ @Test
+ public void testDurationMoveResize() {
+ // test move
+ DurationConstraintEditPart dc = (DurationConstraintEditPart)createNode(UMLElementTypes.DurationConstraint_3021, getRootEditPart(), new Point(400, 200), null);
+ assertNotNull(dc);
+ moveEditPart(dc, new Point(50, 0));
+ moveEditPart(dc, new Point(-20, 0));
+
+ // test resize
+ int move = 30;
+ DurationConstraintEditPart dc2 = (DurationConstraintEditPart)createNode(UMLElementTypes.DurationConstraint_3021, getRootEditPart(), new Point(200, 100), null);
+ assertNotNull(dc2);
+ resize(dc2, getAbsoluteBounds(dc2).getLocation(), PositionConstants.NORTH, new Dimension(0, move));
+ resize(dc2, getAbsoluteBounds(dc2).getLocation(), PositionConstants.SOUTH, new Dimension(0, move));
+ waitForComplete();
+
+ DurationConstraintEditPart dc3 = (DurationConstraintEditPart)createNode(UMLElementTypes.DurationConstraint_3021, getRootEditPart(), new Point(300, 300), null);
+ assertNotNull(dc3);
+ resize(dc3, getAbsoluteBounds(dc3).getLocation(), PositionConstants.WEST, new Dimension(move, 0));
+ resize(dc3, getAbsoluteBounds(dc3).getLocation(), PositionConstants.EAST, new Dimension(move, 0));
+ }
+
+ @Test
+ // test direct edit of duration expression
+ public void testDurationEditExpr() {
+ DurationConstraintEditPart dp = (DurationConstraintEditPart)createNode(UMLElementTypes.DurationConstraint_3021, getRootEditPart(), new Point(400, 200), null);
+ assertNotNull(dp);
+
+ // edit text
+ WrappingLabel label = verifyEditText(dp, "1s", "2s");
+ assertTrue(EDIT + TEST_THE_EXECUTION, label.getText().contains("1s..2s"));
+
+ label = verifyEditText(dp, "d", "d+3");
+ assertTrue(EDIT + TEST_THE_EXECUTION, label.getText().contains("d..d+3"));
+
+ getEMFCommandStack().undo();
+ assertTrue(EDIT + TEST_THE_UNDO, label.getText().contains("1s..2s"));
+
+ label = verifyEditText(dp, "1", "1"); // same value which will only display one
+ assertTrue(EDIT + TEST_THE_EXECUTION, label.getText().contains("1") && !label.getText().contains(SEP));
+ }
+
+ @Test
+ // link to the top and bottom of execution specification on the single lifeline
+ public void testLinkingExecutionOnSameLifeline() {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(200, 100), null);
+ assertNotNull(lifeline);
+ AbstractExecutionSpecificationEditPart es = createExecutionSpecification(lifeline, new Point(231, 150), null);
+ assertNotNull(es);
+
+ DurationConstraintEditPart dc = (DurationConstraintEditPart)createNode(UMLElementTypes.DurationConstraint_3021, getRootEditPart(), new Point(400, 200), null);
+ assertNotNull(dc);
+
+ Point fromLocation = getAbsoluteBounds(dc).getTop();
+ Point toLocation = getAbsoluteBounds(es).getTop();
+ //start connection
+ CommentAnnotatedElementEditPart linkPart = createDurationLink(dc, fromLocation, toLocation);
+ assertTrue(dc.getSourceConnections().size() == 1);
+ EditPart target = linkPart.getTarget();
+ assertTrue("the target is not a ExecutionSpecificationEndEditPart", target instanceof ExecutionSpecificationEndEditPart);
+ OccurrenceSpecification start = (OccurrenceSpecification)((ExecutionSpecificationEndEditPart)target).getNotationView().getElement();
+ assertTrue("the target is not start end", start.getName().contains("ActionExecSpecStart"));
+
+ fromLocation = getAbsoluteBounds(dc).getBottom();
+ toLocation = getAbsoluteBounds(es).getBottom();
+ linkPart = createDurationLink(dc, fromLocation, toLocation);
+ assertTrue(dc.getSourceConnections().size() == 2);
+ target = linkPart.getTarget();
+ assertTrue("the target is not a ExecutionSpecificationEndEditPart", target instanceof ExecutionSpecificationEndEditPart);
+ OccurrenceSpecification end = (OccurrenceSpecification)((ExecutionSpecificationEndEditPart)target).getNotationView().getElement();
+ assertTrue("the target is not finish end", end.getName().contains("ActionExecSpecFinish"));
+
+ DurationConstraint constraint = (DurationConstraint)dc.getNotationView().getElement();
+ assertTrue("constraint elements count", constraint.getConstrainedElements().size() == 2);
+ assertTrue("constraint element ", constraint.getConstrainedElements().contains(start));
+ assertTrue("constraint element ", constraint.getConstrainedElements().contains(end));
+ }
+
+ @Test
+ // link to different execution specification on two lifeline
+ public void testLinkingExecutionOnTwoLifeline() {
+ LifelineEditPart lifeline1 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(200, 100), null);
+ assertNotNull(lifeline1);
+ AbstractExecutionSpecificationEditPart es1 = createExecutionSpecification(lifeline1, new Point(231, 150), null);
+ assertNotNull(es1);
+
+ LifelineEditPart lifeline2 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(400, 100), null);
+ assertNotNull(lifeline2);
+ AbstractExecutionSpecificationEditPart es2 = createExecutionSpecification(lifeline2, new Point(431, 150), null);
+ assertNotNull(es2);
+
+ DurationConstraintEditPart dc = (DurationConstraintEditPart)createNode(UMLElementTypes.DurationConstraint_3021, getRootEditPart(), new Point(350, 150), null);
+ assertNotNull(dc);
+
+ Point fromLocation = getAbsoluteBounds(dc).getTop();
+ Point toLocation = getAbsoluteBounds(es1).getTop();
+ //start connection
+ CommentAnnotatedElementEditPart linkPart = createDurationLink(dc, fromLocation, toLocation);
+ assertTrue(dc.getSourceConnections().size() == 1);
+ EditPart target = linkPart.getTarget();
+ assertTrue("the target is not a ExecutionSpecificationEndEditPart", target instanceof ExecutionSpecificationEndEditPart);
+ OccurrenceSpecification os = (OccurrenceSpecification)((ExecutionSpecificationEndEditPart)target).getNotationView().getElement();
+ assertTrue("the target is not start end", os.getName().contains("Start"));
+
+ fromLocation = getAbsoluteBounds(dc).getBottom();
+ toLocation = getAbsoluteBounds(es2).getBottom();
+ linkPart = createDurationLink(dc, fromLocation, toLocation);
+ assertTrue(dc.getSourceConnections().size() == 2);
+ target = linkPart.getTarget();
+ assertTrue("the target is not a ExecutionSpecificationEndEditPart", target instanceof ExecutionSpecificationEndEditPart);
+ os = (OccurrenceSpecification)((ExecutionSpecificationEndEditPart)target).getNotationView().getElement();
+ assertTrue("the target is not finish end", os.getName().contains("Finish"));
+ }
+
+ // link to different messages on two lifeline
+ @Test
+ public void testLinkingMessageOnTwoLifeline() {
+ LifelineEditPart lifeline1 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(200, 80), null);
+ assertNotNull(lifeline1);
+
+ LifelineEditPart lifeline2 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(400, 80), null);
+ assertNotNull(lifeline2);
+
+ DurationConstraintEditPart dc = (DurationConstraintEditPart)createNode(UMLElementTypes.DurationConstraint_3021, getRootEditPart(), new Point(300, 150), null);
+ assertNotNull(dc);
+ waitForComplete();
+
+ int offset = 40;
+ Point fromLocation = getAbsoluteBounds(lifeline1).getCenter().translate(0, -offset);
+ Point toLocation = getAbsoluteBounds(lifeline2).getCenter().translate(0, -offset);
+ createConnection(lifeline1.getViewer(), fromLocation, toLocation);
+
+ fromLocation = getAbsoluteBounds(lifeline1).getCenter().translate(0, offset);
+ toLocation = getAbsoluteBounds(lifeline2).getCenter().translate(0, offset);
+ createConnection(lifeline1.getViewer(), fromLocation, toLocation);
+
+ { // link duration top
+ fromLocation = getAbsoluteBounds(dc).getTop();
+ toLocation = getAbsoluteBounds(lifeline1).getCenter().translate(0, -offset);
+ CommentAnnotatedElementEditPart linkPart = createDurationLink(dc, fromLocation, toLocation);
+ assertTrue(dc.getSourceConnections().size() == 1); // increase link count
+
+ EditPart target = linkPart.getTarget();
+ assertTrue("the target is not a MessageEndEditPart", target instanceof MessageEndEditPart);
+ MessageEnd end2 = (MessageEnd)((MessageEndEditPart)target).getNotationView().getElement();
+ assertTrue("the target is not send end", end2.getName().contains("Send"));
+ }
+
+ { // link duration bottom
+ fromLocation = getAbsoluteBounds(dc).getBottom();
+ toLocation = getAbsoluteBounds(lifeline2).getCenter().translate(0, offset);
+ CommentAnnotatedElementEditPart linkPart = createDurationLink(dc, fromLocation, toLocation);
+ assertTrue(dc.getSourceConnections().size() == 2); // increase link count
+
+ EditPart target = linkPart.getTarget();
+ assertTrue("the target is not a MessageEndEditPart", target instanceof MessageEndEditPart);
+ MessageEnd end2 = (MessageEnd)((MessageEndEditPart)target).getNotationView().getElement();
+ assertTrue("the target is not receive end", end2.getName().contains("Recv"));
+ }
+ }
+
+ @Test
+ // duration link to message and execution
+ public void testLinkingExecutionMessageOnTwoLifeline() {
+ LifelineEditPart lifeline1 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(200, 80), null);
+ assertNotNull(lifeline1);
+
+ LifelineEditPart lifeline2 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(400, 80), null);
+ assertNotNull(lifeline2);
+
+ DurationConstraintEditPart dc = (DurationConstraintEditPart)createNode(UMLElementTypes.DurationConstraint_3021, getRootEditPart(), new Point(300, 150), null);
+ assertNotNull(dc);
+ waitForComplete();
+
+ int offset = 40;
+ Point fromLocation = getAbsoluteBounds(lifeline1).getCenter().translate(0, -offset);
+ Point toLocation = getAbsoluteBounds(lifeline2).getCenter().translate(0, -offset);
+ createConnection(lifeline1.getViewer(), fromLocation, toLocation);
+
+ AbstractExecutionSpecificationEditPart es = createExecutionSpecification(lifeline2, new Point(231, 150), null);
+ assertNotNull(es);
+
+ { // link duration top
+ fromLocation = getAbsoluteBounds(dc).getTop();
+ toLocation = getAbsoluteBounds(lifeline1).getCenter().translate(0, -offset);
+ CommentAnnotatedElementEditPart linkPart = createDurationLink(dc, fromLocation, toLocation);
+ assertTrue(dc.getSourceConnections().size() == 1); // increase link count
+
+ EditPart target = linkPart.getTarget();
+ assertTrue("the target is not a MessageEndEditPart", target instanceof MessageEndEditPart);
+ MessageEnd end2 = (MessageEnd)((MessageEndEditPart)target).getNotationView().getElement();
+ assertTrue("the target is not send end", end2.getName().contains("Send"));
+ }
+
+ fromLocation = getAbsoluteBounds(dc).getBottom();
+ toLocation = getAbsoluteBounds(es).getBottom();
+ CommentAnnotatedElementEditPart linkPart = createDurationLink(dc, fromLocation, toLocation);
+ assertTrue(dc.getSourceConnections().size() == 2);
+ EditPart target = linkPart.getTarget();
+ assertTrue("the target is not a ExecutionSpecificationEndEditPart", target instanceof ExecutionSpecificationEndEditPart);
+ OccurrenceSpecification os = (OccurrenceSpecification)((ExecutionSpecificationEndEditPart)target).getNotationView().getElement();
+ assertTrue("the target is not finish end", os.getName().contains("Finish"));
+ }
+
+ private void createConnection(EditPartViewer viewer, Point fromLocation, Point toLocation) {
+ EditPart sourceEditPart = null;
+ EditPart targetEditPart = null;
+ CreateConnectionViewRequest request = CreateViewRequestFactory.getCreateConnectionRequest(UMLElementTypes.Message_4004, ((IGraphicalEditPart)getDiagramEditPart()).getDiagramPreferencesHint());
+ assertNotNull(request);
+ request.setLocation(fromLocation);
+ request.setType(RequestConstants.REQ_CONNECTION_START);
+ sourceEditPart = viewer.findObjectAtExcluding(fromLocation, Collections.emptySet(), getTargetingConditional(request));
+ assertNotNull(sourceEditPart);
+ request.setSourceEditPart(sourceEditPart);
+ request.setTargetEditPart(sourceEditPart);
+ Command command = sourceEditPart.getCommand(request);
+ assertNotNull(COMMAND_NULL, command);
+ //connect...
+
+ request.setLocation(toLocation);
+ request.setType(RequestConstants.REQ_CONNECTION_END);
+ targetEditPart = sourceEditPart.getViewer().findObjectAtExcluding(toLocation, Collections.emptySet(), getTargetingConditional(request));
+ assertNotNull(targetEditPart);
+ request.setTargetEditPart(targetEditPart);
+ targetEditPart.getCommand(request); // link by hand will call this method many times
+ waitForComplete();
+ command = targetEditPart.getCommand(request);
+ assertNotNull(COMMAND_NULL, command);
+
+ assertTrue(command.canExecute());
+ getDiagramCommandStack().execute(command);
+ waitForComplete();
+ }
+
+ private CommentAnnotatedElementEditPart createDurationLink(DurationConstraintEditPart dc,
+ Point fromLocation, Point toLocation) {
+ EditPart sourceEditPart = dc;
+ EditPart targetEditPart = null;
+ CreateConnectionViewRequest request = CreateViewRequestFactory.getCreateConnectionRequest(UMLElementTypes.CommentAnnotatedElement_4010, ((IGraphicalEditPart)getDiagramEditPart()).getDiagramPreferencesHint());
+ assertNotNull(request);
+ request.setLocation(fromLocation);
+ request.setType(REQ_ANNOTATED_LINK_START);
+ assertNotNull(sourceEditPart);
+ request.setSourceEditPart(sourceEditPart);
+ request.setTargetEditPart(sourceEditPart);
+ Command command = sourceEditPart.getCommand(request);
+ assertNotNull(COMMAND_NULL, command);
+ //connect...
+ request.setLocation(toLocation);
+ request.setType(REQ_ANNOTATED_LINK_END);
+ targetEditPart = sourceEditPart.getViewer().findObjectAtExcluding(toLocation, Collections.emptySet(), getTargetingConditional(request));
+ assertNotNull(targetEditPart);
+ request.setTargetEditPart(targetEditPart);
+ command = targetEditPart.getCommand(request);
+
+ int connectionCount = dc.getSourceConnections().size();
+ assertNotNull(COMMAND_NULL, command);
+ assertTrue(command.canExecute());
+ getDiagramCommandStack().execute(command);
+ waitForComplete();
+ assertTrue(connectionCount + 1 == dc.getSourceConnections().size()); // connection increase
+ // undo
+ getDiagramCommandStack().undo();
+ assertTrue(connectionCount == dc.getSourceConnections().size());
+ // redo
+ getDiagramCommandStack().redo();
+ assertTrue(connectionCount + 1 == dc.getSourceConnections().size());
+
+ //check result
+ View view = (View)request.getConnectionViewDescriptor().getAdapter(View.class);
+ assertNotNull("view not found", view);
+ EditPart editPart = (EditPart)targetEditPart.getViewer().getEditPartRegistry().get(view);
+ assertNotNull("editpart not found", editPart);
+ assertTrue("not a CommentAnnotatedElementEditPart", editPart instanceof CommentAnnotatedElementEditPart);
+
+ return (CommentAnnotatedElementEditPart)editPart;
+ }
+
+ protected WrappingLabel verifyEditText(DurationConstraintEditPart dp, String min, String max) {
+ DurationConstraintLabelEditPart lp = (DurationConstraintLabelEditPart)dp.getChildren().get(0);
+ WrappingLabel label = performEditRequest(lp);
+
+ Composite composite = (Composite)lp.getViewer().getControl();
+ Text editor = findEditor(composite, label);
+
+ editor.setText(min + SEP + max);
+ input(editor, SWT.CR);
+
+ DurationConstraint constraint = (DurationConstraint)dp.resolveSemanticElement();
+ ValueSpecification spec = constraint.getSpecification();
+ assertTrue(EDIT + TEST_THE_EXECUTION, min.equals(ValueSpecificationUtil.getSpecificationValue(((Interval)spec).getMin())));
+ assertTrue(EDIT + TEST_THE_EXECUTION, max.equals(ValueSpecificationUtil.getSpecificationValue(((Interval)spec).getMax())));
+
+ waitForComplete();
+ return label;
+ }
+
+ public WrappingLabel performEditRequest(LabelEditPart lp) {
+ WrappingLabel label = (WrappingLabel)lp.getFigure();
+ Rectangle b = label.getBounds().getCopy();
+ label.translateToAbsolute(b);
+ DirectEditRequest req = new DirectEditRequest();
+ req.setLocation(b.getCenter());
+ lp.performRequest(req);
+ return label;
+ }
+
+ public Text findEditor(Composite composite, WrappingLabel label) {
+ for(Control c : composite.getChildren()) {
+ if(c instanceof Text) {
+ if(label.getText().equals(((Text)c).getText())) {
+ return (Text)c;
+ }
+ }
+ }
+ return null;
+ }
+
+ public void input(Widget widget, char... character) {
+ if(widget.isDisposed()) {
+ return;
+ }
+
+ for(char c : character) {
+ Event e = createKeyEvent(widget, 0, c);
+ e.type = SWT.KeyDown;
+ widget.notifyListeners(SWT.KeyDown, e);
+
+ e = createKeyEvent(widget, 0, c);
+ e.type = SWT.KeyUp;
+ widget.notifyListeners(SWT.KeyUp, e);
+ }
+ waitForComplete();
+
+ Event e = new Event();
+ e.type = SWT.DefaultSelection;
+ widget.notifyListeners(SWT.DefaultSelection, e);
+ }
+
+ public Event createKeyEvent(Widget widget, int keyCode, char character) {
+ Event event = new Event();
+ event.time = (int)System.currentTimeMillis();
+ event.widget = widget;
+ event.display = Display.getDefault();
+ event.keyCode = keyCode;
+ event.character = character;
+ return event;
+ }
+
+
+ private AbstractExecutionSpecificationEditPart createExecutionSpecification(LifelineEditPart lifeline, Point location, Dimension size) {
+ return (AbstractExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, lifeline, location, size);
+ }
+
+ protected void moveEditPart(IGraphicalEditPart lifelineEP, Point moveDelta) {
+ ChangeBoundsRequest req = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
+ req.setResizeDirection(moveDelta.x > 0 ? PositionConstants.EAST : PositionConstants.WEST);
+ req.setLocation(getAbsoluteCenter(lifelineEP));
+ req.setEditParts(lifelineEP);
+ req.setMoveDelta(moveDelta);
+
+ Command command = lifelineEP.getCommand(req);
+ assertNotNull(MOVE + COMMAND_NULL, command);
+ assertTrue(MOVE + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute() == true);
+ Rectangle before = getAbsoluteBounds(lifelineEP);
+ getEMFCommandStack().execute(new GEFtoEMFCommandWrapper(command));
+ waitForComplete();
+
+ Rectangle after = getAbsoluteBounds(lifelineEP);
+ assertTrue(MOVE + TEST_THE_EXECUTION, after.x() - before.x() == moveDelta.x);
+ assertTrue(MOVE + TEST_THE_EXECUTION, after.y() - before.y() == moveDelta.y);
+
+ getEMFCommandStack().undo(); // undo move
+ waitForComplete();
+ assertTrue(MOVE + TEST_THE_UNDO, before.equals(getAbsoluteBounds(lifelineEP)));
+
+ getEMFCommandStack().redo(); // redo move
+ waitForComplete();
+ assertTrue(MOVE + TEST_THE_REDO, after.equals(getAbsoluteBounds(lifelineEP)));
+ }
+
+ protected EditPartViewer.Conditional getTargetingConditional(final Request req) {
+ return new EditPartViewer.Conditional() {
+
+ public boolean evaluate(EditPart editpart) {
+ return editpart.getTargetEditPart(req) != null;
+ }
+ };
+ }
+}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestExecutionSpecificationPosition_395462.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestExecutionSpecificationPosition_395462.java
index 9427ba9b802..05d508d7141 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestExecutionSpecificationPosition_395462.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestExecutionSpecificationPosition_395462.java
@@ -46,7 +46,6 @@ import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractExecutionSpec
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CustomLifelineEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
-import org.eclipse.papyrus.uml.diagram.sequence.tests.bug.PopupUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGraphicalGate_389531.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGraphicalGate_389531.java
new file mode 100644
index 00000000000..675bf178050
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGraphicalGate_389531.java
@@ -0,0 +1,843 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA
+ *
+ *
+ * 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:
+ * Soyatec - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.sequence.tests.bug.m7;
+
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.CreateRequest;
+import org.eclipse.gef.requests.CreationFactory;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractExecutionSpecificationEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractMessageEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.GateEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.GateNameEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionUseEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message2EditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.sequence.util.GateHelper;
+import org.eclipse.uml2.uml.CombinedFragment;
+import org.eclipse.uml2.uml.Gate;
+import org.eclipse.uml2.uml.Interaction;
+import org.eclipse.uml2.uml.Lifeline;
+import org.eclipse.uml2.uml.Message;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.junit.Test;
+
+/**
+ * Graphical Presentation of Gate with In/Out
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=389531
+ *
+ * @author Jin Liu (jin.liu@soyatec.com)
+ */
+public class TestGraphicalGate_389531 extends AbstractNodeTest {
+
+ private GateEditPart createGate(EditPart parent, Point location) {
+ CreateRequest request = new CreateRequest(RequestConstants.REQ_CREATE);
+ request.setFactory(new CreationFactory() {
+
+ public Object getObjectType() {
+ return GateEditPart.GATE_TYPE;
+ }
+
+ public Object getNewObject() {
+ return GateEditPart.GATE_TYPE;
+ }
+ });
+ request.setLocation(location);
+ Command command = parent.getCommand(request);
+ assertNotNull("create gate command", command);
+ assertTrue("executable of create gate command", command.canExecute());
+ getDiagramCommandStack().execute(command);
+ waitForComplete();
+ GateEditPart gateEditPart = getPrimaryGateEditPart(parent);
+ assertNotNull("created gate", gateEditPart);
+ return gateEditPart;
+ }
+
+ protected GateEditPart getGateEditPart(EditPart parent, Gate gate) {
+ @SuppressWarnings("rawtypes")
+ List children = parent.getChildren();
+ for(int i = children.size() - 1; i >= 0; i--) {
+ Object child = children.get(i);
+ if(child instanceof GateEditPart) {
+ GateEditPart gateEp = (GateEditPart)child;
+ if(gate == gateEp.resolveSemanticElement()) {
+ return gateEp;
+ }
+ }
+ }
+ return null;
+ }
+
+ protected GateEditPart getPrimaryGateEditPart(EditPart parent) {
+ @SuppressWarnings("rawtypes")
+ List children = parent.getChildren();
+ for(int i = children.size() - 1; i >= 0; i--) {
+ Object child = children.get(i);
+ if(child instanceof GateEditPart) {
+ GateEditPart gateEp = (GateEditPart)child;
+ Gate gate = (Gate)gateEp.resolveSemanticElement();
+ if(!(GateHelper.isInnerCFGate(gate))) {
+ return gateEp;
+ }
+ }
+ }
+ return null;
+ }
+
+ protected GateEditPart getInnerGateEditPart(GateEditPart outerGateEditPart) {
+ Gate outerGate = (Gate)outerGateEditPart.resolveSemanticElement();
+ Gate innerCFGate = GateHelper.getInnerCFGate(outerGate);
+ if(innerCFGate == null) {
+ return null;
+ }
+ @SuppressWarnings("rawtypes")
+ List children = outerGateEditPart.getParent().getChildren();
+ for(int i = children.size() - 1; i >= 0; i--) {
+ Object child = children.get(i);
+ if(child instanceof GateEditPart) {
+ GateEditPart gateEp = (GateEditPart)child;
+ Gate gate = (Gate)gateEp.resolveSemanticElement();
+ if(innerCFGate == gate) {
+ return gateEp;
+ }
+ }
+ }
+ return null;
+ }
+
+ protected String getGateName(GateEditPart gateEditPart) {
+ IGraphicalEditPart label = gateEditPart.getChildBySemanticHint(GateNameEditPart.GATE_NAME_TYPE);
+ if(label != null) {
+ return ((WrappingLabel)label.getFigure()).getText();
+ }
+ return null;
+ }
+
+ protected EditPart createGateParent(IElementType parentType, Point parentLocation, Dimension parentSize) {
+ assertNotNull(parentType);
+ EditPart parentEditPart = null;
+ InteractionEditPart interactionEditPart = (InteractionEditPart)getRootEditPart().getParent();
+ if(UMLElementTypes.Interaction_2001 == parentType) {
+ parentEditPart = interactionEditPart;
+ } else {
+ parentEditPart = createNode(parentType, getRootEditPart(), parentLocation, parentSize);
+ }
+ assertNotNull("create Gate parent", parentEditPart);
+ if(UMLElementTypes.InteractionUse_3002 == parentType) {
+ //set refersTo value.
+ updateValue(getEditingDomain(), ((IGraphicalEditPart)parentEditPart).resolveSemanticElement(), UMLPackage.Literals.INTERACTION_USE__REFERS_TO, interactionEditPart.resolveSemanticElement());
+ }
+ return parentEditPart;
+ }
+
+ /**
+ * Create a Gate on given type parent.
+ *
+ * @param parentType
+ * @param parentLocation
+ * @param parentSize
+ * @param onLeftSide
+ * @return
+ */
+ protected GateEditPart createGateWithParent(IElementType parentType, Point parentLocation, Dimension parentSize, boolean onLeftSide) {
+ EditPart parentEditPart = createGateParent(parentType, parentLocation, parentSize);
+ Rectangle bounds = getAbsoluteBounds((IGraphicalEditPart)parentEditPart);
+ GateEditPart gate = createGate(parentEditPart, onLeftSide ? new Point(bounds.x, bounds.y + bounds.height / 2) : new Point(bounds.right() - 1, bounds.y + bounds.height / 2));
+ assertNotNull("create Gate on " + parentType.getDisplayName(), gate);
+ return gate;
+ }
+
+ protected AbstractExecutionSpecificationEditPart createExecutionSpecificationWithLifeline(Point lifelineLocation, Dimension lifelineSize) {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), lifelineLocation, lifelineSize);
+ assertNotNull("create ExecutionSpecification's Lifeline", lifeline);
+ AbstractExecutionSpecificationEditPart es = (AbstractExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, lifeline, getAbsoluteBounds(lifeline).getCenter(), null);
+ assertNotNull("create ExecutionSpecification", es);
+ return es;
+ }
+
+ protected EditPart createNode(IElementType type, EditPart parentPart, Point location, Dimension size) {
+ EditPart editPart = super.createNode(type, parentPart, location, size);
+ assertNotNull("create failed: " + type.getDisplayName(), editPart);
+ return editPart;
+ }
+
+ @Override
+ protected EditPart createLink(IElementType elementType, EditPartViewer currentViewer, Point startLocation, Point endLocation) {
+ EditPart link = super.createLink(elementType, currentViewer, startLocation, endLocation);
+ assertNotNull("create link", link);
+ return link;
+ }
+
+ /**
+ * Test create Gate on CombinedFragment by using Palette.
+ */
+ @Test
+ public void testGateCreateOnCombinedFragment() {
+ createGateWithParent(UMLElementTypes.CombinedFragment_3004, new Point(100, 100), new Dimension(200, 200), true);
+ createGateWithParent(UMLElementTypes.CombinedFragment_3004, new Point(100, 100), new Dimension(200, 200), false);
+ }
+
+ /**
+ * Test create Gate on Interaction by using Palette.
+ */
+ @Test
+ public void testGateCreateOnInteraction() {
+ createGateWithParent(UMLElementTypes.Interaction_2001, new Point(100, 100), new Dimension(200, 200), true);
+ createGateWithParent(UMLElementTypes.Interaction_2001, new Point(100, 100), new Dimension(200, 200), false);
+ }
+
+ /**
+ * Test create Gate on InteractionUse by using Palette.
+ */
+ @Test
+ public void testGateCreateOnInteractionUse() {
+ GateEditPart gateOnInteractionUse = createGateWithParent(UMLElementTypes.InteractionUse_3002, new Point(100, 100), new Dimension(200, 200), true);
+ InteractionEditPart iep = (InteractionEditPart)getRootEditPart().getParent();
+ Gate selfGate = (Gate)gateOnInteractionUse.resolveSemanticElement();
+ assertNotNull(selfGate);
+ //Automatically create a gate on refersTo Interaction.
+ Interaction interaction = (Interaction)iep.resolveSemanticElement();
+ Gate formalGate = interaction.getFormalGate(selfGate.getName());
+ assertNotNull(formalGate);
+ GateEditPart gateOnInteraction = getGateEditPart(iep, formalGate);
+ assertNotNull("Gate created on Interaction", gateOnInteraction);
+ }
+
+ /**
+ * Test Async Message creation from a Lifeline to the existing Gate on CombinedFragment.
+ */
+ @Test
+ public void testGateCreateWithMessageAsyncOnGate() {
+ LifelineEditPart lifeline1 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), new Dimension(100, 400));
+ //the lifeline2 should be covered by the CombinedFragment.
+ LifelineEditPart lifeline2 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(400, 100), new Dimension(100, 400));
+ CombinedFragmentEditPart cf = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(300, 100), new Dimension(200, 200));
+ CombinedFragment combinedFragment = (CombinedFragment)cf.resolveSemanticElement();
+ Lifeline covered = (Lifeline)lifeline2.resolveSemanticElement();
+ assertTrue("lifeline should be covered by CombinedFragment", combinedFragment.getCovereds().contains(covered));
+ Rectangle rect = getAbsoluteBounds(cf);
+ GateEditPart outerGateEditPart = createGate(cf, new Point(rect.x, rect.y + rect.height / 2));
+ assertNotNull("new Gate should be created", outerGateEditPart);
+ //Message from Lifeline1 to Gate(outer gate) of CombinedFragment
+ Rectangle r = getAbsoluteBounds(outerGateEditPart);
+ Point endLocation = r.getCenter();
+ Point startLocation = getAbsoluteBounds(lifeline1).getCenter().setY(endLocation.y);
+ Message2EditPart message1EditPart = (Message2EditPart)createLink(UMLElementTypes.Message_4004, lifeline1.getViewer(), startLocation, endLocation);
+ assertNotNull("Message from Lifeline1 to Gate(outer gate) of CombinedFragment should be created", message1EditPart);
+ //Check names with the outer gate and message1.
+ Message message1 = (Message)message1EditPart.resolveSemanticElement();
+ String name = "m1";
+ changeName(getEditingDomain(), message1, name);
+ assertEquals("Suggestion name of outer gate", "in_m1", getGateName(outerGateEditPart));
+ }
+
+ /**
+ * Test Async Message with inner gate and outer gate on CombinedFragment.
+ * 1. message1: Lifeline1 --> CombinedFragment
+ * 1.1 Lifeline1 is at the left of CombinedFragment, and it not covered by the CombinedFragment.
+ * 1.2 After message creation, there are 2 gates (the inner gate and outer gate) should be created on CombinedFragment automatically.
+ * 1.3 The gates named to "in_<message1.name>".
+ * 2. message2: Inner Gate(1.2) --> Lifeline2
+ * 2.1 Lifeline2 is covered by the CombinedFragment.
+ * 2.2 The name of message2 should be automatically suggested to same as message1 one.
+ * 3. message3: CombinedFragment --> Lifeline3
+ * 3.1 Lifeline3 is at the right of CombinedFragment, and is not covered by the CombinedFragment.
+ * 3.2 The 2 gates should all named to "out_<message3.name>".
+ * 4. message4: Lifeline2 --> Inner Gate(3.2)
+ * 4.1 message4.name == message3.name
+ */
+ @Test
+ public void testGateCreateWithMessageAsyncOnCombinedFragment() {
+ LifelineEditPart lifeline1 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), new Dimension(100, 400));
+ // the lifeline2 should be covered by the CombinedFragment.
+ LifelineEditPart lifeline2 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(350, 100), new Dimension(100, 400));
+ CombinedFragmentEditPart cf = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(300, 100), new Dimension(200, 200));
+ //create CombinedFragment
+ CombinedFragment combinedFragment = (CombinedFragment)cf.resolveSemanticElement();
+ Lifeline covered = (Lifeline)lifeline2.resolveSemanticElement();
+ assertTrue("lifeline should be covered by CombinedFragment", combinedFragment.getCovereds().contains(covered));
+ //1. Message from Lifeline1 to CombinedFragment
+ Point startLocation = getAbsoluteBounds(lifeline1).getCenter();
+ Rectangle r = getAbsoluteBounds(cf);
+ Point endLocation = r.getLocation().setY(startLocation.y);
+ Message2EditPart message1EditPart = (Message2EditPart)createLink(UMLElementTypes.Message_4004, lifeline1.getViewer(), startLocation, endLocation);
+ assertNotNull("Message from Lifeline1 to Gate(outer gate) of CombinedFragment should be created", message1EditPart);
+ //The outer gate should be created automatically.
+ GateEditPart message1EndGate = getPrimaryGateEditPart(cf);
+ assertNotNull("new Gate should be created", message1EndGate);
+ //The inner Gate should be created automatically.
+ GateEditPart message1EndGateInner = getInnerGateEditPart(message1EndGate);
+ assertNotNull("a inner Gate should be created", message1EndGateInner);
+ //2. Message from inner Gate of CombinedFragment to Lifeline2.
+ startLocation = getAbsoluteBounds(message1EndGateInner).getCenter();
+ endLocation = getAbsoluteBounds(lifeline2).getCenter().setY(startLocation.y);
+ Message2EditPart message2EditPart = (Message2EditPart)createLink(UMLElementTypes.Message_4004, lifeline1.getViewer(), startLocation, endLocation);
+ assertNotNull("Message from inner Gate of CombinedFragment to Lifeline2 should be created", message2EditPart);
+ //Check names with the outer gate, inner gate , message1 and message2.
+ Message message1 = (Message)message1EditPart.resolveSemanticElement();
+ Message message2 = (Message)message2EditPart.resolveSemanticElement();
+ String name = "m1";
+ changeName(getEditingDomain(), message1, name);
+ assertEquals("Suggestion name of message2", name, message2.getName());
+ assertEquals("Suggestion name of outer gate", "in_m1", getGateName(message1EndGate));
+ assertEquals("Suggestion name of inner gate", "in_m1", getGateName(message1EndGateInner));
+ //3. Message from CombinedFragment to Lifeline3.
+ LifelineEditPart lifeline3 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(700, 100), new Dimension(100, 400));
+ assertNotNull(lifeline3);
+ waitForComplete();
+ startLocation = new Point(getAbsoluteBounds(cf).right() - 2, getAbsoluteBounds(cf).getCenter().y);
+ endLocation = startLocation.getCopy().setX(getAbsoluteBounds(lifeline3).getCenter().x);
+ Message2EditPart message3EditPart = (Message2EditPart)createLink(UMLElementTypes.Message_4004, lifeline1.getViewer(), startLocation, cf, endLocation, lifeline3);
+ assertNotNull("Message from CombinedFragment to Lifeline3 should be created", message3EditPart);
+ GateEditPart message3StartGate = getPrimaryGateEditPart(cf);
+ assertNotNull("New Gate created", message3StartGate);
+ Message message3 = (Message)message3EditPart.resolveSemanticElement();
+ assertEquals("Suggestion name of new gate", "out_" + message3.getName(), getGateName(message3StartGate));
+ //4. Message from Lifeline2 to message3StartGateInner
+ GateEditPart message3StartGateInner = getInnerGateEditPart(message3StartGate);
+ assertNotNull("a inner Gate should be created", message3StartGateInner);
+ endLocation = getAbsoluteBounds(message3StartGateInner).getCenter();
+ startLocation = new Point(getAbsoluteBounds(lifeline2).getCenter().x, endLocation.y);
+ Message2EditPart message4EditPart = (Message2EditPart)createLink(UMLElementTypes.Message_4004, lifeline1.getViewer(), startLocation, endLocation);
+ assertNotNull("Message from Lifeline2 to message3StartGateInner", message4EditPart);
+ Message message4 = (Message)message4EditPart.resolveSemanticElement();
+ assertEquals("Suggestion name of message4", message3.getName(), message4.getName());
+ }
+
+ /**
+ * Gates should be created automatically.
+ * 1. message1: Interaction --> Lifeline
+ * 2. message2: Lifeline --> Interaction
+ */
+ @Test
+ public void testGateCreateWithMessageAsyncOnInteraction() {
+ InteractionEditPart interaction = (InteractionEditPart)getRootEditPart().getParent();
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ Rectangle lifelineBounds = getAbsoluteBounds(lifeline);
+ //1. message1
+ Point endLocation = lifelineBounds.getCenter();
+ Point startLocation = new Point(0, endLocation.y);
+ Message2EditPart message1ep = (Message2EditPart)createLink(UMLElementTypes.Message_4004, interaction.getViewer(), startLocation, interaction, endLocation, lifeline);
+ assertNotNull("message1: Interaction --> Lifeline", message1ep);
+ Message message1 = (Message)message1ep.resolveSemanticElement();
+ Gate gate1 = (Gate)message1.getSendEvent();
+ GateEditPart gate1EditPart = getGateEditPart(interaction, gate1);
+ assertNotNull("Gate created", gate1EditPart);
+ assertEquals("Gate name", "in_" + message1.getName(), getGateName(gate1EditPart));
+ //2. message2
+ startLocation = endLocation.getTranslated(0, 50);
+ endLocation = new Point(0, startLocation.y);
+ Message2EditPart message2ep = (Message2EditPart)createLink(UMLElementTypes.Message_4004, interaction.getViewer(), startLocation, lifeline, endLocation, interaction);
+ assertNotNull("message2: Lifeline --> Interaction", message2ep);
+ Message message2 = (Message)message2ep.resolveSemanticElement();
+ Gate gate2 = (Gate)message2.getReceiveEvent();
+ GateEditPart gate2EditPart = getGateEditPart(interaction, gate2);
+ assertNotNull("Gate created", gate2EditPart);
+ assertEquals("Gate name", "out_" + message2.getName(), getGateName(gate2EditPart));
+ }
+
+ /**
+ * 1. message1: Lifeline1 --> InteractionUse
+ * 2. message2: InteractionUse --> Lifeline2
+ */
+ @Test
+ public void testGateCreateWithMessageAsyncOnInteractionUse() {
+ LifelineEditPart lifeline1 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), new Dimension(100, 400));
+ LifelineEditPart lifeline2 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(600, 100), new Dimension(100, 400));
+ InteractionUseEditPart interactionUse = (InteractionUseEditPart)createNode(UMLElementTypes.InteractionUse_3002, getRootEditPart(), new Point(300, 200), new Dimension(200, 100));
+ InteractionEditPart iep = (InteractionEditPart)getRootEditPart().getParent();
+ //set refersTo value.
+ updateValue(getEditingDomain(), interactionUse.resolveSemanticElement(), UMLPackage.Literals.INTERACTION_USE__REFERS_TO, iep.resolveSemanticElement());
+ //1. message1
+ Point endLocation = getAbsoluteBounds(lifeline1).getCenter();
+ Point startLocation = new Point(getAbsoluteBounds(interactionUse).x, endLocation.y);
+ Message2EditPart message1ep = (Message2EditPart)createLink(UMLElementTypes.Message_4004, lifeline1.getViewer(), startLocation, lifeline1, endLocation, interactionUse);
+ assertNotNull("message1: Lifeline1 --> InteractionUse", message1ep);
+ Message message1 = (Message)message1ep.resolveSemanticElement();
+ Gate gate1 = (Gate)message1.getReceiveEvent();
+ GateEditPart gate1EditPart = getGateEditPart(interactionUse, gate1);
+ assertNotNull("Gate created", gate1EditPart);
+ assertEquals("Gate name", "in_" + message1.getName(), getGateName(gate1EditPart));
+ //2. message2
+ endLocation = getAbsoluteBounds(lifeline2).getCenter();
+ startLocation = new Point(getAbsoluteBounds(interactionUse).right(), endLocation.y);
+ Message2EditPart message2ep = (Message2EditPart)createLink(UMLElementTypes.Message_4004, interactionUse.getViewer(), startLocation, interactionUse, endLocation, lifeline2);
+ assertNotNull("message2: InteractionUse --> Lifeline2", message2ep);
+ Message message2 = (Message)message2ep.resolveSemanticElement();
+ Gate gate2 = (Gate)message2.getSendEvent();
+ GateEditPart gate2EditPart = getGateEditPart(interactionUse, gate2);
+ assertNotNull("Gate created", gate2EditPart);
+ assertEquals("Gate name", "out_" + message2.getName(), getGateName(gate2EditPart));
+ }
+
+ @Test
+ public void testGateCreateWithMessageReplyOnGate() {
+ GateEditPart gateEditPart = createGateWithParent(UMLElementTypes.CombinedFragment_3004, new Point(20, 100), new Dimension(100, 200), false);
+ AbstractExecutionSpecificationEditPart es = createExecutionSpecificationWithLifeline(new Point(300, 100), null);
+ //Message reply
+ Point startLocation = getAbsoluteBounds(es).getCenter();
+ Point endLocation = getAbsoluteBounds(gateEditPart).getCenter().setY(startLocation.y);
+ AbstractMessageEditPart messageReply = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4005, gateEditPart.getViewer(), startLocation, es, endLocation, gateEditPart);
+ assertNotNull("Message Reply", messageReply);
+ }
+
+ /**
+ * check source when ends == 1;
+ * check target when ends == 2;
+ * check both when ends == others.
+ */
+ private void checkGateCreatedWithMessage(EditPart parent, AbstractMessageEditPart messageEditPart, int ends) {
+ assertNotNull(parent);
+ assertNotNull(messageEditPart);
+ EditPart source = messageEditPart.getSource();
+ EditPart target = messageEditPart.getTarget();
+ if(ends == 1) {
+ assertTrue("message start with gate", source instanceof GateEditPart);
+ assertTrue("auto added gate", parent == source.getParent());
+ } else if(ends == 2) {
+ assertTrue("message end with gate", target instanceof GateEditPart);
+ assertTrue("auto added gate", parent == target.getParent());
+ } else {
+ assertTrue("message start with gate", source instanceof GateEditPart);
+ assertTrue("auto added gate", parent == source.getParent());
+ assertTrue("message end with gate", target instanceof GateEditPart);
+ assertTrue("auto added gate", parent == target.getParent());
+ }
+ }
+
+ @Test
+ public void testGateCreateWithMessageReplyOnCombinedFragment() {
+ CombinedFragmentEditPart combinedFragment = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(50, 100), new Dimension(100, 200));
+ AbstractExecutionSpecificationEditPart es = createExecutionSpecificationWithLifeline(new Point(400, 50), null);
+ //Message reply
+ Point startLocation = getAbsoluteBounds(es).getCenter();
+ Point endLocation = new Point(getAbsoluteBounds(combinedFragment).right() - 1, startLocation.y);
+ AbstractMessageEditPart messageReply = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4005, combinedFragment.getViewer(), startLocation, es, endLocation, combinedFragment);
+ assertNotNull("Message Reply", messageReply);
+ checkGateCreatedWithMessage(combinedFragment, messageReply, 2);
+ }
+
+ @Test
+ public void testGateCreateWithMessageReplyOnInteraction() {
+ InteractionEditPart iep = (InteractionEditPart)getRootEditPart().getParent();
+ AbstractExecutionSpecificationEditPart es = createExecutionSpecificationWithLifeline(new Point(100, 50), null);
+ //Message reply
+ Point startLocation = getAbsoluteBounds(es).getCenter();
+ Point endLocation = new Point(0, startLocation.y);
+ AbstractMessageEditPart messageReply = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4005, iep.getViewer(), startLocation, es, endLocation, iep);
+ assertNotNull("Message Reply", messageReply);
+ checkGateCreatedWithMessage(iep, messageReply, 2);
+ }
+
+ @Test
+ public void testGateCreateWithMessageReplyOnInteractionUse() {
+ AbstractExecutionSpecificationEditPart es = createExecutionSpecificationWithLifeline(new Point(300, 100), new Dimension(100, 400));
+ InteractionUseEditPart interactionUse = (InteractionUseEditPart)createNode(UMLElementTypes.InteractionUse_3002, getRootEditPart(), new Point(100, 220), new Dimension(100, 100));
+ InteractionEditPart iep = (InteractionEditPart)getRootEditPart().getParent();
+ //set refersTo value.
+ updateValue(getEditingDomain(), interactionUse.resolveSemanticElement(), UMLPackage.Literals.INTERACTION_USE__REFERS_TO, iep.resolveSemanticElement());
+ //Message reply
+ Point endLocation = getAbsoluteBounds(es).getCenter();
+ Point startLocation = new Point(getAbsoluteBounds(interactionUse).x, endLocation.y);
+ AbstractMessageEditPart messageReply = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4005, es.getViewer(), startLocation, es, endLocation, interactionUse);
+ assertNotNull("Message Reply", messageReply);
+ checkGateCreatedWithMessage(interactionUse, messageReply, 2);
+ }
+
+ private void testGateCreateWithMessageFound(IElementType targetType, Point targetLocation, Dimension targetSize) {
+ IGraphicalEditPart targetEditPart = (IGraphicalEditPart)createGateParent(targetType, targetLocation, targetSize);
+ Point endLocation = null;
+ if(UMLElementTypes.Interaction_2001 == targetType) {
+ endLocation = getAbsoluteBounds(targetEditPart).getRight().getTranslated(-1, 0);
+ } else {
+ endLocation = getAbsoluteBounds(targetEditPart).getLeft().getTranslated(1, 0);
+ }
+ Point startLocation = endLocation.getTranslated(-100, -1);
+ AbstractMessageEditPart messageFound = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4009, targetEditPart.getViewer(), startLocation, getRootEditPart().getParent(), endLocation, targetEditPart);
+ assertNotNull("Message Found", messageFound);
+ checkGateCreatedWithMessage(targetEditPart, messageFound, 2);
+ }
+
+ @Test
+ public void testGateCreateWithMessageFoundOnGate() {
+ GateEditPart gate = createGateWithParent(UMLElementTypes.CombinedFragment_3004, new Point(150, 100), new Dimension(200, 100), true);
+ Point endLocation = getAbsoluteBounds(gate).getCenter();
+ Point startLocation = endLocation.getTranslated(-80, 0);
+ EditPart messageFound = createLink(UMLElementTypes.Message_4009, gate.getViewer(), startLocation, endLocation);
+ assertNotNull("Message Found", messageFound);
+ }
+
+ @Test
+ public void testGateCreateWithMessageFoundOnCombinedFragment() {
+ testGateCreateWithMessageFound(UMLElementTypes.CombinedFragment_3004, new Point(300, 100), new Dimension(200, 100));
+ }
+
+ @Test
+ public void testGateCreateWithMessageFoundOnInteraction() {
+ testGateCreateWithMessageFound(UMLElementTypes.Interaction_2001, null, null);
+ }
+
+ @Test
+ public void testGateCreateWithMessageFoundOnInteractionUse() {
+ testGateCreateWithMessageFound(UMLElementTypes.InteractionUse_3002, new Point(300, 100), new Dimension(200, 100));
+ }
+
+ @Test
+ public void testGateCreateWithMessageLostOnGate() {
+ GateEditPart gateEditPart = createGateWithParent(UMLElementTypes.CombinedFragment_3004, new Point(100, 100), new Dimension(200, 100), false);
+ Point startLocation = getAbsoluteBounds(gateEditPart).getCenter();
+ Point endLocation = startLocation.getTranslated(100, 0);
+ EditPart messageLost = createLink(UMLElementTypes.Message_4008, gateEditPart.getViewer(), startLocation, endLocation);
+ assertNotNull("Message Lost", messageLost);
+ }
+
+ private void testGateCreateWithMessageLost(IElementType targetType, Point targetLocation, Dimension targetSize) {
+ IGraphicalEditPart targetEditPart = (IGraphicalEditPart)createGateParent(targetType, targetLocation, targetSize);
+ Point startLocation = null;
+ if(UMLElementTypes.Interaction_2001 == targetType) {
+ startLocation = getAbsoluteBounds(targetEditPart).getLeft().getTranslated(1, 0);
+ } else {
+ startLocation = getAbsoluteBounds(targetEditPart).getRight().getTranslated(-1, 0);
+ }
+ Point endLocation = startLocation.getTranslated(100, 1);
+ AbstractMessageEditPart messageFound = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4008, targetEditPart.getViewer(), startLocation, targetEditPart, endLocation, getRootEditPart().getParent());
+ assertNotNull("Message Lost", messageFound);
+ checkGateCreatedWithMessage(targetEditPart, messageFound, 1);
+ }
+
+ @Test
+ public void testGateCreateWithMessageLostOnCombinedFragment() {
+ testGateCreateWithMessageLost(UMLElementTypes.CombinedFragment_3004, new Point(100, 100), new Dimension(200, 100));
+ }
+
+ @Test
+ public void testGateCreateWithMessageLostOnInteraction() {
+ testGateCreateWithMessageLost(UMLElementTypes.Interaction_2001, null, null);
+ }
+
+ @Test
+ public void testGateCreateWithMessageLostOnInteractionUse() {
+ testGateCreateWithMessageLost(UMLElementTypes.InteractionUse_3002, new Point(100, 100), new Dimension(200, 100));
+ }
+
+ @Test
+ public void testReconnectMessageAsyncTargetToGate() {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ CombinedFragmentEditPart combinedFragment = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(300, 80), new Dimension(100, 200));
+ Rectangle rect = getAbsoluteBounds(combinedFragment);
+ GateEditPart gate1 = createGate(combinedFragment, rect.getLeft().getTranslated(0, -20));
+ //gate2 and gate 1 are located on same CombinedFrament
+ GateEditPart gate2 = createGate(combinedFragment, rect.getLeft().getTranslated(0, 20));
+ //gate3 is located on different CombinedFragment.
+ GateEditPart gate3 = createGateWithParent(UMLElementTypes.CombinedFragment_3004, new Point(300, 300), new Dimension(100, 100), true);
+ AbstractMessageEditPart messageAsync = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, lifeline.getViewer(), getAbsoluteCenter(lifeline), getAbsoluteCenter(gate1));
+ assertNotNull("Message Async", messageAsync);
+ checkGraphicalElements(messageAsync, gate1, false);
+ checkSemanticElements(messageAsync, gate1, false);
+ reconnectTarget(messageAsync, gate2, getAbsoluteCenter(gate2));
+ checkGraphicalElements(messageAsync, gate2, false);
+ checkSemanticElements(messageAsync, gate2, false);
+ reconnectTarget(messageAsync, gate3, getAbsoluteCenter(gate3));
+ checkGraphicalElements(messageAsync, gate3, false);
+ checkSemanticElements(messageAsync, gate3, false);
+ }
+
+ @Test
+ public void testReconnectMessageAsyncSourceToGate() {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), null);
+ CombinedFragmentEditPart combinedFragment = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(100, 80), new Dimension(100, 100));
+ Rectangle rect = getAbsoluteBounds(combinedFragment);
+ GateEditPart gate1 = createGate(combinedFragment, rect.getRight().getTranslated(0, -20));
+ GateEditPart gate2 = createGate(combinedFragment, rect.getRight().getTranslated(0, 20));
+ GateEditPart gate3 = createGateWithParent(UMLElementTypes.CombinedFragment_3004, new Point(100, 380), new Dimension(100, 100), false);
+ AbstractMessageEditPart messageAsync = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, lifeline.getViewer(), getAbsoluteCenter(gate1), getAbsoluteCenter(lifeline));
+ assertNotNull("Message Async", messageAsync);
+ checkGraphicalElements(messageAsync, gate1, true);
+ checkSemanticElements(messageAsync, gate1, true);
+ reconnectSource(messageAsync, gate2, getAbsoluteCenter(gate2));
+ checkGraphicalElements(messageAsync, gate2, true);
+ checkSemanticElements(messageAsync, gate2, true);
+ reconnectSource(messageAsync, gate3, getAbsoluteCenter(gate3));
+ checkGraphicalElements(messageAsync, gate3, true);
+ checkSemanticElements(messageAsync, gate3, true);
+ }
+
+ private void checkGraphicalElements(AbstractMessageEditPart messageEditPart, GateEditPart gateEditPart, boolean source) {
+ assertNotNull(messageEditPart);
+ assertNotNull(gateEditPart);
+ if(source) {
+ assertEquals("message source editPart", gateEditPart, messageEditPart.getSource());
+ } else {
+ assertEquals("message target editPart", gateEditPart, messageEditPart.getTarget());
+ }
+ }
+
+ private void checkSemanticElements(AbstractMessageEditPart messageEditPart, GateEditPart gateEditPart, boolean source) {
+ assertNotNull(messageEditPart);
+ assertNotNull(gateEditPart);
+ Message message = (Message)messageEditPart.resolveSemanticElement();
+ assertNotNull(message);
+ Gate gate = (Gate)gateEditPart.resolveSemanticElement();
+ assertNotNull(gate);
+ if(source) {
+ assertEquals("message source", gate, message.getSendEvent());
+ } else {
+ assertEquals("message target", gate, message.getReceiveEvent());
+ }
+ }
+
+ /**
+ * 1. When moved a message start with gate on the container CombinedFragment, just move the gate to the new location.
+ * 2. Otherwise, create a new gate.
+ */
+ @Test
+ public void testReconnectMessageAsyncSourceToCombinedFragment() {
+ GateEditPart gate1 = createGateWithParent(UMLElementTypes.CombinedFragment_3004, new Point(100, 100), new Dimension(100, 100), false);
+ CombinedFragmentEditPart cf1 = (CombinedFragmentEditPart)gate1.getParent();
+ CombinedFragmentEditPart cf2 = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(100, 220), new Dimension(100, 80));
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), new Dimension(100, 500));
+ AbstractMessageEditPart messageAsync = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, lifeline.getViewer(), getAbsoluteCenter(gate1), getAbsoluteCenter(lifeline));
+ checkSemanticElements(messageAsync, gate1, true);
+ //1. moved on same combinedFragment.
+ reconnectSource(messageAsync, cf1, getAbsoluteCenter(gate1).getTranslated(0, 30));
+ checkGraphicalElements(messageAsync, gate1, true);
+ checkSemanticElements(messageAsync, gate1, true);
+ //2. moved to new combinedFragment.
+ GateEditPart gate2 = getPrimaryGateEditPart(cf2);
+ assertNull("no gate before", gate2);
+ reconnectSource(messageAsync, cf2, getAbsoluteBounds(cf2).getRight().getTranslated(-1, 0));
+ gate2 = getPrimaryGateEditPart(cf2);
+ assertNotNull("gate created", gate2);
+ checkGraphicalElements(messageAsync, gate2, true);
+ checkSemanticElements(messageAsync, gate2, true);
+ }
+
+ @Test
+ public void testReconnectMessageAsyncTargetToCombinedFragment() {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), new Dimension(100, 500));
+ GateEditPart gate1 = createGateWithParent(UMLElementTypes.CombinedFragment_3004, new Point(300, 100), new Dimension(100, 100), true);
+ CombinedFragmentEditPart cf1 = (CombinedFragmentEditPart)gate1.getParent();
+ CombinedFragmentEditPart cf2 = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(300, 220), new Dimension(100, 80));
+ AbstractMessageEditPart messageAsync = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, lifeline.getViewer(), getAbsoluteCenter(lifeline), getAbsoluteCenter(gate1));
+ checkSemanticElements(messageAsync, gate1, false);
+ //1. moved on same combinedFragment.
+ reconnectTarget(messageAsync, cf1, getAbsoluteCenter(gate1).getTranslated(0, 30));
+ checkGraphicalElements(messageAsync, gate1, false);
+ checkSemanticElements(messageAsync, gate1, false);
+ //2. moved to new combinedFragment.
+ GateEditPart gate2 = getPrimaryGateEditPart(cf2);
+ assertNull("no gate before", gate2);
+ reconnectTarget(messageAsync, cf2, getAbsoluteBounds(cf2).getLeft().getTranslated(1, 0));
+ gate2 = getPrimaryGateEditPart(cf2);
+ assertNotNull("gate created", gate2);
+ checkGraphicalElements(messageAsync, gate2, false);
+ checkSemanticElements(messageAsync, gate2, false);
+ }
+
+ @Test
+ public void testReconnectMessageAsyncSourceToInteraction() {
+ EditPart iep = getRootEditPart().getParent();
+ GateEditPart gate = createGate(iep, new Point(0, 100));
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ Point startLocation = getAbsoluteCenter(gate);
+ Point endLocation = getAbsoluteCenter(lifeline).setY(startLocation.y + 1);
+ AbstractMessageEditPart messageAsync = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, iep.getViewer(), startLocation, gate, endLocation, lifeline);
+ checkGraphicalElements(messageAsync, gate, true);
+ checkSemanticElements(messageAsync, gate, true);
+ reconnectSource(messageAsync, iep, startLocation.getTranslated(0, 50));
+ checkGraphicalElements(messageAsync, gate, true);
+ checkSemanticElements(messageAsync, gate, true);
+ }
+
+ @Test
+ public void testReconnectMessageAsyncTargetToInteraction() {
+ EditPart iep = getRootEditPart().getParent();
+ GateEditPart gate = createGate(iep, new Point(0, 100));
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ Point endLocation = getAbsoluteCenter(gate);
+ Point startLocation = getAbsoluteCenter(lifeline).setY(endLocation.y);
+ AbstractMessageEditPart messageAsync = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, iep.getViewer(), startLocation, lifeline, endLocation, gate);
+ checkGraphicalElements(messageAsync, gate, false);
+ checkSemanticElements(messageAsync, gate, false);
+ reconnectTarget(messageAsync, iep, startLocation.getTranslated(0, 50));
+ checkGraphicalElements(messageAsync, gate, false);
+ checkSemanticElements(messageAsync, gate, false);
+ }
+
+ @Test
+ public void testReconnectMessageAsyncSourceToInteractionUse() {
+ InteractionEditPart iep = (InteractionEditPart)getRootEditPart().getParent();
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), new Dimension(100, 300));
+ InteractionUseEditPart iuep1 = (InteractionUseEditPart)createNode(UMLElementTypes.InteractionUse_3002, getRootEditPart(), new Point(100, 150), new Dimension(100, 100));
+ updateValue(getEditingDomain(), ((IGraphicalEditPart)iuep1).resolveSemanticElement(), UMLPackage.Literals.INTERACTION_USE__REFERS_TO, iep.resolveSemanticElement());
+ InteractionUseEditPart iuep2 = (InteractionUseEditPart)createNode(UMLElementTypes.InteractionUse_3002, getRootEditPart(), new Point(100, 280), new Dimension(100, 100));
+ updateValue(getEditingDomain(), ((IGraphicalEditPart)iuep2).resolveSemanticElement(), UMLPackage.Literals.INTERACTION_USE__REFERS_TO, iep.resolveSemanticElement());
+ //messageAsync = iuep1 --> lifeline
+ GateEditPart gate1 = getPrimaryGateEditPart(iuep1);
+ assertNull(gate1);
+ Point startLocation = getAbsoluteBounds(iuep1).getRight().getTranslated(-1, 0);
+ Point endLocation = getAbsoluteCenter(lifeline).setY(startLocation.y + 1);
+ AbstractMessageEditPart messageAsync = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, lifeline.getViewer(), startLocation, iuep1, endLocation, lifeline);
+ gate1 = getPrimaryGateEditPart(iuep1);
+ assertNotNull("gate1 should be created", gate1);
+ checkGraphicalElements(messageAsync, gate1, true);
+ checkSemanticElements(messageAsync, gate1, true);
+ //reconnect to: iuep2 --> lifeline
+ GateEditPart gate2 = getPrimaryGateEditPart(iuep2);
+ assertNull(gate2);
+ reconnectSource(messageAsync, iuep2, getAbsoluteBounds(iuep2).getRight().getTranslated(-1, 0));
+ gate2 = getPrimaryGateEditPart(iuep2);
+ assertNotNull("gate2 should be created", gate2);
+ checkGraphicalElements(messageAsync, gate2, true);
+ checkSemanticElements(messageAsync, gate2, true);
+ }
+
+ @Test
+ public void testReconnectMessageAsyncTargetToInteractionUse() {
+ InteractionEditPart iep = (InteractionEditPart)getRootEditPart().getParent();
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), new Dimension(100, 300));
+ InteractionUseEditPart iuep1 = (InteractionUseEditPart)createNode(UMLElementTypes.InteractionUse_3002, getRootEditPart(), new Point(300, 150), new Dimension(100, 100));
+ updateValue(getEditingDomain(), ((IGraphicalEditPart)iuep1).resolveSemanticElement(), UMLPackage.Literals.INTERACTION_USE__REFERS_TO, iep.resolveSemanticElement());
+ InteractionUseEditPart iuep2 = (InteractionUseEditPart)createNode(UMLElementTypes.InteractionUse_3002, getRootEditPart(), new Point(300, 280), new Dimension(100, 100));
+ updateValue(getEditingDomain(), ((IGraphicalEditPart)iuep2).resolveSemanticElement(), UMLPackage.Literals.INTERACTION_USE__REFERS_TO, iep.resolveSemanticElement());
+ //messageAsync = lifeline --> iuep1
+ GateEditPart gate1 = getPrimaryGateEditPart(iuep1);
+ assertNull(gate1);
+ AbstractMessageEditPart messageAsync = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4004, lifeline.getViewer(), getAbsoluteCenter(lifeline), lifeline, getAbsoluteBounds(iuep1).getLeft().getTranslated(1, 0), iuep1);
+ gate1 = getPrimaryGateEditPart(iuep1);
+ assertNotNull("gate1 should be created", gate1);
+ checkGraphicalElements(messageAsync, gate1, false);
+ checkSemanticElements(messageAsync, gate1, false);
+ //reconnect to: lifeline --> iuep2
+ GateEditPart gate2 = getPrimaryGateEditPart(iuep2);
+ assertNull(gate2);
+ reconnectTarget(messageAsync, iuep2, getAbsoluteBounds(iuep2).getLeft().getTranslated(1, 0));
+ gate2 = getPrimaryGateEditPart(iuep2);
+ assertNotNull("gate2 should be created", gate2);
+ checkGraphicalElements(messageAsync, gate2, false);
+ checkSemanticElements(messageAsync, gate2, false);
+ }
+
+ @Test
+ public void testReconnectMessageReplyToCombinedFragment() {
+ AbstractExecutionSpecificationEditPart es = createExecutionSpecificationWithLifeline(new Point(100, 100), new Dimension(100, 500));
+ CombinedFragmentEditPart cf1 = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(300, 200), new Dimension(200, 200));
+ //messageReply: es --> cf1
+ GateEditPart gate1 = getPrimaryGateEditPart(cf1);
+ assertNull(gate1);
+ AbstractMessageEditPart messageReply = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4005, es.getViewer(), getAbsoluteCenter(es), es, getAbsoluteBounds(cf1).getLeft().getTranslated(1, 0), cf1);
+ gate1 = getPrimaryGateEditPart(cf1);
+ assertNotNull("gate1 should be created", gate1);
+ checkGraphicalElements(messageReply, gate1, false);
+ checkSemanticElements(messageReply, gate1, false);
+ //reconnect: es --> cf2
+ CombinedFragmentEditPart cf2 = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(300, 420), new Dimension(200, 200));
+ GateEditPart gate2 = getPrimaryGateEditPart(cf2);
+ assertNull(gate2);
+ reconnectTarget(messageReply, cf2, getAbsoluteBounds(cf2).getLeft().getTranslated(1, 0));
+ gate2 = getPrimaryGateEditPart(cf2);
+ assertNotNull("gate2 should be created", gate2);
+ checkGraphicalElements(messageReply, gate2, false);
+ checkSemanticElements(messageReply, gate2, false);
+ }
+
+ @Test
+ public void testReconnectMessageReplyToInteraction() {
+ AbstractExecutionSpecificationEditPart es = createExecutionSpecificationWithLifeline(new Point(200, 100), null);
+ InteractionEditPart iep = (InteractionEditPart)getRootEditPart().getParent();
+ Point startLocation = getAbsoluteCenter(es);
+ Point endLocation = getAbsoluteBounds(iep).getLocation().setY(startLocation.y);
+ GateEditPart gate = getPrimaryGateEditPart(iep);
+ assertNull(gate);
+ AbstractMessageEditPart messageReply = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4005, es.getViewer(), startLocation, es, endLocation, iep);
+ gate = getPrimaryGateEditPart(iep);
+ assertNotNull("gate should be created", gate);
+ checkGraphicalElements(messageReply, gate, false);
+ checkSemanticElements(messageReply, gate, false);
+ //reconnect
+ endLocation = endLocation.getTranslated(0, 80);
+ reconnectTarget(messageReply, iep, endLocation);
+ checkGraphicalElements(messageReply, gate, false);
+ checkSemanticElements(messageReply, gate, false);
+ }
+
+ @Test
+ public void testReconnectMessageReplyToInteractionUse() {
+ InteractionEditPart iep = (InteractionEditPart)getRootEditPart().getParent();
+ AbstractExecutionSpecificationEditPart es = createExecutionSpecificationWithLifeline(new Point(100, 100), new Dimension(100, 300));
+ InteractionUseEditPart iuep1 = (InteractionUseEditPart)createNode(UMLElementTypes.InteractionUse_3002, getRootEditPart(), new Point(300, 150), new Dimension(100, 100));
+ updateValue(getEditingDomain(), ((IGraphicalEditPart)iuep1).resolveSemanticElement(), UMLPackage.Literals.INTERACTION_USE__REFERS_TO, iep.resolveSemanticElement());
+ InteractionUseEditPart iuep2 = (InteractionUseEditPart)createNode(UMLElementTypes.InteractionUse_3002, getRootEditPart(), new Point(300, 280), new Dimension(100, 100));
+ updateValue(getEditingDomain(), ((IGraphicalEditPart)iuep2).resolveSemanticElement(), UMLPackage.Literals.INTERACTION_USE__REFERS_TO, iep.resolveSemanticElement());
+ //messageReply: es --> iuep1
+ GateEditPart gate1 = getPrimaryGateEditPart(iuep1);
+ assertNull(gate1);
+ AbstractMessageEditPart messageReply = (AbstractMessageEditPart)createLink(UMLElementTypes.Message_4005, es.getViewer(), getAbsoluteCenter(es), es, getAbsoluteBounds(iuep1).getLeft().getTranslated(1, 0), iuep1);
+ gate1 = getPrimaryGateEditPart(iuep1);
+ assertNotNull("gate1 should be created", gate1);
+ checkGraphicalElements(messageReply, gate1, false);
+ checkSemanticElements(messageReply, gate1, false);
+ //reconnect to: es --> iuep2
+ GateEditPart gate2 = getPrimaryGateEditPart(iuep2);
+ assertNull(gate2);
+ reconnectTarget(messageReply, iuep2, getAbsoluteBounds(iuep2).getLeft().getTranslated(1, 0));
+ gate2 = getPrimaryGateEditPart(iuep2);
+ assertNotNull("gate2 should be created", gate2);
+ checkGraphicalElements(messageReply, gate2, false);
+ checkSemanticElements(messageReply, gate2, false);
+ }
+
+ @Test
+ public void testReconnectMessageFoundToCombinedFragment() {
+ //MessageFound not support reconnect.
+ }
+
+ @Test
+ public void testReconnectMessageFoundToInteraction() {
+ //MessageFound not support reconnect.
+ }
+
+ @Test
+ public void testReconnectMessageFoundToInteractionUse() {
+ //MessageFound not support reconnect.
+ }
+
+ @Test
+ public void testReconnectMessageLostToCombinedFragment() {
+ //MessageLost not support reconnect.
+ }
+
+ @Test
+ public void testReconnectMessageLostToInteraction() {
+ //MessageLost not support reconnect.
+ }
+
+ @Test
+ public void testReconnectMessageLostToInteractionUse() {
+ //MessageLost not support reconnect.
+ }
+}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGuardVisibility_402966.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGuardVisibility_402966.java
index c56de87d54a..d19c2ddda5d 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGuardVisibility_402966.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestGuardVisibility_402966.java
@@ -15,23 +15,35 @@ package org.eclipse.papyrus.uml.diagram.sequence.tests.bug.m7;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.jface.preference.IPreferencePage;
import org.eclipse.jface.preference.PreferenceDialog;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentCombinedFragmentCompartmentEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart.CustomInteractionOperandFigure;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.sequence.util.InteractionOperandModelElementFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
-import org.eclipse.uml2.uml.CombinedFragment;
-import org.eclipse.uml2.uml.InteractionOperand;
+import org.eclipse.ui.part.IPage;
+import org.eclipse.ui.views.properties.PropertySheet;
+import org.eclipse.ui.views.properties.tabbed.ITabDescriptor;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import org.junit.Before;
import org.junit.Test;
@@ -60,8 +72,9 @@ public class TestGuardVisibility_402966 extends AbstractNodeTest {
Control control = page.getControl();
Control group = getControl((Composite)control, Group.class, "Guard", SWT.NONE);
assertNotNull("Preference Item Guard Group: ", group);
- Control checkbox = getControl((Composite)group, Button.class, "Show", SWT.CHECK);
+ Button checkbox = (Button)getControl((Composite)group, Button.class, "Show", SWT.CHECK);
assertNotNull("Preference Item Visibility CheckBox: ", checkbox);
+ assertEquals("Default value of Guard Visibility: ", true, checkbox.getSelection());
dialog.close();
}
@@ -90,12 +103,57 @@ public class TestGuardVisibility_402966 extends AbstractNodeTest {
@Test
public void testPropertySheetPage() {
CombinedFragmentEditPart cf = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(100, 100), new Dimension(400, 100));
- Rectangle rect = getAbsoluteBounds(cf);
- InteractionOperandEditPart operand = (InteractionOperandEditPart)createNode(UMLElementTypes.InteractionOperand_3005, cf, rect.getCenter(), null);
+ assertNotNull(cf);
+ CombinedFragmentCombinedFragmentCompartmentEditPart compartment = (CombinedFragmentCombinedFragmentCompartmentEditPart)cf.getChildBySemanticHint("" + CombinedFragmentCombinedFragmentCompartmentEditPart.VISUAL_ID);
+ assertNotNull(compartment);
+ InteractionOperandEditPart operand = (InteractionOperandEditPart)createNode(UMLElementTypes.InteractionOperand_3005, compartment, getAbsoluteCenter(compartment), null);
assertNotNull(operand);
+ waitForComplete();
+ try {
+ IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ PropertySheet propertySheet = (PropertySheet)activePage.showView(IPageLayout.ID_PROP_SHEET);
+ IPage currentPage = propertySheet.getCurrentPage();
+ assertTrue(currentPage instanceof TabbedPropertySheetPage);
+ waitForComplete();
+ TabbedPropertySheetPage page = (TabbedPropertySheetPage)currentPage;
+ page.setSelectedTab("appearance");
+ waitForComplete();
+ ITabDescriptor selectedTab = page.getSelectedTab();
+ assertNotNull(selectedTab);
+ assertEquals("appearance", selectedTab.getId());
+ waitForComplete();
+ //force select the operand
+ page.selectionChanged(activePage.getActiveEditor(), new StructuredSelection(operand));
+ waitForComplete();
+ Control control = page.getControl();
+ assertNotNull(control);
+ Button checkbox = (Button)getControl((Composite)control, Button.class, "Show Guard", SWT.CHECK);
+ assertNotNull("Could not found \"Show Guard\" CheckBox in Properties: ", checkbox);
+ assertEquals("Synchronized value with model: ", InteractionOperandModelElementFactory.isGuardVisible(operand.getPrimaryView()), checkbox.getSelection());
+ testGuardVisibility(operand, checkbox.getSelection());
+ checkbox.setSelection(!checkbox.getSelection());
+ Event event = new Event();
+ event.button = 1;
+ event.widget = checkbox;
+ event.type = SWT.Selection;
+ checkbox.notifyListeners(SWT.Selection, event);
+ waitForComplete();
+ testGuardVisibility(operand, checkbox.getSelection());
+ } catch (PartInitException e) {
+ fail("Could not open Property Sheet View: " + e.getMessage());
+ }
}
- @Test
- public void testGuardVisibility() {
+ public void testGuardVisibility(InteractionOperandEditPart operand, boolean visible) {
+ assertNotNull(operand);
+ CustomInteractionOperandFigure primaryShape = operand.getPrimaryShape();
+ WrappingLabel constraintLabel = primaryShape.getInteractionConstraintLabel();
+ assertNotNull(constraintLabel);
+ if(visible) {
+ String text = ((ITextAwareEditPart)operand).getParser().getPrintString(new EObjectAdapter(operand.resolveSemanticElement()), ParserOptions.NONE.intValue());
+ assertEquals("Show Guard:", text, constraintLabel.getText());
+ } else {
+ assertEquals("Hide Guard:", "", constraintLabel.getText());
+ }
}
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestMessageCreateWithLifeline_403134.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestMessageCreateWithLifeline_403134.java
index 394215d6a10..b3dabaea136 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestMessageCreateWithLifeline_403134.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestMessageCreateWithLifeline_403134.java
@@ -13,18 +13,8 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.tests.bug.m7;
-import java.util.Collections;
-
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
-import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
-import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message4EditPart;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
@@ -43,47 +33,11 @@ public class TestMessageCreateWithLifeline_403134 extends AbstractNodeTest {
LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
assertNotNull(lifeline);
Point fromLocation = getAbsoluteBounds(lifeline).getCenter();
- //start connection
- EditPart sourceEditPart = null;
- EditPart targetEditPart = null;
- CreateConnectionViewRequest request = CreateViewRequestFactory.getCreateConnectionRequest(UMLElementTypes.Message_4006, ((IGraphicalEditPart)getDiagramEditPart()).getDiagramPreferencesHint());
- assertNotNull(request);
- request.setLocation(fromLocation);
- request.setType(RequestConstants.REQ_CONNECTION_START);
- sourceEditPart = lifeline.getViewer().findObjectAtExcluding(fromLocation, Collections.emptySet(), getTargetingConditional(request));
- assertNotNull(sourceEditPart);
- request.setSourceEditPart(sourceEditPart);
- request.setTargetEditPart(sourceEditPart);
- Command command = sourceEditPart.getCommand(request);
- assertNotNull(COMMAND_NULL, command);
- //connect...
- Point toLocation = fromLocation.getTranslated(100, 0);
- request.setLocation(toLocation);
- request.setType(RequestConstants.REQ_CONNECTION_END);
- targetEditPart = sourceEditPart.getViewer().findObjectAtExcluding(toLocation, Collections.emptySet(), getTargetingConditional(request));
- assertNotNull(targetEditPart);
- request.setTargetEditPart(targetEditPart);
- command = targetEditPart.getCommand(request);
- assertNotNull(COMMAND_NULL, command);
- assertTrue(command.canExecute());
- getDiagramCommandStack().execute(command);
- waitForComplete();
+ EditPart editPart = createLink(UMLElementTypes.Message_4006, lifeline.getViewer(), fromLocation, fromLocation.getTranslated(100, 0));
//check result
- View view = (View)request.getConnectionViewDescriptor().getAdapter(View.class);
- assertNotNull("view not found", view);
- EditPart editPart = (EditPart)lifeline.getViewer().getEditPartRegistry().get(view);
assertNotNull("editpart not found", editPart);
assertTrue("not a messageCreate editpart", editPart instanceof Message4EditPart);
EditPart target = ((Message4EditPart)editPart).getTarget();
assertTrue("the target is not a lifeline", target instanceof LifelineEditPart);
}
-
- protected EditPartViewer.Conditional getTargetingConditional(final Request req) {
- return new EditPartViewer.Conditional() {
-
- public boolean evaluate(EditPart editpart) {
- return editpart.getTargetEditPart(req) != null;
- }
- };
- }
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestTooltip_402964.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestTooltip_402964.java
index 418c32866cc..22af13af8dd 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestTooltip_402964.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/m7/TestTooltip_402964.java
@@ -13,9 +13,52 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.tests.bug.m7;
-import org.eclipse.papyrus.commands.ICreationCommand;
-import org.eclipse.papyrus.uml.diagram.sequence.tests.canonical.CreateSequenceDiagramCommand;
-import org.eclipse.papyrus.uml.diagram.sequence.tests.canonical.TestTopNode;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.ActionExecutionSpecificationEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.BehaviorExecutionSpecificationEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragment2EditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentCombinedFragmentCompartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.DestructionOccurrenceSpecificationEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.ExecutionSpecificationEndEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.GeneralOrderingEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionUseEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message2EditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message3EditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message4EditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message5EditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message6EditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message7EditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageEndEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.StateInvariantEditPart;
+import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.sequence.util.SequenceUtil;
+import org.eclipse.papyrus.uml.diagram.sequence.util.TooltipUtil.TooltipFigure;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.CombinedFragment;
+import org.eclipse.uml2.uml.Interaction;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.UMLPackage;
import org.junit.Test;
/**
@@ -26,20 +69,304 @@ import org.junit.Test;
*
* @author Jin Liu (jin.liu@soyatec.com)
*/
-public class TestTooltip_402964 extends TestTopNode {
+public class TestTooltip_402964 extends AbstractNodeTest {
+
+ private Property representsProperty;
+
+ @Test
+ public void testLifelineTooltip() {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(lifeline);
+ final Package model = getPackage();
+ getDiagramCommandStack().execute(new ICommandProxy(new AbstractTransactionalCommand(getEditingDomain(), "", Collections.singletonList(file)) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ Class libraryType = model.createOwnedClass("Library", false);
+ Class bookType = model.createOwnedClass("Book", false);
+ representsProperty = libraryType.createOwnedAttribute("books", bookType, 0, -1);
+ return CommandResult.newOKCommandResult();
+ }
+ }));
+ waitForComplete();
+ assertNotNull(representsProperty);
+ Command setRepresentCommand = createSetCommand(getEditingDomain(), lifeline.resolveSemanticElement(), UMLPackage.Literals.LIFELINE__REPRESENTS, representsProperty);
+ assertNotNull(setRepresentCommand);
+ assertTrue(setRepresentCommand.canExecute());
+ getDiagramCommandStack().execute(setRepresentCommand);
+ waitForComplete();
+ IFigure figure = lifeline.getFigure();
+ assertNotNull(figure);
+ IFigure toolTip = figure.getToolTip();
+ checkTooltip(toolTip, "Lifeline", "label: books : Book");
+ }
+
+ @Test
+ public void testActionExecutionSpecification() {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(lifeline);
+ ActionExecutionSpecificationEditPart aes = (ActionExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, lifeline, getAbsoluteCenter(lifeline), null);
+ assertNotNull(aes);
+ String name = "TestActionExecutionSpecification";
+ changeName(getEditingDomain(), (NamedElement)aes.resolveSemanticElement(), name);
+ checkTooltip(aes.getFigure().getToolTip(), "Action Execution Specification", "name: " + name);
+ }
+
+ @Test
+ public void testBehaviorExecutionSpecification() {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(lifeline);
+ BehaviorExecutionSpecificationEditPart bes = (BehaviorExecutionSpecificationEditPart)createNode(UMLElementTypes.BehaviorExecutionSpecification_3003, lifeline, getAbsoluteCenter(lifeline), null);
+ assertNotNull(bes);
+ String name = "TestBehaviorExecutionSpecification";
+ changeName(getEditingDomain(), (NamedElement)bes.resolveSemanticElement(), name);
+ checkTooltip(bes.getFigure().getToolTip(), "Behavior Execution Specification", "name: " + name);
+ }
+
+ @Test
+ public void testCombinedFragment() {
+ CombinedFragmentEditPart cf = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(100, 100), new Dimension(200, 100));
+ assertNotNull(cf);
+ String name = "Test Combined Fragment";
+ CombinedFragment elt = (CombinedFragment)cf.resolveSemanticElement();
+ changeName(getEditingDomain(), elt, name);
+ checkTooltip(cf.getFigure().getToolTip(), "Combined Fragment", "name: " + name + "\noperator: " + elt.getInteractionOperator().getName());
+ }
- /**
- * @see org.eclipse.papyrus.diagram.tests.canonical.AbstractPapyrusTestCase#getDiagramCommandCreation()
- *
- * @return
- */
- @Override
- protected ICreationCommand getDiagramCommandCreation() {
- return new CreateSequenceDiagramCommand();
+ @Test
+ public void testInteractionOperand() {
+ CombinedFragmentEditPart cf = (CombinedFragmentEditPart)createNode(UMLElementTypes.CombinedFragment_3004, getRootEditPart(), new Point(100, 100), new Dimension(200, 100));
+ assertNotNull(cf);
+ String cfName = "Test Combined Fragment";
+ CombinedFragment elt = (CombinedFragment)cf.resolveSemanticElement();
+ changeName(getEditingDomain(), elt, cfName);
+ CombinedFragmentCombinedFragmentCompartmentEditPart compartment = (CombinedFragmentCombinedFragmentCompartmentEditPart)cf.getChildBySemanticHint("" + CombinedFragmentCombinedFragmentCompartmentEditPart.VISUAL_ID);
+ assertNotNull(compartment);
+ InteractionOperandEditPart operand = (InteractionOperandEditPart)createNode(UMLElementTypes.InteractionOperand_3005, compartment, getAbsoluteCenter(compartment), null);
+ assertNotNull(operand);
+ String name = "Test Interaction Operand";
+ changeName(getEditingDomain(), (NamedElement)operand.resolveSemanticElement(), name);
+ checkTooltip(operand.getFigure().getToolTip(), "Interaction Operand", "name: " + name + "\nparent:name: " + cfName + "\nparent:operator: " + elt.getInteractionOperator().getName());
+ }
+
+ @Test
+ public void testSynchronousMessage() {
+ LifelineEditPart lifeline1 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(lifeline1);
+ ActionExecutionSpecificationEditPart source = (ActionExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, lifeline1, getAbsoluteCenter(lifeline1), null);
+ assertNotNull(source);
+ LifelineEditPart lifeline2 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), null);
+ assertNotNull(lifeline2);
+ ActionExecutionSpecificationEditPart target = (ActionExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, lifeline2, getAbsoluteCenter(lifeline2), null);
+ assertNotNull(target);
+ MessageEditPart message = (MessageEditPart)createLink(UMLElementTypes.Message_4003, lifeline1.getViewer(), getAbsoluteCenter(source), getAbsoluteCenter(target));
+ assertNotNull(message);
+ String name = "Test Synchronous Message";
+ changeName(getEditingDomain(), (NamedElement)message.resolveSemanticElement(), name);
+ checkTooltip(message.getFigure().getToolTip(), "Synchronous Message", "name: " + name);
}
@Test
- protected void testLifelineTooltip() {
+ public void testAsynchronousMessage() {
+ LifelineEditPart source = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(source);
+ LifelineEditPart target = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), null);
+ assertNotNull(target);
+ Message2EditPart message = (Message2EditPart)createLink(UMLElementTypes.Message_4004, source.getViewer(), getAbsoluteCenter(source), getAbsoluteCenter(target));
+ assertNotNull(message);
+ String name = "Test Asynchronous Message";
+ changeName(getEditingDomain(), (NamedElement)message.resolveSemanticElement(), name);
+ checkTooltip(message.getFigure().getToolTip(), "Asynchronous Message", "name: " + name);
+ }
+
+ @Test
+ public void testCreateMessage() {
+ LifelineEditPart source = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(source);
+ LifelineEditPart target = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), null);
+ assertNotNull(target);
+ Message4EditPart message = (Message4EditPart)createLink(UMLElementTypes.Message_4006, source.getViewer(), getAbsoluteCenter(source), getAbsoluteCenter(target));
+ assertNotNull(message);
+ String name = "Test Create Message";
+ changeName(getEditingDomain(), (NamedElement)message.resolveSemanticElement(), name);
+ checkTooltip(message.getFigure().getToolTip(), "Create Message", "name: " + name);
+ }
+
+ @Test
+ public void testReplyMessage() {
+ LifelineEditPart lifeline1 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), null);
+ assertNotNull(lifeline1);
+ ActionExecutionSpecificationEditPart source = (ActionExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, lifeline1, getAbsoluteCenter(lifeline1).getTranslated(0, -100), null);
+ assertNotNull(source);
+ LifelineEditPart lifeline2 = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(lifeline2);
+ ActionExecutionSpecificationEditPart target = (ActionExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, lifeline2, getAbsoluteCenter(lifeline2).getTranslated(0, 100), null);
+ assertNotNull(target);
+ Message3EditPart message = (Message3EditPart)createLink(UMLElementTypes.Message_4005, source.getViewer(), getAbsoluteCenter(source), getAbsoluteCenter(target));
+ assertNotNull(message);
+ String name = "Test Reply Message";
+ changeName(getEditingDomain(), (NamedElement)message.resolveSemanticElement(), name);
+ checkTooltip(message.getFigure().getToolTip(), "Reply Message", "name: " + name);
+ }
+
+ @Test
+ public void testFoundMessage() {
+ LifelineEditPart target = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), null);
+ assertNotNull(target);
+ Point targetLocation = getAbsoluteCenter(target);
+ Point sourceLocation = targetLocation.getTranslated(-100, 0);
+ Message7EditPart message = (Message7EditPart)createLink(UMLElementTypes.Message_4009, target.getViewer(), sourceLocation, targetLocation);
+ assertNotNull(message);
+ String name = "Test Found Message";
+ changeName(getEditingDomain(), (NamedElement)message.resolveSemanticElement(), name);
+ checkTooltip(message.getFigure().getToolTip(), "Found Message", "name: " + name);
+ }
+
+ @Test
+ public void testLostMessage() {
+ LifelineEditPart source = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), null);
+ assertNotNull(source);
+ Point sourceLocation = getAbsoluteCenter(source);
+ Point targetLocation = sourceLocation.getTranslated(100, 0);
+ Message6EditPart message = (Message6EditPart)createLink(UMLElementTypes.Message_4008, source.getViewer(), sourceLocation, targetLocation);
+ assertNotNull(message);
+ String name = "Test Lost Message";
+ changeName(getEditingDomain(), (NamedElement)message.resolveSemanticElement(), name);
+ checkTooltip(message.getFigure().getToolTip(), "Lost Message", "name: " + name);
+ }
+
+ @Test
+ public void testDeleteMessage() {
+ LifelineEditPart source = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(source);
+ LifelineEditPart target = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), null);
+ assertNotNull(target);
+ Message5EditPart message = (Message5EditPart)createLink(UMLElementTypes.Message_4007, source.getViewer(), getAbsoluteCenter(source), getAbsoluteCenter(target));
+ assertNotNull(message);
+ String name = "Test Delete Message";
+ changeName(getEditingDomain(), (NamedElement)message.resolveSemanticElement(), name);
+ checkTooltip(message.getFigure().getToolTip(), "Delete Message", "name: " + name);
+ }
+
+ @Test
+ public void testMessageOccurrenceSpecification() {
+ LifelineEditPart source = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(source);
+ LifelineEditPart target = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), null);
+ assertNotNull(target);
+ Message2EditPart message = (Message2EditPart)createLink(UMLElementTypes.Message_4004, source.getViewer(), getAbsoluteCenter(source), getAbsoluteCenter(target));
+ assertNotNull(message);
+ MessageEndEditPart messageEnd = (MessageEndEditPart)message.getChildBySemanticHint("999999");
+ assertNotNull(messageEnd);
+ String name = "Test Message Occurrence Specification";
+ changeName(getEditingDomain(), (NamedElement)messageEnd.resolveSemanticElement(), name);
+ checkTooltip(messageEnd.getFigure().getToolTip(), "Message Occurrence Specification", "name: " + name);
+ }
+
+ @Test
+ public void testExecutionOccurrenceSpecification() {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(lifeline);
+ ActionExecutionSpecificationEditPart es = (ActionExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, lifeline, getAbsoluteCenter(lifeline), null);
+ assertNotNull(es);
+ ExecutionSpecificationEndEditPart esEnd = (ExecutionSpecificationEndEditPart)es.getChildren().get(0);
+ assertNotNull(esEnd);
+ String name = "Test Execution Occurrence Specification";
+ changeName(getEditingDomain(), (NamedElement)esEnd.resolveSemanticElement(), name);
+ checkTooltip(esEnd.getFigure().getToolTip(), "Execution Occurrence Specification", "name: " + name);
+ }
+
+ @Test
+ public void testInteractionUse() {
+ InteractionUseEditPart interactionUse = (InteractionUseEditPart)createNode(UMLElementTypes.InteractionUse_3002, getRootEditPart(), new Point(300, 200), new Dimension(200, 100));
+ assertNotNull(interactionUse);
+ String name = "Test Interaction Use";
+ NamedElement element = (NamedElement)interactionUse.resolveSemanticElement();
+ changeName(getEditingDomain(), element, name);
+ checkTooltip(interactionUse.getFigure().getToolTip(), "Interaction Use", "name: " + name);
+ //add Refer
+ final String referInteractionName = "Refered Interaction";
+ final List<Interaction> refers = new ArrayList<Interaction>();
+ final Model model = (Model)getPackage();
+ getDiagramCommandStack().execute(new ICommandProxy(new AbstractTransactionalCommand(getEditingDomain(), "", null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ Interaction interaction = (Interaction)model.createPackagedElement(referInteractionName, UMLPackage.Literals.INTERACTION);
+ refers.add(interaction);
+ return CommandResult.newOKCommandResult();
+ }
+ }));
+ waitForComplete();
+ assertEquals(refers.size(), 1);
+ Command command = createSetCommand(getEditingDomain(), element, UMLPackage.Literals.INTERACTION_USE__REFERS_TO, refers.get(0));
+ assertNotNull(command);
+ assertEquals(true, command.canExecute());
+ getDiagramCommandStack().execute(command);
+ waitForComplete();
+ checkTooltip(interactionUse.getFigure().getToolTip(), "Interaction Use", "name: " + name + "\nref: " + referInteractionName);
+ }
+
+ @Test
+ public void testStateInvariant() {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(lifeline);
+ Rectangle r = getAbsoluteBounds(lifeline);
+ StateInvariantEditPart stateInvariant = (StateInvariantEditPart)createNode(UMLElementTypes.StateInvariant_3017, lifeline, r.getCenter(), null);
+ assertNotNull(stateInvariant);
+ String name = "Test State Invariant";
+ changeName(getEditingDomain(), (NamedElement)stateInvariant.resolveSemanticElement(), name);
+ checkTooltip(stateInvariant.getFigure().getToolTip(), "State Invariant", "");
+ }
+
+ @Test
+ public void testDestructionEvent() {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(lifeline);
+ DestructionOccurrenceSpecificationEditPart destructionEvent = (DestructionOccurrenceSpecificationEditPart)createNode(UMLElementTypes.DestructionOccurrenceSpecification_3022, lifeline, getAbsoluteCenter(lifeline), null);
+ assertNotNull(destructionEvent);
+ checkTooltip(destructionEvent.getFigure().getToolTip(), "Destruction Event", "");
+ }
+
+ @Test
+ public void testGeneralOrdering() {
+ LifelineEditPart source = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(source);
+ LifelineEditPart target = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(300, 100), null);
+ assertNotNull(target);
+ Point sourcePoint = getAbsoluteCenter(source);
+ Point targetPoint = getAbsoluteCenter(target);
+ Message2EditPart message1 = (Message2EditPart)createLink(UMLElementTypes.Message_4004, source.getViewer(), sourcePoint, targetPoint);
+ assertNotNull(message1);
+ Message2EditPart message2 = (Message2EditPart)createLink(UMLElementTypes.Message_4004, source.getViewer(), sourcePoint.getTranslated(0, 50), targetPoint.getTranslated(0, 50));
+ assertNotNull(message2);
+ sourcePoint = SequenceUtil.getAbsoluteEdgeExtremity(message1, true);
+ targetPoint = SequenceUtil.getAbsoluteEdgeExtremity(message2, false);
+ GeneralOrderingEditPart generalOrdering = (GeneralOrderingEditPart)createLink(UMLElementTypes.GeneralOrdering_4012, source.getViewer(), sourcePoint, targetPoint);
+ assertNotNull(generalOrdering);
+ checkTooltip(generalOrdering.getFigure().getToolTip(), "General Ordering", "");
+ }
+
+ @Test
+ public void testCoRegion() {
+ LifelineEditPart lifeline = (LifelineEditPart)createNode(UMLElementTypes.Lifeline_3001, getRootEditPart(), new Point(100, 100), null);
+ assertNotNull(lifeline);
+ Rectangle r = getAbsoluteBounds(lifeline);
+ CombinedFragment2EditPart coRegion = (CombinedFragment2EditPart)createNode(UMLElementTypes.CombinedFragment_3018, lifeline, r.getCenter(), null);
+ assertNotNull(coRegion);
+ checkTooltip(coRegion.getFigure().getToolTip(), "Co Region", "");
+ }
+
+ private void checkTooltip(IFigure figure, String name, String description) {
+ assertNotNull(figure);
+ assertTrue(figure instanceof TooltipFigure);
+ TooltipFigure tipFig = (TooltipFigure)figure;
+ tipFig.update();
+ assertEquals("Tooltip Name: ", trim(name), trim(tipFig.getName()));
+ assertEquals("Tooltip Description: ", trim(description), trim(tipFig.getDescription()));
+ }
+ private String trim(String str) {
+ return str == null ? null : str.trim();
}
}

Back to the top