Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 88546ec4bbf0cf5fcc796d19809a5a806aca8023 (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
[comment encoding = UTF-8 /]
[**
 * module CopyPasteTests to generate junit test files.
 */]
[module CopyPasteTests('http://www.eclipse.org/uml2/3.0.0/UML')]

[**
 * generate all the files for the given test model.
 * @param aTestModel model containing the test definitions
 * @param testedModel sysml model on which tests are performed
 */]
[template public generateCopyPasteTests(aTestModel : Model, testedModel : Model )]
	[for (elementTypeRule : Package | getAllElementTypesRules(aTestModel))]
		[generateCopyPasteElementTypeTestFile(elementTypeRule, aTestModel)/]
		[for (sourceTargetRule : Class | getAllSourceTargetRules(elementTypeRule, aTestModel))]
			[generateCopyPasteTestFile(sourceTargetRule, aTestModel)/]
		[/for]
	[/for]
[/template]

[template public generateCopyPasteElementTypeTestFile (aPackage : Package, aTestModel : Model) ]
[file ('/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/'.concat(getFileName(aPackage)).concat('.java'), false, 'Cp1252')]
/*****************************************************************************
 * Copyright (c) 2011 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:
 *  Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
 * 
 * @Generated from [aPackage.name/] - [aTestModel.name/] 
 *
 *****************************************************************************/
package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.eclipse.papyrus.core.utils.FilteredCollectionView;
import org.eclipse.papyrus.core.utils.IFilter;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.UMLPackage;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;


/**
 * Test for Copy / Paste of a Part
 */
public abstract class [getFileName(aPackage)/] extends AbstractCopyPasteTest {

	/**
     * {@inheritDoc}
     * @generated
 	 */
	@Override
	protected void initializeTest(Map<Object, Object> additionalChecks, EObject targetContainer, EObject copiedEObject) {
		super.initializeTest(additionalChecks, targetContainer, copiedEObject);
	
		[generatePreCopyInitialization(aPackage)/]
	}

	/**
	 * {@inheritDoc}
	 * @generated	
	 */
	@Override
	protected void postCopyAdditionalChecks(Map<?, ?> originalModel, List<EObject> newValues, List<EObject> delta) throws Exception {
		super.postCopyAdditionalChecks(originalModel, newValues, delta);
		
		[generatePostCopyAdditionalChecks(aPackage)/]
	}

}


[/file]
[/template]


[template public generateCopyPasteTestFile(aClass : Class, aTestModel : Model)]
	[file ('/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/'.concat(getFileName(aClass)).concat('.java'), false, 'Cp1252')]
/*****************************************************************************
 * Copyright (c) 2011 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:
 *  Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
 * 
 * @Generated from [aClass.name/] - [aTestModel.name/] 
 *
 *****************************************************************************/
package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste;

import java.util.List;
import java.util.Map;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.UMLPackage;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;


/**
 * Test for Copy / Paste of a Part
 */
public class [getFileName(aClass)/] extends [getFileName(aClass.eContainer(Package))/]  {
	
	/**
	 * prepare the copy
	 * 
	 * @throws Exception
	 *         exception thrown in case of problems
	 */
	@Before
	public void testPrepare() throws Exception {
		// check editor state (should be non dirty)
		Assert.assertFalse("Editor should not be dirty at initialization", isEditorDirty());
		// retrieve elements in the model explorer
		selectAndReveal([generateElementName(getSource(aClass))/]);

		// copy Paste
		ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class);
		commandService.refreshElements(IWorkbenchCommandConstants.EDIT_COPY, null);
		org.eclipse.core.commands.Command copyCommand = commandService.getCommand(IWorkbenchCommandConstants.EDIT_COPY);
		Assert.assertNotNull("Impossible to find copy command", copyCommand);
		Assert.assertTrue("command in not enabled", copyCommand.isEnabled());
		Assert.assertTrue("command in not defined", copyCommand.isDefined());
		copyCommand.executeWithChecks(new ExecutionEvent());

		// check editor state (should be non dirty)
		// Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty());

		// NOTE: save editor. The copy command should not dirty the model, the implementation of the copy command or the editor should be modified
		Assert.assertTrue("Copy command is dirtying the model, whereas it should not. This assert is here to remember that the test code should be modified: Isdirty = false after copy...", isEditorDirty());
		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor());
		Assert.assertFalse("Save command is non-dirtying the model, whereas it should. ", isEditorDirty());
		// END NOTE
	}

	@Override
	protected void initializeTest(Map<Object, Object> additionalChecks, EObject targetContainer, EObject copiedEObject) {
		super.initializeTest(additionalChecks, targetContainer, copiedEObject);
	
		[generatePreCopyInitialization(aClass)/]
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void postCopyAdditionalChecks(Map<?, ?> originalModel, List<EObject> newValues, List<EObject> delta) throws Exception {
		super.postCopyAdditionalChecks(originalModel, newValues, delta);
		
		[generatePostCopyAdditionalChecks(aClass)/]
	}

	[generateAllTargets(aClass)/]

}


[/file]
[/template]

