Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 60f48570a1e1654e942cf99e0ad9e8c57a5f98a2 (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
/*****************************************************************************
 * 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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.commands.ICreationCommand;
import org.eclipse.papyrus.infra.gmfdiag.common.updater.DiagramUpdater;
import org.eclipse.papyrus.uml.diagram.common.editparts.NamedElementEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionUseEditPart;
import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
import org.eclipse.papyrus.uml.diagram.sequence.tests.ISequenceDiagramTestsConstants;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Pseudostate;
import org.eclipse.uml2.uml.UMLPackage;
import org.junit.Assert;
import org.junit.Test;


public class TestSequenceDiagramInsideInteraction extends AbstractTestSequenceChildNode {

	//this test has been overloaded for combined fragment no name
	// and interactionUse Ref for the label.
	@Override
	protected void testNameLabel(EditPart createdEditPart, String initialName) {
		if (createdEditPart instanceof NamedElementEditPart && (!(createdEditPart instanceof CombinedFragmentEditPart))) {
			GraphicalEditPart namedEditPart = (GraphicalEditPart) ((NamedElementEditPart) createdEditPart).getPrimaryChildEditPart();
			Assert.assertTrue("the primary editpart must be the namelabelEditpart", namedEditPart instanceof ITextAwareEditPart); //$NON-NLS-1$
			String name = namedEditPart.resolveSemanticElement().eClass().getName();
			if (initialName != null) {
				name = initialName;
			}
			// Don't test if it's a Pseudostate: the name = the kind of element
			if (!(((View) namedEditPart.getModel()).getElement() instanceof Pseudostate)) {
				if (name.length() < ((ITextAwareEditPart) namedEditPart).getEditText().length()) {
					Assert.assertEquals(" the name must contain the name of the metaclass", name, ((ITextAwareEditPart) namedEditPart).getEditText().substring(0, name.length())); //$NON-NLS-1$
				} else {
					
					if(createdEditPart instanceof InteractionUseEditPart){
						//this is a particularity of interactionUse
						Assert.assertEquals(" the name must contain the name of the metaclass", "Ref", ((ITextAwareEditPart) namedEditPart).getEditText()); //$NON-NLS-1$
						
					}
					else{
						// not the same it sure but display the mistake is important
						Assert.assertEquals(" the name must contain the name of the metaclass", name, ((ITextAwareEditPart) namedEditPart).getEditText()); //$NON-NLS-1$
					}
				}
			}
			if (namedEditPart instanceof CompartmentEditPart) {
				Assert.assertTrue("the primary editpart must be the namelabelEditpart", namedEditPart instanceof CompartmentEditPart); //$NON-NLS-1$
				Assert.assertTrue("namelabelEditpart must be editable", ((CompartmentEditPart) namedEditPart).isEditModeEnabled()); //$NON-NLS-1$
			} else {
				Assert.assertTrue("the primary editpart must be the namelabelEditpart", namedEditPart instanceof LabelEditPart); //$NON-NLS-1$

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

	@Override
	protected String getProjectName() {
		return ISequenceDiagramTestsConstants.PROJECT_NAME;
	}

	@Override
	protected String getFileName() {
		return ISequenceDiagramTestsConstants.FILE_NAME;
	}

	@Override
	public DiagramUpdater getDiagramUpdater() {
		return null;
	}


	@Override
	protected boolean isSemanticTest() {
		// TODO Auto-generated method stub
		return false;
	}

	@Test
	public void testToManageLifeline() {
		testToManageNode(UMLElementTypes.Lifeline_Shape, UMLPackage.eINSTANCE.getLifeline(),UMLElementTypes.Interaction_Shape, false);
	}

	/**
	 * Test to manage constraint.
	 */
	@Test
	public void testToManageConstraint() {
		testToManageNode(UMLElementTypes.Constraint_Shape, UMLPackage.eINSTANCE.getConstraint(),UMLElementTypes.Interaction_Shape, false);
	}
	/**
	 * Test to manage constraint.
	 */
	@Test
	public void testToManageCombinedFragment() {
		testToManageNode(UMLElementTypes.CombinedFragment_Shape, UMLPackage.eINSTANCE.getCombinedFragment(),UMLElementTypes.Interaction_Shape, false);
	}

	/**
	 * Test to manage constraint.
	 */
	@Test
	public void testToManageConsiderIgnoreFragment() {
		testToManageNode(UMLElementTypes.ConsiderIgnoreFragment_Shape, UMLPackage.eINSTANCE.getConsiderIgnoreFragment(),UMLElementTypes.Interaction_Shape, false);
	}

	@Test
	public void testToManageDurationObservation() {
	
		testToManageNode(UMLElementTypes.DurationObservation_Shape,UMLPackage.eINSTANCE.getDurationObservation(),UMLElementTypes.Interaction_Shape	,false);
	}
	/**
	 * Test to manage comment.
	 */
	@Test
	public void testToManageComment() {
		testToManageNode(UMLElementTypes.Comment_Shape, UMLPackage.eINSTANCE.getComment(),UMLElementTypes.Interaction_Shape, false);
	}

	@Test
	public void testToManageInteractionUse() {
		testToManageNode(UMLElementTypes.InteractionUse_Shape, UMLPackage.eINSTANCE.getInteractionUse(),UMLElementTypes.Interaction_Shape, false);
	}
	
	/**
	 * @see org.eclipse.papyrus.uml.diagram.tests.canonical.AbstractTestNode#testDrop(org.eclipse.gmf.runtime.emf.type.core.IElementType, org.eclipse.emf.ecore.EClass, int, int, int)
	 *
	 * @param type
	 * @param eClass
	 * @param expectedGraphicalChildren
	 * @param expectedSemanticChildren
	 * @param addedGraphicalChildren
	 */
	@Override
	public void testDrop(IElementType type, EClass eClass, int expectedGraphicalChildren, int expectedSemanticChildren, int addedGraphicalChildren) {
		if(eClass.equals(UMLPackage.eINSTANCE.getDurationObservation())) {
			// DROP
			assertEquals(DROP + INITIALIZATION_TEST, expectedGraphicalChildren, getRootView().getChildren().size());
			DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
			ArrayList<Element> list = new ArrayList<Element>();
			for (Element element : getRootSemanticModel().getModel().getOwnedElements()) {
				if (element != null && element.eClass().equals(eClass)) {
					list.add(element);
				}
			}
			dropObjectsRequest.setObjects(list);
			dropObjectsRequest.setLocation(new Point(40, 40));
			Command command = getContainerEditPart().getCommand(dropObjectsRequest);
			assertNotNull(DROP + COMMAND_NULL, command);
			assertTrue(DROP + TEST_IF_THE_COMMAND_IS_CREATED, command != UnexecutableCommand.INSTANCE);
			assertTrue(DROP + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute());
			// execute the drop
			executeOnUIThread(command);
			Assert.assertEquals(DROP + TEST_THE_EXECUTION, expectedGraphicalChildren + addedGraphicalChildren, getRootView().getChildren().size());
			// undo the drop
			undoOnUIThread();
			Assert.assertEquals(DROP + TEST_THE_UNDO, expectedGraphicalChildren, getRootView().getChildren().size());
			// redo the drop
			redoOnUIThread();
			Assert.assertEquals(DROP + TEST_THE_REDO, expectedGraphicalChildren + addedGraphicalChildren, getRootView().getChildren().size());
		}
		else {
		super.testDrop(type, eClass, expectedGraphicalChildren, expectedSemanticChildren, addedGraphicalChildren);
		}
	}
	
	/**
	 * @see org.eclipse.papyrus.uml.diagram.tests.canonical.AbstractTestNode#createViewRequestShapeContainer()
	 *
	 * @return
	 */
	@Override
	protected CreateViewRequest createViewRequestShapeContainer() {
		return null;
	}

}

Back to the top