Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6af460bbb43f69f51ddfb13febd55cf73fb56402 (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
/*****************************************************************************
 * Copyright (c) 2013 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 org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
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.uml.diagram.sequence.edit.parts.AbstractExecutionSpecificationEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message3EditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
import org.eclipse.uml2.uml.ExecutionSpecification;
import org.eclipse.uml2.uml.Message;
import org.eclipse.uml2.uml.OccurrenceSpecification;
import org.junit.Test;

/**
 * @author Jin Liu (jin.liu@soyatec.com)
 */
public class TestMessageOccurrenceSpecification_402975 extends AbstractNodeTest {

	protected EditPart createNode(IElementType type, EditPart parentPart, Point location, Dimension size) {
		EditPart node = super.createNode(type, parentPart, location, size);
		assertNotNull("Create Node Failed: " + type.getDisplayName(), node);
		return node;
	}

	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;
	}

	private void doCheckExecution(ExecutionSpecification execution, Message message, boolean isStart) {
		if(execution == null) {
			return;
		}
		OccurrenceSpecification start = execution.getStart();
		assertNotNull("execution start event", start);
		OccurrenceSpecification finish = execution.getFinish();
		assertNotNull("execution finish event", finish);
		//		if(message != null) {
		//			MessageSort messageSort = message.getMessageSort();
		//			if(isStart && MessageSort.SYNCH_CALL_LITERAL == messageSort) {
		//				assertEquals("execution start == message target", message.getReceiveEvent(), start);
		//			} else if(!isStart && MessageSort.REPLY_LITERAL == messageSort) {
		//				assertEquals("execution finish == message source", message.getSendEvent(), finish);
		//			}
		//		} else {
		//			assertTrue("execution start type", start instanceof ExecutionOccurrenceSpecification);
		//			assertTrue("execution finish type", finish instanceof ExecutionOccurrenceSpecification);
		//		}
	}

	private void doCheckExecution(ExecutionSpecification execution) {
		doCheckExecution(execution, null, false);
	}

	@Test
	public void testCreateSyncMessage() {
		AbstractExecutionSpecificationEditPart part1 = createExecutionSpecificationWithLifeline(new Point(50, 100), null);
		AbstractExecutionSpecificationEditPart part2 = createExecutionSpecificationWithLifeline(new Point(200, 100), null);
		Point startLocation = getAbsoluteBounds(part1).getCenter();
		Point endLocation = getAbsoluteCenter(part2).setY(startLocation.y + 1);
		ExecutionSpecification execution = (ExecutionSpecification)part2.resolveSemanticElement();
		assertNotNull("execution", execution);
		doCheckExecution(execution);
		MessageEditPart message = (MessageEditPart)createLink(UMLElementTypes.Message_4003, part1.getViewer(), startLocation, part1, endLocation, part2);
		assertNotNull("Sync message", message);
		Message msg = (Message)message.resolveSemanticElement();
		assertNotNull("message", msg);
		doCheckExecution(execution, msg, true);
		getDiagramCommandStack().undo();
		doCheckExecution(execution);
		getDiagramCommandStack().redo();
		message = (MessageEditPart)part2.getTargetConnections().get(0);
		msg = (Message)message.resolveSemanticElement();
		assertNotNull("message", msg);
		doCheckExecution(execution, msg, true);
	}

	@Test
	public void testReconnectSyncMessage() {
		AbstractExecutionSpecificationEditPart part1 = createExecutionSpecificationWithLifeline(new Point(50, 100), null);
		AbstractExecutionSpecificationEditPart part2 = createExecutionSpecificationWithLifeline(new Point(200, 100), null);
		Point startLocation = getAbsoluteBounds(part1).getCenter();
		Point endLocation = getAbsoluteCenter(part2).setY(startLocation.y + 1);
		ExecutionSpecification execution2 = (ExecutionSpecification)part2.resolveSemanticElement();
		assertNotNull("execution2", execution2);
		doCheckExecution(execution2);
		MessageEditPart messagePart = (MessageEditPart)createLink(UMLElementTypes.Message_4003, part1.getViewer(), startLocation, part1, endLocation, part2);
		assertNotNull("Sync message", messagePart);
		Message message = (Message)messagePart.resolveSemanticElement();
		assertNotNull("message", message);
		doCheckExecution(execution2, message, true);
		AbstractExecutionSpecificationEditPart part3 = (AbstractExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, part2.getParent(), getAbsoluteBounds(part2).getLocation().getTranslated(0, 100), null);
		ExecutionSpecification execution3 = (ExecutionSpecification)part3.resolveSemanticElement();
		assertNotNull("execution3", execution3);
		//reconnect from execution2 to execution3.
		reconnectTarget(messagePart, part3, getAbsoluteBounds(part3).getLocation());
		doCheckExecution(execution2);
		doCheckExecution(execution3, message, true);
		getDiagramCommandStack().undo();
		doCheckExecution(execution3);
		doCheckExecution(execution2, message, true);
		getDiagramCommandStack().redo();
		assertNotNull("message", message);
		doCheckExecution(execution2);
		doCheckExecution(execution3, message, true);
	}

	@Test
	public void testDeleteSyncMessage() {
		AbstractExecutionSpecificationEditPart part1 = createExecutionSpecificationWithLifeline(new Point(50, 100), null);
		AbstractExecutionSpecificationEditPart part2 = createExecutionSpecificationWithLifeline(new Point(200, 100), null);
		Point startLocation = getAbsoluteBounds(part1).getCenter();
		Point endLocation = getAbsoluteCenter(part2).setY(startLocation.y + 1);
		ExecutionSpecification execution2 = (ExecutionSpecification)part2.resolveSemanticElement();
		assertNotNull("execution2", execution2);
		doCheckExecution(execution2);
		MessageEditPart messagePart = (MessageEditPart)createLink(UMLElementTypes.Message_4003, part1.getViewer(), startLocation, part1, endLocation, part2);
		assertNotNull("Sync message", messagePart);
		Message message = (Message)messagePart.resolveSemanticElement();
		assertNotNull("message", message);
		doCheckExecution(execution2, message, true);
		deleteMessage(messagePart);
		doCheckExecution(execution2);
	}

	/**
	 * @param editPart
	 */
	private void deleteMessage(EditPart editPart) {
		assertNotNull(editPart);
		Request deleteViewRequest = new EditCommandRequestWrapper(new DestroyElementRequest(false));
		Command command = editPart.getCommand(deleteViewRequest);
		assertNotNull("delete command", command);
		assertTrue("delete command executable", command.canExecute());
		getDiagramCommandStack().execute(command);
		waitForComplete();
	}

	@Test
	public void testCreateReplyMessage() {
		AbstractExecutionSpecificationEditPart part1 = createExecutionSpecificationWithLifeline(new Point(200, 100), null);
		AbstractExecutionSpecificationEditPart part2 = createExecutionSpecificationWithLifeline(new Point(50, 100), null);
		Point startLocation = getAbsoluteBounds(part1).getCenter();
		Point endLocation = getAbsoluteBounds(part2).getBottom();
		ExecutionSpecification execution = (ExecutionSpecification)part1.resolveSemanticElement();
		assertNotNull("execution", execution);
		doCheckExecution(execution);
		Message3EditPart messagePart = (Message3EditPart)createLink(UMLElementTypes.Message_4005, part1.getViewer(), startLocation, part1, endLocation, part2);
		assertNotNull("Reply message", messagePart);
		Message message = (Message)messagePart.resolveSemanticElement();
		assertNotNull("message", message);
		doCheckExecution(execution, message, false);
		getDiagramCommandStack().undo();
		doCheckExecution(execution);
		getDiagramCommandStack().redo();
		messagePart = (Message3EditPart)part1.getSourceConnections().get(0);
		message = (Message)messagePart.resolveSemanticElement();
		assertNotNull("message", message);
		doCheckExecution(execution, message, false);
	}

	@Test
	public void testReconnectReplyMessage() {
		AbstractExecutionSpecificationEditPart part1 = createExecutionSpecificationWithLifeline(new Point(200, 100), null);
		AbstractExecutionSpecificationEditPart part2 = createExecutionSpecificationWithLifeline(new Point(50, 100), null);
		Point startLocation = getAbsoluteBounds(part1).getCenter();
		Point endLocation = getAbsoluteBounds(part2).getBottom();
		ExecutionSpecification execution = (ExecutionSpecification)part1.resolveSemanticElement();
		assertNotNull("execution", execution);
		doCheckExecution(execution);
		Message3EditPart messagePart = (Message3EditPart)createLink(UMLElementTypes.Message_4005, part1.getViewer(), startLocation, part1, endLocation, part2);
		assertNotNull("Reply message", messagePart);
		Message message = (Message)messagePart.resolveSemanticElement();
		assertNotNull("message", message);
		doCheckExecution(execution, message, false);
		Point location = startLocation.getTranslated(0, -100);
		AbstractExecutionSpecificationEditPart part3 = (AbstractExecutionSpecificationEditPart)createNode(UMLElementTypes.ActionExecutionSpecification_3006, part1.getParent(), location, null);
		ExecutionSpecification execution3 = (ExecutionSpecification)part3.resolveSemanticElement();
		assertNotNull("execution3", execution3);
		//reconnect from execution to execution3.
		reconnectSource(messagePart, part3, getAbsoluteBounds(part3).getLocation());
		doCheckExecution(execution);
		doCheckExecution(execution3, message, false);
		getDiagramCommandStack().undo();
		doCheckExecution(execution3);
		doCheckExecution(execution, message, false);
		getDiagramCommandStack().redo();
		assertNotNull("message", message);
		doCheckExecution(execution);
		doCheckExecution(execution3, message, false);
	}

	@Test
	public void testDeleteReplyMessage() {
		AbstractExecutionSpecificationEditPart part1 = createExecutionSpecificationWithLifeline(new Point(200, 100), null);
		AbstractExecutionSpecificationEditPart part2 = createExecutionSpecificationWithLifeline(new Point(50, 100), null);
		Point startLocation = getAbsoluteBounds(part1).getCenter();
		Point endLocation = getAbsoluteBounds(part2).getBottom();
		ExecutionSpecification execution = (ExecutionSpecification)part1.resolveSemanticElement();
		assertNotNull("execution", execution);
		doCheckExecution(execution);
		Message3EditPart messagePart = (Message3EditPart)createLink(UMLElementTypes.Message_4005, part1.getViewer(), startLocation, part1, endLocation, part2);
		assertNotNull("Reply message", messagePart);
		Message message = (Message)messagePart.resolveSemanticElement();
		assertNotNull("message", message);
		doCheckExecution(execution, message, false);
		deleteMessage(messagePart);
		doCheckExecution(execution);
	}
}

Back to the top