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
|
/*****************************************************************************
* Copyright (c) 2014 CEA LIST and others.
*
*
* 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:
* Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.modelexplorer.tests.paste;
import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.nattable.model.nattable.Table;
import org.eclipse.papyrus.junit.utils.HandlerUtils;
import org.eclipse.papyrus.junit.utils.TableUtils;
import org.eclipse.papyrus.junit.utils.tests.AbstractEditorTest;
import org.eclipse.papyrus.uml.modelexplorer.tests.Activator;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.uml2.uml.Model;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
/**
* Sample test for copy of table in model explorer
*
* @author bmaggi
*/
public class TableCopyPasteModelExplorerTest extends AbstractEditorTest {
public static final String COPY_COMMAND_ID = "org.eclipse.ui.edit.copy"; //$NON-NLS-1$
public static final String PASTE_COMMAND_ID = "org.eclipse.ui.edit.paste"; //$NON-NLS-1$
public static final String RESOURCES_PATH = "resources/"; //$NON-NLS-1$
public static final String MODEL_NAME = "model"; //$NON-NLS-1$
public static final String PROJECT_NAME = "copyPasteTest"; //$NON-NLS-1$
public final static String VIEW_TABLE_NAME = "TableOfViews0"; //$NON-NLS-1$
public final static String CLASS1_NAME = "Class1"; //$NON-NLS-1$
@Before
public void initModelForCutTest() {
try {
initModel(PROJECT_NAME, MODEL_NAME, Activator.getDefault().getBundle()); //$NON-NLS-1$ //$NON-NLS-2$
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
@Override
protected String getSourcePath() {
return RESOURCES_PATH;
}
/**
* here the purpose is to test the creation of constraint on variable elements.
*/
@Test
public void copyPasteTableTest() throws Exception {
//get the rootModel
Assert.assertNotNull("RootModel is null", getRootUMLModel()); //$NON-NLS-1$
Collection<Table> allNotationTable = TableUtils.getAllNotationTable(getModelSet(), VIEW_TABLE_NAME);
Assert.assertNotNull("No Tables for copy", allNotationTable); //$NON-NLS-1$
Assert.assertEquals("Table to copy is missing", 1, allNotationTable.size()); //$NON-NLS-1$
//get all semantic elment that will handled
Model model = (Model)getRootUMLModel();
org.eclipse.uml2.uml.Class class1 = (org.eclipse.uml2.uml.Class)model.getPackagedElement(CLASS1_NAME);
Table notationFirstTable = TableUtils.getNotationFirstTable(getModelSet(), VIEW_TABLE_NAME);
Assert.assertEquals("Wrong Table selected", VIEW_TABLE_NAME, notationFirstTable.getName()); //$NON-NLS-1$
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
ISelectionService selectionService = activeWorkbenchWindow.getSelectionService();
modelExplorerView = getModelExplorerView();
modelExplorerView.setFocus();
ArrayList<Object> elements = new ArrayList<Object>();
elements.add(getRootUMLModel());
modelExplorerView.revealSemanticElement(elements);
//getItem for model
Object modelTreeObject = ((IStructuredSelection)selectionService.getSelection()).getFirstElement();
Assert.assertNotNull("Model TreeElement is null", modelTreeObject); //$NON-NLS-1$
// FIXME : this is required otherwise Table1TreeObject is empty (something wrong in the revealSemantic on Tables)
//get Item for class1
elements.clear();
elements.add(class1);
modelExplorerView.revealSemanticElement(elements);
Object class1TreeObject = ((IStructuredSelection)selectionService.getSelection()).getFirstElement();
Assert.assertNotNull("Class1 TreeElement is null", class1TreeObject); //$NON-NLS-1$
//get Item for Table1
elements.clear();
elements.add(notationFirstTable);
modelExplorerView.revealSemanticElement(elements);
Object tableTreeObject = ((IStructuredSelection)selectionService.getSelection()).getFirstElement();
Assert.assertNotNull("TableOfViews0 TreeElement is null", tableTreeObject); //$NON-NLS-1$
IHandler copyHandler = HandlerUtils.getActiveHandlerFor(COPY_COMMAND_ID);
Assert.assertTrue("Copy not available", copyHandler.isEnabled()); //$NON-NLS-1$
copyHandler.execute(new ExecutionEvent());
// select root
elements.clear();
elements.add(getRootUMLModel());
modelExplorerView.revealSemanticElement(elements);
// paste
IHandler pasteHandler = HandlerUtils.getActiveHandlerFor(PASTE_COMMAND_ID);
Assert.assertTrue("Paste not available", pasteHandler.isEnabled()); //$NON-NLS-1$
pasteHandler.execute(new ExecutionEvent());
allNotationTable = TableUtils.getAllNotationTable(getModelSet(), VIEW_TABLE_NAME);
Assert.assertEquals("Duplicate Table is missing", 2, allNotationTable.size());
}
}
|