Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 99e802860dc4767d626c92442e697a5d01f29d09 (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
/*****************************************************************************
 * 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.canonical;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
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.requests.CreateViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
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.LifelineEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
import org.eclipse.uml2.uml.ActionExecutionSpecification;
import org.eclipse.uml2.uml.BehaviorExecutionSpecification;
import org.eclipse.uml2.uml.DestructionOccurrenceSpecification;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.InteractionFragment;
import org.eclipse.uml2.uml.Lifeline;
import org.junit.Test;


public class TestSequenceDiagramChildNode extends TestChildNode {

	@Override
	protected CreateViewRequest createViewRequestShapeContainer() {
		return CreateViewRequestFactory.getCreateShapeRequest(UMLElementTypes.Lifeline_3001, getDiagramEditPart().getDiagramPreferencesHint());
	}

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

	@Test
	public void testToManageActionExecution() {
		testToManageChildNode(UMLElementTypes.ActionExecutionSpecification_3006, lifelineProvider);
	}

	@Test
	public void testToManageBehaviorExecution() {
		testToManageChildNode(UMLElementTypes.BehaviorExecutionSpecification_3003, lifelineProvider);
	}

	@Test
	public void testToManageDestructionOccurrence() {
		testToManageChildNode(UMLElementTypes.DestructionOccurrenceSpecification_3022, lifelineProvider);
	}

	@Test
	public void testToManageCoRegion() {
		semanticChild = false;
		testToManageChildNode(UMLElementTypes.CombinedFragment_3018, lifelineProvider);
		semanticChild = true;
	}

	@Test
	public void testToManageStateInvariant() {
		semanticChild = false;
		testToManageChildNode(UMLElementTypes.StateInvariant_3017, lifelineProvider);
		semanticChild = true;
	}


	@Test
	public void testToManageTimeConstraint() {
		createChildNode(UMLElementTypes.ActionExecutionSpecification_3006, lifelineProvider);
		semanticChild = false;
		testToManageChildNode(UMLElementTypes.TimeConstraint_3019, executionProvider);
		semanticChild = true;
	}

	@Test
	public void testToManageDurationConstraint() {
		createChildNode(UMLElementTypes.ActionExecutionSpecification_3006, lifelineProvider);
		semanticChild = false;

		testToCreateChildNode(UMLElementTypes.ActionExecutionSpecification_3006, executionProvider);
		{
			//DESTROY SEMANTIC+ VIEW
			IChildTestProvider provider = executionProvider;
			assertTrue(DESTROY_DELETION + INITIALIZATION_TEST, provider.getEditPartChildrenSize() == 1);
			assertTrue(DESTROY_DELETION + INITIALIZATION_TEST, provider.getViewChildrenSize() == 1);
			assertTrue(DESTROY_DELETION + INITIALIZATION_TEST, !provider.hasSemanticChild() || provider.getSemanticChildrenSize() == 1);

			Request deleteViewRequest = new EditCommandRequestWrapper(new DestroyElementRequest(false));
			Command command = provider.getDestroyEditPart().getCommand(deleteViewRequest);
			assertNotNull(DESTROY_DELETION + COMMAND_NULL, command);
			assertTrue(DESTROY_DELETION + TEST_IF_THE_COMMAND_IS_CREATED, command != UnexecutableCommand.INSTANCE);
			assertTrue(DESTROY_DELETION + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute() == true);

			getEMFCommandStack().execute(new GEFtoEMFCommandWrapper(command));
			assertTrue(DESTROY_DELETION + TEST_THE_EXECUTION, provider.getEditPartChildrenSize() == 0);
			assertTrue(DESTROY_DELETION + TEST_THE_EXECUTION, provider.getViewChildrenSize() == 0);
			assertTrue(DESTROY_DELETION + TEST_THE_EXECUTION, provider.getSemanticChildrenSize() == 0);
		}

		// the node has been destroyed, the UML element also
		getEMFCommandStack().undo();

		// the node and the UML element are present
		testViewDeletion(UMLElementTypes.ActionExecutionSpecification_3006, executionProvider);

		semanticChild = true;
	}

	GraphicalEditPart containerEditPart;

	boolean semanticChild = true;

	IChildTestProvider executionProvider = new IChildTestProvider() {

		public int getEditPartChildrenSize() {
			return TestSequenceDiagramChildNode.this.lifelineProvider.getEditPartChildrenSize() - 1; // ignore ActionExecution
		}

		public int getSemanticChildrenSize() {
			return TestSequenceDiagramChildNode.this.lifelineProvider.getSemanticChildrenSize() - 1;
		}

		public int getViewChildrenSize() {
			return TestSequenceDiagramChildNode.this.lifelineProvider.getViewChildrenSize() - 1;
		}

		public Element getDropElement() {
			return null;
		}

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

		public GraphicalEditPart getDestroyEditPart() {
			return (GraphicalEditPart)getParentEditPart().getChildren().get(2);
		}

		public boolean hasSemanticChild() {
			return semanticChild;
		}

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

	IChildTestProvider lifelineProvider = new IChildTestProvider() {

		public int getEditPartChildrenSize() {
			return getParentEditPart().getChildren().size() - 1; // ignore LifelineNameEditPart
		}

		public int getSemanticChildrenSize() {
			Lifeline lifeline = ((Lifeline)getParentEditPart().getNotationView().getElement());
			int count = 0;
			for(InteractionFragment f : lifeline.getCoveredBys())
				if(f instanceof DestructionOccurrenceSpecification || f instanceof ActionExecutionSpecification || f instanceof BehaviorExecutionSpecification)
					count++;

			return count;
		}

		public int getViewChildrenSize() {
			return getParentEditPart().getNotationView().getChildren().size() - 1; // ignore LifelineNameEditPart view
		}

		public Element getDropElement() {
			return null;
		}

		public GraphicalEditPart getParentEditPart() {
			if(containerEditPart == null) {
				GraphicalEditPart ep = (GraphicalEditPart)getRootEditPart().getChildren().get(0);
				containerEditPart = ep;
			}
			return containerEditPart;
		}

		public GraphicalEditPart getDestroyEditPart() {
			return (GraphicalEditPart)getParentEditPart().getChildren().get(1);
		}

		public boolean hasSemanticChild() {
			return semanticChild;
		}

		public Point getChildLocation(GraphicalEditPart parentEditPart) {
			IFigure f = ((LifelineEditPart)parentEditPart).getPrimaryShape().getFigureLifelineDotLineFigure();
			Rectangle b = f.getBounds().getCopy();
			f.translateToAbsolute(b);
			return b.getCenter().getCopy().translate(0, 50);
		}
	};
}

Back to the top