[template public generatePreCopyInitialization (aPackage : Package) ]
	/* pre-copy initialization */
	[getPreCopyInitialization(aPackage)/]
	/* END OF pre-copy initialization */
[/template]

[template public generatePreCopyInitialization (aClass : Class) ]
	/* pre-copy initialization */
	[getPreCopyInitialization(aClass)/]
	/* END OF pre-copy initialization */
[/template]

[template public generatePostCopyAdditionalChecks (aPackage : Package) ]
	/* post copy checks */
	[getPostCopyAdditionalChecks(aPackage)/]
	/* END OF post copy checks */
[/template]

[template public generatePostCopyAdditionalChecks (aClass : Class) ]
	/* post copy checks */
	[getPostCopyAdditionalChecks(aClass)/]
	/* END OF post copy checks */
[/template]

[template public generateAllTargets (aClass : Class) ]
[let source : Element = getSource(aClass)]
	
	[for (target : Element | getAllTargets(aClass))]
	/**
	 * Test the copy /paste on [getName(target)/]
	 * 
	 * @throws Exception
	 *         exception thrown in case of problems
	 */
	@Test
	public void testCopyPasteIn[getName(target)/]() throws Exception {
		testExecutableCopyPaste([generateElementName(target)/], [generateElementName(source)/], "[getCopyFeature(aClass)/]", [getExpectedNumberOfElements(aClass)/]);
	}
	[/for]
[/let]
[/template]

[query public getExpectedNumberOfElements (aClass : Class) : String = aClass.getValue(aClass.getAppliedStereotype('ModelExplorerTest::SourceTargetRulesCopyPasteTest'), 'additionalElementsQuantity')/]

[query public getCopyFeature(aClass : Class) : String = aClass.getValue(aClass.getAppliedStereotype('ModelExplorerTest::SourceTargetRulesCopyPasteTest'), 'feature')/]

[query public getSource(aClass : Class) : Element =  aClass.getValue(aClass.getAppliedStereotype('ModelExplorerTest::SourceTargetRulesCopyPasteTest'), 'sourceElement')/]

[** Returns the name of the test file for the given test class *]
[query public getFileName(aClass: Class) : String = 'CopyPaste'.concat(aClass.name).concat('Test')/]

[** Returns the name of the test file for the given test package (element type) *]
[query public getFileName(aPackage: Package) : String = 'AbstractCopyPaste'.concat(aPackage.name).concat('Test')/]

[** Returns all Rules for the given test model *]
[query public getAllElementTypesRules(aTestModel : Model) : Set(Package) = aTestModel.allOwnedElements()->select(e : Element | isStereotyped(e, 'ModelExplorerTest::ElementTypeRulesCopyPasteTest'))/]

[query public getAllSourceTargetRules(elementTypeRule : Package, aTestModel :Model ) : Set(Class) = elementTypeRule.ownedElement->select(e : Element | isStereotyped(e, 'ModelExplorerTest::SourceTargetRulesCopyPasteTest')) /]

[query public isStereotyped(element : Element, stereotypeQN : String) : Boolean = not element.getAppliedStereotype(stereotypeQN).oclIsUndefined()/] 

[query public getAllTargets(aClass : Class) : Set(Element) = aClass.getValue(aClass.getAppliedStereotype('ModelExplorerTest::SourceTargetRulesCopyPasteTest'), 'targets')/]

[query public getPostCopyAdditionalChecks(aPackage : Package) : String = aPackage.getValue(aPackage.getAppliedStereotype('ModelExplorerTest::ElementTypeRulesCopyPasteTest'), 'postCopyRule')/]
[query public getPostCopyAdditionalChecks(aClass : Class) : String = aClass.getValue(aClass.getAppliedStereotype('ModelExplorerTest::SourceTargetRulesCopyPasteTest'), 'postCopyRule')/]

[query public getPreCopyInitialization(aPackage : Package) : String = aPackage.getValue(aPackage.getAppliedStereotype('ModelExplorerTest::ElementTypeRulesCopyPasteTest'), 'preCopyInitialization')/]
[query public getPreCopyInitialization(aClass : Class) : String = aClass.getValue(aClass.getAppliedStereotype('ModelExplorerTest::SourceTargetRulesCopyPasteTest'), 'preCopyInitialization')/]

[**
 * Returns the java name for an element. ex: 'p1_pb2_EObject'
 */]
[template public generateElementName(aElement : Element) post(postTreatment())]
[getName(aElement)/]_[for (element : Element | getAllContainersExceptModel(aElement))][getName(element)/]_[/for]EObject
[/template]  

[template public postTreatment(txt: String)]
	[txt.toLowerFirst().trim()/]
[/template]

[query public getName(element : Element) : String = if(element.oclIsKindOf(NamedElement)) then element.oclAsType(NamedElement).name else element.eClass().name endif/]

[query public getNames(elements: Sequence(Element)) : Sequence(String) = elements->collect(getName())/]

[query public getAllContainersExceptModel(element : Element) : Sequence(Element) = element.ancestors(Element)->reject(e| e.eContainer().oclIsUndefined())/] 


Back to the top