Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6c444d8357c12a340dce35e09ed85c4fbf0f681c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*****************************************************************************
 * Copyright (c) 2012 CEA LIST.
 *
 *    
 * 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:
 *   CEA LIST - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.tests.bug;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
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.EditCommandRequestWrapper;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.papyrus.commands.ICreationCommand;
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.InteractionEditPart;
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.ILinkTestProvider;
import org.eclipse.papyrus.uml.diagram.sequence.tests.canonical.TestLink;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ExecutionOccurrenceSpecification;
import org.eclipse.uml2.uml.Interaction;
import org.eclipse.uml2.uml.InteractionFragment;
import org.eclipse.uml2.uml.MessageEnd;
import org.junit.Test;

/**
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=364828
 * When a message is deleted, its associated send and receive events are not
 * deleted. These events must be deleted because new events are systematically
 * created upon the creation of a new message.
 * 
 * It fixes the deletion of the associated send MessageSend and receive
 * MessageRecv events for
 * - Message Sync
 * - Message Async
 * - Message Reply
 * - Message Create
 * - Message Delete
 * 
 */
public class TestMessagesDeletion_364828 extends TestLink {

	@Override
	protected ICreationCommand getDiagramCommandCreation() {
		return new CreateSequenceDiagramCommand();
	}

	@Override
	public CreateConnectionViewRequest createConnectionViewRequest(IElementType type, EditPart source, EditPart target, ILinkTestProvider provider) {
		CreateConnectionViewRequest request = super.createConnectionViewRequest(type, source, target, provider);
		EObject container = getRootEditPart().resolveSemanticElement();
		request.getExtendedData().put(SOURCE_MODEL_CONTAINER, container);
		request.getExtendedData().put(TARGET_MODEL_CONTAINER, container);
		return request;
	}

	public void deleteMessageEvents(IElementType sourceType, IElementType targetType, IElementType linkType, ILinkTestProvider provider) {
		installEnvironment(sourceType, targetType, provider);
		Interaction interaction = (Interaction)getRootEditPart().resolveSemanticElement();

		// create message link
		CreateConnectionViewRequest req = createConnectionViewRequest(linkType, source, target, provider);
		Command command = target.getCommand(req);
		assertNotNull(CREATION + COMMAND_NULL, command);
		assertTrue(CONTAINER_CREATION + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute() == true);
		getDiagramCommandStack().execute(command);

		// delete message link
		assertTrue(DESTROY_DELETION + INITIALIZATION_TEST, provider.getEdgesSize() == 1);
		assertTrue(DESTROY_DELETION + INITIALIZATION_TEST, getMessageEndCount(interaction.getFragments()) == 2);
		Request deleteViewRequest = new EditCommandRequestWrapper(new DestroyElementRequest(false));
		Command delCommand = ((ConnectionEditPart)source.getSourceConnections().get(0)).getCommand(deleteViewRequest);
		assertNotNull(DESTROY_DELETION + COMMAND_NULL, delCommand);
		assertTrue(DESTROY_DELETION + TEST_IF_THE_COMMAND_IS_CREATED, delCommand != UnexecutableCommand.INSTANCE);
		assertTrue(DESTROY_DELETION + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, delCommand.canExecute() == true);
		getEMFCommandStack().execute(new GEFtoEMFCommandWrapper(delCommand));
		assertTrue(DESTROY_DELETION + TEST_THE_EXECUTION, getMessageEndCount(interaction.getFragments()) == 0);

		getEMFCommandStack().undo();
		assertTrue(DESTROY_DELETION + TEST_THE_UNDO, getMessageEndCount(interaction.getFragments()) == 2);

		getEMFCommandStack().redo();
		assertTrue(DESTROY_DELETION + TEST_THE_REDO, getMessageEndCount(interaction.getFragments()) == 0);
	}

	private int getMessageEndCount(EList<InteractionFragment> fragments) {
		int count = 0;
		for(InteractionFragment f : fragments)
			if(f instanceof MessageEnd)
				count++;

		return count;
	}

	@Test
	public void testMessageAsync_4004() {
		deleteMessageEvents(UMLElementTypes.Lifeline_3001, UMLElementTypes.Lifeline_3001, UMLElementTypes.Message_4004, lifelineProvider);
	}

	@Test
	public void testMessageSync_4003() {
		deleteMessageEvents(UMLElementTypes.Lifeline_3001, UMLElementTypes.Lifeline_3001, UMLElementTypes.Message_4003, executionProvider);
	}

	@Test
	public void testMessageReply_4005() {
		deleteMessageEvents(UMLElementTypes.Lifeline_3001, UMLElementTypes.Lifeline_3001, UMLElementTypes.Message_4005, executionProvider);
	}

	@Test
	public void testMessageDelete_4007() {
		deleteMessageEvents(UMLElementTypes.Lifeline_3001, UMLElementTypes.Lifeline_3001, UMLElementTypes.Message_4007, lifelineProvider);
	}

