summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-05-07 07:41:09 (EDT)
committerBenoit Maggi2014-05-12 10:41:17 (EDT)
commit17e6654964559fbac412a8722c27bc4f0436648d (patch)
tree0801d4a1c5cf1ca8f73c401e2c78241b0895c80f
parent868d14101a6833b1dc7d5f4b078563c0d048a297 (diff)
downloadorg.eclipse.papyrus-17e6654964559fbac412a8722c27bc4f0436648d.zip
org.eclipse.papyrus-17e6654964559fbac412a8722c27bc4f0436648d.tar.gz
org.eclipse.papyrus-17e6654964559fbac412a8722c27bc4f0436648d.tar.bz2
Bug 290261 - [Usability] Papyrus shall provide a copy/paste/cut featurerefs/changes/22/26122/2
Add/updade tests for : - copy/paste in model explorer - cut/paste in model explorer - delete in model explorer Change-Id: Ic6d51b89cfcf118037a0710fae84348f1fdd57c6 Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
-rw-r--r--tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/AllTests.java5
-rw-r--r--tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/DeleteHandlerTest.java205
-rw-r--r--tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/DeleteModelExplorerTest.java176
-rw-r--r--tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteHandlerTest.java186
-rw-r--r--tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteModelExplorerTest.java172
-rw-r--r--tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CutPasteModelExplorerTest.java127
-rw-r--r--tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractDualHandlerTest.java194
7 files changed, 478 insertions, 587 deletions
diff --git a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/AllTests.java b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/AllTests.java
index 068c0dd..daa31b7 100644
--- a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/AllTests.java
+++ b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/AllTests.java
@@ -16,14 +16,15 @@
package org.eclipse.papyrus.uml.modelexplorer.tests;
-import org.eclipse.papyrus.uml.modelexplorer.tests.paste.CopyPasteHandlerTest;
+import org.eclipse.papyrus.uml.modelexplorer.tests.paste.CopyPasteModelExplorerTest;
+import org.eclipse.papyrus.uml.modelexplorer.tests.paste.CutPasteModelExplorerTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
- DeleteHandlerTest.class, RenameHandlerTest.class, ModelExplorerViewTests.class, CopyPasteHandlerTest.class
+ DeleteModelExplorerTest.class, RenameHandlerTest.class, ModelExplorerViewTests.class, CutPasteModelExplorerTest.class, CopyPasteModelExplorerTest.class
})
public class AllTests {
diff --git a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/DeleteHandlerTest.java b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/DeleteHandlerTest.java
deleted file mode 100644
index 477b5a4..0000000
--- a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/DeleteHandlerTest.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*****************************************************************************
- * 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:
- * Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.modelexplorer.tests;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView;
-import org.eclipse.papyrus.views.modelexplorer.tests.AbstractHandlerTest;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.uml2.uml.Model;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-
-
-/**
- *
- * @author VL222926
- *
- * This plugin tests the activation of the correct handler for differents selection in the ModelExplorer
- */
-public class DeleteHandlerTest extends AbstractHandlerTest {
-
- /**
- * the id of the delete command
- */
- private static final String DELETE_COMMAND_ID = "org.eclipse.ui.edit.delete";
-
- /**
- *
- * Constructor.
- *
- */
- public DeleteHandlerTest() {
- super(DELETE_COMMAND_ID, Activator.getDefault().getBundle());
- }
-
- /**
- * We test if we can delete the root of the Model or not
- */
- @Ignore("Currently fails on Hudson and freezes the Test Thread (EMF Facet dialog)")
- @Test
- public void deleteRootOfTheModel() {
- final List<EObject> selectedElement = new ArrayList<EObject>();
- selectedElement.add(getRootOfTheModel());
- getModelExplorerView().revealSemanticElement(selectedElement);
-
- RunnableWithResult<IWorkbenchPart> runnable;
-
- Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<IWorkbenchPart>() {
-
- public void run() {
- final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- final IWorkbenchPart activePart = activePage.getActivePart();
- setResult(activePart);
- }
- });
-
- IWorkbenchPart activePart = runnable.getResult();
-
- assertTrue("The active part is not the ModelExplorer", activePart instanceof ModelExplorerPageBookView); //$NON-NLS-1$
-
- final IStructuredSelection currentSelection = getCurrentSelection();
- Assert.assertEquals("Only one element should be selected", 1, currentSelection.size()); //$NON-NLS-1$
- Object obj = currentSelection.getFirstElement();
- if(obj instanceof IAdaptable) {
- obj = ((IAdaptable)obj).getAdapter(EObject.class);
- }
- assertEquals(getRootOfTheModel(), obj);
- final IHandler currentHandler = getActiveHandler();
- if(currentHandler == null) {
- // not a problem in this case
- } else {
- Assert.assertFalse("We can delete the root of the model. It is not the wanted behavior", currentHandler.isEnabled()); //$NON-NLS-1$
- }
- }
-
- /**
- * We test if we can delete other uml elements
- */
- @Ignore("Currently fails on Hudson and freezes the Test Thread (EMF Facet dialog)")
- @Test
- public void deleteUMLElementsTest() throws Exception {
- testIsModelExplorerActivePart();
-
- int size = ((Model)getRootOfTheModel()).getPackagedElements().size();
- EObject elementToDelete;
- while(((Model)getRootOfTheModel()).getPackagedElements().size() != 0) {
- //we need to clean the selection
-
- Display.getDefault().syncExec(new Runnable() {
-
- public void run() {
- getCommonViewer().setSelection(new StructuredSelection());
- }
- });
-
- IStructuredSelection currentSelection = getCurrentSelection();
- elementToDelete = ((Model)getRootOfTheModel()).getPackagedElements().get(0);
- List<EObject> selectedElement = new ArrayList<EObject>();
- selectedElement.add(elementToDelete);
- getModelExplorerView().revealSemanticElement(selectedElement);
- currentSelection = getCurrentSelection();
- assertEquals("Only one element should be selected", 1, currentSelection.size()); //$NON-NLS-1$
- Object obj = currentSelection.getFirstElement();
- if(obj instanceof IAdaptable) {
- obj = ((IAdaptable)obj).getAdapter(EObject.class);
- }
- Assert.assertEquals(elementToDelete, obj);
- IHandler currentHandler = getActiveHandler();
- Assert.assertTrue("We can't delete the following element" + elementToDelete, currentHandler.isEnabled()); //$NON-NLS-1$
-
- currentHandler.execute(new ExecutionEvent());
-
- int newSize = ((Model)getRootOfTheModel()).getPackagedElements().size();
- Assert.assertEquals(size - 1, newSize);
- //We test the undo
- Assert.assertTrue(getCommandStack().canUndo());
- getCommandStack().undo();
- newSize = ((Model)getRootOfTheModel()).getPackagedElements().size();
- Assert.assertEquals(size, newSize);
-
- //we test the redo
- Assert.assertTrue(getCommandStack().canRedo());
- getCommandStack().redo();
- newSize = ((Model)getRootOfTheModel()).getPackagedElements().size();
- Assert.assertEquals(size - 1, newSize);
- size = newSize;
- }
-
- int newSize = ((Model)getRootOfTheModel()).getPackagedElements().size();
- Assert.assertEquals(0, newSize);
- undoRedo(10);
- }
-
-
- @Test
- @Ignore("this tests doesn't work because the method revealSemanticElement is not able to reveal imported element")
- public void deleteReadOnlyElementsTest() {
- //TODO this tests doesn't work because the method revealSemanticElement is not able to reveal imported element
- // testIsModelExplorerActivePart();
- //
- // List<PackageImport> packageImports = ((Model)getRootOfTheModel()).getPackageImports();
- // EObject elementToDelete;
- // for(int i = 0; i < packageImports.size(); i++) {
- // //we clean the selection
- // getCommonViewer().setSelection(new StructuredSelection());
- // IStructuredSelection currentSelection = getCurrentSelection();
- // Assert.isTrue(currentSelection.isEmpty());
- //
- // List<EObject> selectedElement = new ArrayList<EObject>();
- // selectedElement.add(packageImports.get(i).getImportedPackage());
- // getModelExplorerView().revealSemanticElement(selectedElement);
- // currentSelection = getCurrentSelection();
- //// IContentProvider contentProvider = getModelExplorerView().getCommonViewer().getContentProvider();
- //// Object[] children = ((ITreeContentProvider)contentProvider).getChildren(currentSelection.getFirstElement());
- //// for(int iter = 0; iter < children.length; iter++) {
- //// Object tcurrent = children[0];
- //// int d = 0;
- //// d++;
- //// }
- //// selectedElement.clear();
- // elementToDelete = packageImports.get(i);
- //// selectedElement.add(elementToDelete);
- //
- // getModelExplorerView().revealSemanticElement(selectedElement);
- //
- //
- // currentSelection = getCurrentSelection();
- // Assert.isTrue(currentSelection.size() == 1, "Only one element should be selected");
- // Object obj = currentSelection.getFirstElement();
- // if(obj instanceof IAdaptable) {
- // obj = ((IAdaptable)obj).getAdapter(EObject.class);
- // }
- // Assert.isTrue(obj == elementToDelete);
- // IHandler currentHandler = getActiveHandler();
- // Assert.isTrue(currentHandler.isEnabled(), "We can't delete the following element" + elementToDelete);
- // }
- }
-}
diff --git a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/DeleteModelExplorerTest.java b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/DeleteModelExplorerTest.java
new file mode 100644
index 0000000..cd45006
--- /dev/null
+++ b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/DeleteModelExplorerTest.java
@@ -0,0 +1,176 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.modelexplorer.tests;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.junit.utils.HandlerUtils;
+import org.eclipse.papyrus.junit.utils.tests.AbstractEditorTest;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.Model;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.PackageableElement;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ *
+ * Sample tests for delete in model explorer
+ *
+ * @author bmaggi
+ *
+ */
+public class DeleteModelExplorerTest extends AbstractEditorTest {
+
+ public static final String DELETE_COMMAND_ID = "org.eclipse.ui.edit.delete"; //$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 = "DeleteEditorTest"; //$NON-NLS-1$
+
+ public final static String CLASS1_NAME = "Class1"; //$NON-NLS-1$
+
+ public final static String PRIMITIVE_BOOLEAN_NAME = "Boolean"; //$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) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected String getSourcePath() {
+ return RESOURCES_PATH;
+ }
+
+ /**
+ * A user can not delete the root of a model
+ */
+ @Test
+ public void deleteRootOfTheModel() throws Exception {
+
+ Assert.assertNotNull("RootModel is null", getRootUMLModel()); //$NON-NLS-1$
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ISelectionService selectionService = activeWorkbenchWindow.getSelectionService();
+
+ modelExplorerView = getModelExplorerView();
+ modelExplorerView.setFocus();
+ List<Object> elements = new ArrayList<Object>();
+ elements.add(getRootUMLModel());
+ modelExplorerView.revealSemanticElement(elements);
+
+ //getItem for model
+ EObject modelTreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement();
+ Assert.assertNotNull("Model TreeElement is null", modelTreeObject); //$NON-NLS-1$
+
+ IHandler deleteHandler = HandlerUtils.getActiveHandlerFor(DELETE_COMMAND_ID); //$NON-NLS-1$
+ Assert.assertFalse("Delete is available", deleteHandler.isEnabled()); //$NON-NLS-1$
+ }
+
+
+ /**
+ * A user can delete an uml class
+ */
+ @Test
+ public void deleteClassInTheModel() throws Exception {
+
+ Assert.assertNotNull("RootModel is null", getRootUMLModel()); //$NON-NLS-1$
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ISelectionService selectionService = activeWorkbenchWindow.getSelectionService();
+
+ modelExplorerView = getModelExplorerView();
+ modelExplorerView.setFocus();
+
+ List<Object> elements = new ArrayList<Object>();
+ elements.add(getRootUMLModel());
+ modelExplorerView.revealSemanticElement(elements);
+
+ //getItem for model
+ EObject modelTreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement();
+ Assert.assertNotNull("Model TreeElement is null", modelTreeObject); //$NON-NLS-1$
+
+ //get Item for class1
+ Model model = (Model)getRootUMLModel();
+ org.eclipse.uml2.uml.Class class1 = (org.eclipse.uml2.uml.Class)model.getPackagedElement(CLASS1_NAME);
+
+ elements.clear();
+ elements.add(class1);
+ modelExplorerView.revealSemanticElement(elements);
+ EObject class1TreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement();
+ Assert.assertNotNull("Class1 TreeElement is null", class1TreeObject); //$NON-NLS-1$
+
+ IHandler deleteHandler = HandlerUtils.getActiveHandlerFor(DELETE_COMMAND_ID); //$NON-NLS-1$
+ Assert.assertTrue("Delete is not available on a class", deleteHandler.isEnabled()); //$NON-NLS-1$
+ deleteHandler.execute(new ExecutionEvent());
+
+ org.eclipse.uml2.uml.Class deletedClass1 = (org.eclipse.uml2.uml.Class)getRootUMLModel().getPackagedElement(CLASS1_NAME);
+ Assert.assertNull("The class is still present", deletedClass1); //$NON-NLS-1$
+
+ }
+
+
+ /**
+ * A user can not delete a read only element
+ */
+ @Test
+ public void deleteReadOnlyElement() throws Exception {
+
+ Package rootUMLModel = getRootUMLModel();
+
+ Assert.assertNotNull("RootModel is null", rootUMLModel); //$NON-NLS-1$
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ISelectionService selectionService = activeWorkbenchWindow.getSelectionService();
+
+ modelExplorerView = getModelExplorerView();
+ modelExplorerView.setFocus();
+
+ List<Object> elements = new ArrayList<Object>();
+ elements.add(rootUMLModel);
+ modelExplorerView.revealSemanticElement(elements);
+
+ //getItem for model
+ EObject modelTreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement();
+ Assert.assertNotNull("Model TreeElement is null", modelTreeObject); //$NON-NLS-1$
+
+ //get read only item
+ EList<Package> importedPackages = rootUMLModel.getImportedPackages();
+ Package primitiveTypes = importedPackages.get(0);
+ PackageableElement packagedElement = primitiveTypes.getPackagedElement(PRIMITIVE_BOOLEAN_NAME);
+
+ elements.clear();
+ elements.add(packagedElement);
+ modelExplorerView.revealSemanticElement(elements);
+ EObject treeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement();
+ Assert.assertNotNull("Boolean Primitive TreeElement is null", treeObject); //$NON-NLS-1$
+
+ IHandler deleteHandler = HandlerUtils.getActiveHandlerFor(DELETE_COMMAND_ID);
+ Assert.assertFalse("Delete is available on a readonly element (Boolean Primitive)", deleteHandler.isEnabled()); //$NON-NLS-1$
+ }
+
+}
diff --git a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteHandlerTest.java b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteHandlerTest.java
deleted file mode 100644
index a1f231b..0000000
--- a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteHandlerTest.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2014 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:
- * 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.List;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.uml.modelexplorer.tests.Activator;
-import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
-import org.eclipse.papyrus.views.modelexplorer.tests.AbstractDualHandlerTest;
-import org.eclipse.uml2.uml.NamedElement;
-import org.junit.Assert;
-import org.junit.Test;
-
-
-
-/**
- * The Class CopyPasteHandlerTest. Test Copy/Paste inside ModelExplorer
- */
-public class CopyPasteHandlerTest extends AbstractDualHandlerTest {
-
- private static final String CLASS2 = "Class2";
- private static final String CLASS1 = "Class1";
-
- /**
- * Instantiates a new copy paste handler test.
- */
- public CopyPasteHandlerTest() {
- super("org.eclipse.ui.edit.copy", "org.eclipse.ui.edit.paste", Activator.getDefault().getBundle());
- }
-
- /**
- * Simple copy paste of a class1
- */
- @Test
- public void SimpleCopyPasteofClass1Test() {
- try {
- EObject rootOfTheModel = getRootOfTheModel();
- // check that there is Class1
- Assert.assertEquals("Class1 is missing", getCountElementByName(CLASS1), 1); //$NON-NLS-1$
- EObject class1 = getNameElementByName(CLASS1); // get Class1
-
- // select class1
- selectElementInTheModelexplorer(class1);
-
- // copy
- IHandler copyHandler = getActiveHandler();
- Assert.assertTrue(copyHandler.isEnabled());
- copyHandler.execute(new ExecutionEvent());
-
- // select root
- selectElementInTheModelexplorer(rootOfTheModel);
-
- // paste
- IHandler pasteHandler = getSecondActiveHandler();
- Assert.assertTrue(pasteHandler.isEnabled());
- pasteHandler.execute(new ExecutionEvent());
-
- // check that there is a Class1
- Assert.assertNotNull("Class1 copy is missing", getNameElementByName(NamedElementUtil.COPY_OF+"_"+CLASS1+"_1")); //$NON-NLS-1$
-
- } catch (ExecutionException e) {
- Assert.fail(e.toString());
- }
-
- }
-
-
- /**
- * Simple copy pasteof class1 & class2 test.
- */
- @Test
- public void SimpleCopyPasteofClass1And2Test() {
- try {
- EObject rootOfTheModel = getRootOfTheModel();
- // check that there is Class1 and Class2
- Assert.assertEquals("Class1 is missing", getCountElementByName(CLASS1), 1); //$NON-NLS-1$
- Assert.assertEquals("Class2 is missing", getCountElementByName(CLASS2), 1); //$NON-NLS-1$
-
- EObject class1 = getNameElementByName(CLASS1); // get Class1
- EObject class2 = getNameElementByName(CLASS2); // get Class2
-
- // select Class1 and Class2
- List<EObject> listToCopy = new ArrayList<EObject>();
- listToCopy.add(class1);
- listToCopy.add(class2);
- selectListElementInTheModelexplorer(listToCopy);
-
- // copy
- IHandler copyHandler = getActiveHandler();
- Assert.assertTrue(copyHandler.isEnabled());
- copyHandler.execute(new ExecutionEvent());
-
- // selec root
- selectElementInTheModelexplorer(rootOfTheModel);
-
- // paste
- IHandler pasteHandler = getSecondActiveHandler();
- Assert.assertTrue(pasteHandler.isEnabled());
- pasteHandler.execute(new ExecutionEvent());
- // check that there are Class1 and Class2
- Assert.assertNotNull("Class1 copy is missing", getNameElementByName(NamedElementUtil.COPY_OF+"_"+CLASS1+"_1")); //$NON-NLS-1$
- Assert.assertNotNull("Class2 copy is missing", getNameElementByName(NamedElementUtil.COPY_OF+"_"+CLASS2+"_1")); //$NON-NLS-1$
-
- } catch (ExecutionException e) {
- Assert.fail(e.toString());
- }
-
- }
-
- // TODO : all these methods should already exist in or move to some *Utils class
- /**
- * Gets the name element by name.
- *
- * @param name the name
- * @return the name element by name
- */
- public EObject getNameElementByName(String name){
- EObject rootOfTheModel = getRootOfTheModel();
- for(EObject child : rootOfTheModel.eContents()) {
- if (child instanceof NamedElement){
- NamedElement namedElement = (NamedElement) child;
- if (name.equals(namedElement.getName())) {
- return namedElement;
- }
- }
- }
- return null;
- }
-
- /**
- * Gets the count element by name.
- *
- * @param name the name
- * @return the count element by name
- */
- public int getCountElementByName(String name){
- EObject rootOfTheModel = getRootOfTheModel();
- int i = 0;
- for(EObject child : rootOfTheModel.eContents()) {
- if (child instanceof NamedElement){
- NamedElement namedElement = (NamedElement) child;
- if (name.equals(namedElement.getName())) {
- i++;
- }
- }
- }
- return i;
- }
-
- /**
- * Log tree.
- *
- * @param i the i
- * @param root the root
- */
- public void logTree(int i, EObject root){
- for(int j = 0; j < i; j++) {
- System.out.print("\t");
- }
- if (root instanceof NamedElement){
- System.out.println(((NamedElement)root).getName());
- } else {
- System.out.println(root);
- }
-
- for(EObject child : root.eContents()) {
- logTree(i+1, child);
- }
- }
-}
diff --git a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteModelExplorerTest.java b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteModelExplorerTest.java
new file mode 100644
index 0000000..81ba997
--- /dev/null
+++ b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteModelExplorerTest.java
@@ -0,0 +1,172 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * 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.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.junit.utils.HandlerUtils;
+import org.eclipse.papyrus.junit.utils.tests.AbstractEditorTest;
+import org.eclipse.papyrus.uml.modelexplorer.tests.Activator;
+import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
+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.Test;
+
+/**
+ * Sample test for cut in model explorer
+ *
+ * @author bmaggi
+ */
+public class CopyPasteModelExplorerTest 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 CLASS1_NAME = "Class1"; //$NON-NLS-1$
+
+ public final static String CLASS2_NAME = "Class2"; //$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) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected String getSourcePath() {
+ return RESOURCES_PATH;
+ }
+
+
+ /**
+ * Simple copy paste of a class1
+ *
+ * @throws Exception
+ */
+ @Test
+ public void copyPasteofClass1Test() throws Exception {
+ //get the rootModel
+ Assert.assertNotNull("RootModel is null", getRootUMLModel()); //$NON-NLS-1$
+ //get all semantic elment that will handled
+ Model model = (Model)getRootUMLModel();
+
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ISelectionService selectionService = activeWorkbenchWindow.getSelectionService();
+ modelExplorerView = getModelExplorerView();
+ modelExplorerView.setFocus();
+ List<Object> elements = new ArrayList<Object>();
+ elements.add(getRootUMLModel());
+ modelExplorerView.revealSemanticElement(elements);
+
+ org.eclipse.uml2.uml.Class class1 = (org.eclipse.uml2.uml.Class)model.getPackagedElement(CLASS1_NAME);
+ elements.clear();
+ elements.add(class1);
+ modelExplorerView.revealSemanticElement(elements);
+ EObject class1TreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement();
+ Assert.assertNotNull("Class1 TreeElement is null", class1TreeObject); //$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());
+
+ // check that there is a Class1
+ org.eclipse.uml2.uml.Class copyOfClass1 = (org.eclipse.uml2.uml.Class)model.getPackagedElement(NamedElementUtil.COPY_OF + "_" + CLASS1_NAME + "_1");
+ Assert.assertNotNull("The copy is missing", copyOfClass1); //$NON-NLS-1$
+ }
+
+
+ /**
+ * Simple copy pasteof class1 & class2 test.
+ */
+ @Test
+ public void copyPasteofClass1And2Test() throws Exception {
+
+ //get the rootModel
+ Assert.assertNotNull("RootModel is null", getRootUMLModel()); //$NON-NLS-1$
+ //get all semantic elment that will handled
+ Model model = (Model)getRootUMLModel();
+
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ISelectionService selectionService = activeWorkbenchWindow.getSelectionService();
+ modelExplorerView = getModelExplorerView();
+ modelExplorerView.setFocus();
+ List<Object> elements = new ArrayList<Object>();
+ elements.add(getRootUMLModel());
+ modelExplorerView.revealSemanticElement(elements);
+
+ org.eclipse.uml2.uml.Class class1 = (org.eclipse.uml2.uml.Class)model.getPackagedElement(CLASS1_NAME);
+ org.eclipse.uml2.uml.Class class2 = (org.eclipse.uml2.uml.Class)model.getPackagedElement(CLASS2_NAME);
+ elements.clear();
+ elements.add(class1);
+ elements.add(class2);
+ modelExplorerView.revealSemanticElement(elements);
+ EObject class1TreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement();
+ Assert.assertNotNull("Class1 TreeElement is null", class1TreeObject); //$NON-NLS-1$
+
+ EObject class2TreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement();
+ Assert.assertNotNull("Class2 TreeElement is null", class2TreeObject); //$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());
+
+ // check that there is a Class1
+ org.eclipse.uml2.uml.Class copyOfClass1 = (org.eclipse.uml2.uml.Class)model.getPackagedElement(NamedElementUtil.COPY_OF + "_" + CLASS1_NAME + "_1");
+ Assert.assertNotNull("The class1 copy is missing", copyOfClass1); //$NON-NLS-1$
+
+ org.eclipse.uml2.uml.Class copyOfClass2 = (org.eclipse.uml2.uml.Class)model.getPackagedElement(NamedElementUtil.COPY_OF + "_" + CLASS2_NAME + "_1");
+ Assert.assertNotNull("The class2 copy is missing", copyOfClass2); //$NON-NLS-1$
+ }
+
+}
diff --git a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CutPasteModelExplorerTest.java b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CutPasteModelExplorerTest.java
new file mode 100644
index 0000000..7bda261
--- /dev/null
+++ b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CutPasteModelExplorerTest.java
@@ -0,0 +1,127 @@
+/*****************************************************************************
+ * Copyright (c) 2014 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:
+ * 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 org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.junit.utils.HandlerUtils;
+import org.eclipse.papyrus.junit.utils.tests.AbstractEditorTest;
+import org.eclipse.papyrus.uml.modelexplorer.tests.Activator;
+import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
+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.Test;
+
+/**
+ * Sample test for cut in model explorer
+ *
+ * @author bmaggi
+ */
+public class CutPasteModelExplorerTest extends AbstractEditorTest {
+
+ public static final String PASTE_COMMAND_ID = "org.eclipse.ui.edit.paste"; //$NON-NLS-1$
+
+ public static final String CUT_COMMAND_ID = "org.eclipse.ui.edit.cut"; //$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 = "cutPasteTest"; //$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) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected String getSourcePath() {
+ return RESOURCES_PATH;
+ }
+
+
+ /**
+ * here the purpose is to test the cut/paste of a class in modelexplorer.
+ */
+ @Test
+ public void cutClassTest() throws Exception {
+
+ //get the rootModel
+ Assert.assertNotNull("RootModel is null", getRootUMLModel()); //$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);
+
+ 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
+ EObject modelTreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement();
+ Assert.assertNotNull("Model TreeElement is null", modelTreeObject); //$NON-NLS-1$
+
+ //get Item for class1
+ elements.clear();
+ elements.add(class1);
+ modelExplorerView.revealSemanticElement(elements);
+ EObject class1TreeObject = (EObject)((IStructuredSelection)selectionService.getSelection()).getFirstElement();
+ Assert.assertNotNull("Class1 TreeElement is null", class1TreeObject); //$NON-NLS-1$
+
+
+ IHandler cutHandler = HandlerUtils.getActiveHandlerFor(CUT_COMMAND_ID);
+ Assert.assertTrue("Copy not available", cutHandler.isEnabled()); //$NON-NLS-1$
+ cutHandler.execute(new ExecutionEvent());
+
+ org.eclipse.uml2.uml.Class cutClass1 = (org.eclipse.uml2.uml.Class)model.getPackagedElement(CLASS1_NAME);
+ Assert.assertNull("The cut class is still present", cutClass1); //$NON-NLS-1$
+
+ elements.clear();
+ elements.add(getRootUMLModel());
+ modelExplorerView.revealSemanticElement(elements);
+
+ IHandler pasteHandler = HandlerUtils.getActiveHandlerFor(PASTE_COMMAND_ID);
+ Assert.assertTrue("Paste not available", pasteHandler.isEnabled()); //$NON-NLS-1$
+ pasteHandler.execute(new ExecutionEvent());
+
+ org.eclipse.uml2.uml.Class firstCopyOfClass1 = (org.eclipse.uml2.uml.Class)model.getPackagedElement(CLASS1_NAME);
+ Assert.assertNotNull("The first copy is missing", firstCopyOfClass1); //$NON-NLS-1$
+
+ pasteHandler.execute(new ExecutionEvent());
+
+ org.eclipse.uml2.uml.Class secondCopyOfClass1 = (org.eclipse.uml2.uml.Class)model.getPackagedElement(NamedElementUtil.COPY_OF + "_" + CLASS1_NAME + "_1");
+ Assert.assertNotNull("The copy second is missing", secondCopyOfClass1); //$NON-NLS-1$
+ }
+
+}
diff --git a/tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractDualHandlerTest.java b/tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractDualHandlerTest.java
deleted file mode 100644
index 023d3dc..0000000
--- a/tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractDualHandlerTest.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2014 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:
- * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.views.modelexplorer.tests;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.commands.IHandler;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.emf.facet.util.core.internal.exported.FileUtils;
-import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPage;
-import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView;
-import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.commands.ICommandService;
-import org.eclipse.ui.internal.handlers.HandlerProxy;
-import org.eclipse.ui.part.IPage;
-import org.junit.Assert;
-import org.junit.Before;
-import org.osgi.framework.Bundle;
-
-/**
- * Just duplicate the mecanism to handle scenario with 2 handlers
- */
-public abstract class AbstractDualHandlerTest extends AbstractHandlerTest{
-
-
- /** The second tested command. */
- protected Command secondTestedCommand;
-
- /** The second command id. */
- protected final String secondCommandId;
-
- /**
- * Instantiates a new abstract dual handler test.
- *
- * @param commandId the command id
- * @param secondCommandId the second command id
- * @param bundle the bundle
- */
- public AbstractDualHandlerTest(String commandId, String secondCommandId, Bundle bundle) {
- super(commandId, bundle);
- this.secondCommandId = secondCommandId;
- }
-
-
- /**
- * Gets the second active handler.
- *
- * @return the second active handler
- */
- protected IHandler getSecondActiveHandler() {
- IHandler currentHandler = secondTestedCommand.getHandler();
- if(currentHandler instanceof HandlerProxy) {
- currentHandler = ((HandlerProxy)currentHandler).getHandler();
- }
- return currentHandler;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.papyrus.views.modelexplorer.tests.AbstractHandlerTest#initTests()
- */
- @Before
- @Override
- public void initTests() throws CoreException, IOException {
- // we clean the workspace and create a new project to test the handlers
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- for(IProject project : workspace.getRoot().getProjects()) {
- project.delete(true, new NullProgressMonitor());
- }
- IProject testProject = workspace.getRoot().getProject(AbstractHandlerTest.PROJECT_NAME);
- testProject.create(new NullProgressMonitor());
- testProject.open(new NullProgressMonitor());
-
- // we copy the file of the tested model in the new project
- FileUtils.copyFileFromBundle("/resources/" + AbstractHandlerTest.FILE_NAME + AbstractHandlerTest.EXTENSION_UML, //$NON-NLS-1$
- testProject, '/' + AbstractHandlerTest.FILE_NAME + AbstractHandlerTest.EXTENSION_UML, bundle);
- FileUtils.copyFileFromBundle("/resources/" + AbstractHandlerTest.FILE_NAME + AbstractHandlerTest.EXTENSION_NOTATION, //$NON-NLS-1$
- testProject, '/' + AbstractHandlerTest.FILE_NAME + AbstractHandlerTest.EXTENSION_NOTATION, bundle);
- FileUtils.copyFileFromBundle("/resources/" + AbstractHandlerTest.FILE_NAME + AbstractHandlerTest.EXTENSION_DI, //$NON-NLS-1$
- testProject, '/' + AbstractHandlerTest.FILE_NAME + AbstractHandlerTest.EXTENSION_DI, bundle);
- IFile file = testProject.getFile(AbstractHandlerTest.FILE_NAME + AbstractHandlerTest.EXTENSION_DI);
-
- // we open the editor
- editor = (CoreMultiDiagramEditor)openEditor(file);
-
- RunnableWithResult runnable;
-
- Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl() {
-
- public void run() {
- IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
-
- // we look for the modelexplorer
- IViewPart modelexplorer;
- try {
- modelexplorer = activeWorkbenchWindow.getActivePage().showView(AbstractHandlerTest.viewId);
- } catch (PartInitException ex) {
- ex.printStackTrace(System.out);
- setStatus(new Status(IStatus.ERROR, bundle.getSymbolicName(), ex.getMessage()));
- return;
- }
- ModelExplorerPageBookView view = (ModelExplorerPageBookView)modelexplorer;
- IPage currentPage = view.getCurrentPage();
- ModelExplorerPage page = (ModelExplorerPage)currentPage;
- IViewPart viewer = page.getViewer();
- modelExplorerView = (ModelExplorerView)viewer;
- modelExplorerView.setFocus();
-
- // we look for the common viewer
- commonViewer = modelExplorerView.getCommonViewer();
-
- // we look for the selection service
- selectionService = activeWorkbenchWindow.getSelectionService();
-
- // we look for the testedCommand
- ICommandService commandService = (ICommandService)activeWorkbenchWindow.getService(ICommandService.class);
- if(commandId != null) {
- testedCommand = commandService.getCommand(commandId);
- }
- if(commandId != null) {
- secondTestedCommand = commandService.getCommand(secondCommandId);
- }
-
- commonViewer.expandToLevel(2);
-
- // store the root of the model
- Object[] visibleElement = commonViewer.getVisibleExpandedElements();
- modelRoot = EMFHelper.getEObject(visibleElement[0]);
-
- setStatus(Status.OK_STATUS);
- }
- });
-
- Assert.assertEquals(runnable.getStatus().getMessage(), IStatus.OK, runnable.getStatus().getSeverity());
-
- while(modelRoot.eContainer() != null) {
- modelRoot = modelRoot.eContainer();
- }
- }
-
- /**
- * This method selects many elements in the modelexplorer and test that the new
- * selection is the wanted selection using assertion
- *
- * @param elementToSelect
- * the list element to select
- */
- protected void selectListElementInTheModelexplorer(List<EObject> listElementToSelect) {
- final List<EObject> selectedElement = new ArrayList<EObject>();
- selectedElement.addAll(listElementToSelect);
- Display.getDefault().syncExec(new Runnable() {
-
- public void run() {
- modelExplorerView.revealSemanticElement(selectedElement);
- }
- });
-
- IStructuredSelection currentSelection = (IStructuredSelection)selectionService.getSelection();
- Assert.assertEquals("Only one element should be selected", listElementToSelect.size(), currentSelection.size()); //$NON-NLS-1$
- }
-
-
-
-}