-
Notifications
You must be signed in to change notification settings - Fork 91
/
CutPasteUndoModelElement.java
84 lines (75 loc) · 3.79 KB
/
CutPasteUndoModelElement.java
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
/*******************************************************************************
* Copyright (c) 2023 THALES GLOBAL SERVICES.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Thales - initial API and implementation
*******************************************************************************/
package org.polarsys.capella.test.model.ju.testcase.copyPasteModel;
import java.util.Collections;
import org.eclipse.emf.edit.command.CommandParameter;
import org.eclipse.emf.edit.ui.EMFEditUIPlugin;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.ui.PlatformUI;
import org.polarsys.capella.core.data.oa.OperationalActivity;
import org.polarsys.capella.core.platform.sirius.ui.commands.CapellaCutCommand;
import org.polarsys.capella.core.platform.sirius.ui.commands.CapellaPasteCommand;
import org.polarsys.capella.core.platform.sirius.ui.navigator.view.CapellaCommonNavigator;
import org.polarsys.capella.test.framework.context.SessionContext;
import org.polarsys.capella.test.model.ju.model.MiscModel;
/**
* Test undo after cut and paste on capella model.
*
* @author lfasani
*/
public class CutPasteUndoModelElement extends MiscModel {
@Override
public void test() throws Exception {
//
// Test data creation.
//
Session session = getSessionForTestModel(getRequiredTestModels().get(0));
SessionContext context = new SessionContext(session);
OperationalActivity rootOA = context.getSemanticElement(OA__OPERATIONAL_ACTIVITIES__ROOT_OA);
OperationalActivity operationalActivity1 = rootOA.getChildrenOperationalActivities().get(0);
OperationalActivity operationalActivity2 = rootOA.getChildrenOperationalActivities().get(1);
TransactionalEditingDomain ted = session.getTransactionalEditingDomain();
assertEquals("bad number of expected elements in root OperationalActivity", 3,
rootOA.getChildrenOperationalActivities().size());
// ------------------
// Cut paste and undo
// Cut
CapellaCommonNavigator capellaProjectView = (CapellaCommonNavigator) PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage().showView(CapellaCommonNavigator.ID);
CapellaCutCommand capellaCutCommand = new CapellaCutCommand(
EMFEditUIPlugin.INSTANCE.getString("_UI_Cut_menu_item"),
Collections.singleton(operationalActivity1), capellaProjectView.getCommonViewer());
ted.getCommandStack().execute(capellaCutCommand);
// Paste
CapellaPasteCommand capellaPasteCommand = new CapellaPasteCommand(ted, operationalActivity2, null,
CommandParameter.NO_INDEX);
ted.getCommandStack().execute(capellaPasteCommand);
// Checks
assertTrue("operationalActivity1 is expected to in operationalActivity2",
operationalActivity1.eContainer().equals(operationalActivity2));
assertEquals("bad number of expected elements in operationalActivity2", 1,
operationalActivity2.getChildrenOperationalActivities().size());
assertEquals("bad number of expected elements in root OperationalActivity", 2,
rootOA.getChildrenOperationalActivities().size());
// ----------------
// Undo and check
ted.getCommandStack().undo();
assertTrue("operationalActivity1 is expected to in rootOA",
operationalActivity1.eContainer().equals(rootOA));
assertEquals("bad number of expected elements in operationalActivity2", 0,
operationalActivity2.getChildrenOperationalActivities().size());
assertEquals("bad number of expected elements in root OperationalActivity", 3,
rootOA.getChildrenOperationalActivities().size());
}
}