Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7f2d76c61a3d7774a46cb07767613b3312682feb (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
/*****************************************************************************
 * 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
 * 
 *  from SimpleReference - Model 
 *
 *****************************************************************************/
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.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;


/**
 * Test for Copy / Paste of a Part
 */
public class CopyPasteSimpleReferenceTest extends AbstractCopyPasteReferenceTest {

	/**
	 * prepare the copy
	 * 
	 * @throws Exception
	 *         exception thrown in case of problems
	 */
	@Before
	public void testPrepare() throws Exception {
		// check editor state (should be non dirty)
		//FIXME: In Papyrus, the editor may be dirty at initialization. This should not be tested here. We simply save the editor as soon as it is opened.
		Display.getDefault().syncExec(new Runnable() {

			public void run() {
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor());
			}
		});

		Assert.assertFalse("Editor should not be dirty at initialization", isEditorDirty()); //$NON-NLS-1$
		// retrieve elements in the model explorer
		selectAndReveal(rB2_B1_EObject);

		// 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); //$NON-NLS-1$
		Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); //$NON-NLS-1$
		Assert.assertTrue("command in not defined", copyCommand.isDefined()); //$NON-NLS-1$
		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.assertFalse("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()); //$NON-NLS-1$
		Display.getDefault().syncExec(new Runnable() {

			public void run() {
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor());
			}
		});

		Assert.assertFalse("Save command is non-dirtying the model, whereas it should. ", isEditorDirty()); //$NON-NLS-1$
		// END NOTE
	}

	@Override
	protected void initializeTest(Map<Object, Object> additionalChecks, EObject targetContainer, EObject copiedEObject) {
		super.initializeTest(additionalChecks, targetContainer, copiedEObject);

		/* pre-copy initialization */

		/* END OF pre-copy initialization */
	}

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

		/* post copy checks */

		/* END OF post copy checks */
	}


	/**
	 * Test the copy /paste on B1
	 * 
	 * @throws Exception
	 *         exception thrown in case of problems
	 */
	@Test
	public void testCopyPasteInB1() throws Exception {
		testExecutableCopyPaste(b1_EObject, rB2_B1_EObject, "attribute", 1); 
	}

	/**
	 * Test the copy /paste on B2
	 * 
	 * @throws Exception
	 *         exception thrown in case of problems
	 */
	@Test
	public void testCopyPasteInB2() throws Exception {
		testExecutableCopyPaste(b2_EObject, rB2_B1_EObject, "attribute", 1);
	}

	/**
	 * Test the copy /paste on B1P1
	 * 
	 * @throws Exception
	 *         exception thrown in case of problems
	 */
	@Test
	public void testCopyPasteInB1P1() throws Exception {
		testExecutableCopyPaste(b1P1_P1_EObject, rB2_B1_EObject, "attribute", 1);
	}

	/**
	 * Test the copy /paste on B2P1
	 * 
	 * @throws Exception
	 *         exception thrown in case of problems
	 */
	@Test
	public void testCopyPasteInB2P1() throws Exception {
		testExecutableCopyPaste(b2P1_P1_EObject, rB2_B1_EObject, "attribute", 1);
	}


}

Back to the top