	@Test
	public void testMessageCreate_4006() {
		deleteMessageEvents(UMLElementTypes.Lifeline_3001, UMLElementTypes.Lifeline_3001, UMLElementTypes.Message_4006, lifelineProvider);
	}

	protected ILinkTestProvider executionProvider = new ILinkTestProvider() {


		public boolean hasSemanticChild() {
			return TestMessagesDeletion_364828.this.lifelineProvider.hasSemanticChild();
		}

		public Point getChildLocation(GraphicalEditPart parentEditPart) {
			return TestMessagesDeletion_364828.this.lifelineProvider.getChildLocation(parentEditPart);
		}

		public int getEditPartChildrenSize() {
			return TestMessagesDeletion_364828.this.lifelineProvider.getEditPartChildrenSize();
		}

		public Element getDropElement() {
			return null;
		}

		public int getSemanticChildrenSize() {
			return TestMessagesDeletion_364828.this.lifelineProvider.getSemanticChildrenSize() - 4; // ignore ActionExecution
		}

		public int getViewChildrenSize() {
			return TestMessagesDeletion_364828.this.lifelineProvider.getViewChildrenSize();
		}

		public GraphicalEditPart getParentEditPart() {
			return TestMessagesDeletion_364828.this.lifelineProvider.getParentEditPart();
		}

		public GraphicalEditPart getDestroyEditPart() {
			return null;
		}

		public int getEdgesSize() {
			return TestMessagesDeletion_364828.this.lifelineProvider.getEdgesSize();
		}

		public Point getConnectionSourceLocation(EditPart source) {
			return TestMessagesDeletion_364828.this.lifelineProvider.getConnectionSourceLocation(source);
		}

		public Point getConnectionTargetLocation(EditPart target) {
			return TestMessagesDeletion_364828.this.lifelineProvider.getConnectionTargetLocation(target);
		}

		public void setUp() {
			IElementType childNodeType = UMLElementTypes.ActionExecutionSpecification_3006;
			source = createSubNode(source, childNodeType, getChildLocation(source));
			sourcePlayer = createSubNode(sourcePlayer, childNodeType, getChildLocation(sourcePlayer));

			target = createSubNode(target, childNodeType, getChildLocation(target).translate(0, 50));
			targetPlayer = createSubNode(targetPlayer, childNodeType, getChildLocation(targetPlayer).translate(0, 50));
		}

	};

	protected ILinkTestProvider lifelineProvider = new ILinkTestProvider() {

		public int getEdgesSize() {
			return getDiagramEditPart().getDiagramView().getEdges().size();
		}

		public int getEditPartChildrenSize() {
			return getRootEditPart().getChildren().size();
		}

		public int getSemanticChildrenSize() {
			int count = 0;
			EList<Element> elems = ((Element)getRootEditPart().getNotationView().getElement()).getOwnedElements();
			for(Element f : elems)
				if(!(f instanceof MessageEnd) && !(f instanceof ExecutionOccurrenceSpecification))
					count++;

			return count;
		}

		public int getViewChildrenSize() {
			return getRootEditPart().getNotationView().getChildren().size();
		}

		public Element getDropElement() {
			return null;
		}

		public GraphicalEditPart getParentEditPart() {
			return getRootEditPart();
		}

		public GraphicalEditPart getDestroyEditPart() {
			return null;
		}

		public Point getConnectionSourceLocation(EditPart part) {
			if(part instanceof LifelineEditPart) {
				IFigure f = ((LifelineEditPart)part).getPrimaryShape().getFigureLifelineDotLineFigure();
				return getCenter(f);
			}
			if(part instanceof AbstractExecutionSpecificationEditPart || part instanceof InteractionEditPart) { // found message
				return getAbsoluteBounds((IGraphicalEditPart)part).getTopLeft();
			}
			return new Point(0, 0);
		}

		public Point getConnectionTargetLocation(EditPart part) {
			if(part instanceof LifelineEditPart) {
				IFigure f = ((LifelineEditPart)part).getPrimaryShape().getFigureLifelineDotLineFigure();
				return getCenter(f);
			}
			if(part instanceof AbstractExecutionSpecificationEditPart || part instanceof InteractionEditPart) {
				Rectangle r = getAbsoluteBounds((IGraphicalEditPart)part);
				return r.getBottom();
			}
			return new Point(0, 0);
		}

		public boolean hasSemanticChild() {
			return true;
		}

		public Point getChildLocation(GraphicalEditPart parentEditPart) {
			IFigure f = ((LifelineEditPart)parentEditPart).getPrimaryShape().getFigureLifelineDotLineFigure();
			return getCenter(f).translate(0, 1);
		}

		public void setUp() {
		}
	};

	private Point getCenter(IFigure f) {
		Rectangle b = f.getBounds().getCopy();
		f.translateToAbsolute(b);
		Point c = b.getCenter().getCopy();
		return c;
	}
}

Back to the top