summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-03-07 10:26:16 (EST)
committerVincent Lorenzo2014-03-18 10:03:26 (EDT)
commita07b4966c682adacb414d522fd07f77c1d9c4a5b (patch)
tree63188bb28b446caecc7fad707f4eac8cd241175c
parent0ea08311b1863fd8528b0226f5b0ee0f2b49ce3e (diff)
downloadorg.eclipse.papyrus-a07b4966c682adacb414d522fd07f77c1d9c4a5b.zip
org.eclipse.papyrus-a07b4966c682adacb414d522fd07f77c1d9c4a5b.tar.gz
org.eclipse.papyrus-a07b4966c682adacb414d522fd07f77c1d9c4a5b.tar.bz2
#290261: Add a Simple TestCase for copy/paste inside a modelExplorer
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr> Conflicts: tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/META-INF/MANIFEST.MF tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractHandlerTest.java
-rw-r--r--tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/META-INF/MANIFEST.MF3
-rw-r--r--tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteHandlerTest.java185
-rw-r--r--tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractDualHandlerTest.java196
-rw-r--r--tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractHandlerTest.java16
4 files changed, 391 insertions, 9 deletions
diff --git a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/META-INF/MANIFEST.MF
index 22572a2..132506c 100644
--- a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/META-INF/MANIFEST.MF
@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.views.modelexplorer;bundle-version="1.0.0",
org.eclipse.emf.transaction;bundle-version="1.4.0",
org.junit;bundle-version="4.10.0",
- org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0"
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.core
Export-Package: org.eclipse.papyrus.uml.modelexplorer.tests
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
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
new file mode 100644
index 0000000..7d75106
--- /dev/null
+++ b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/paste/CopyPasteHandlerTest.java
@@ -0,0 +1,185 @@
+/*****************************************************************************
+ * 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.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);
+ 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 2 Class1
+ Assert.assertEquals("Class1 copy is missing", getCountElementByName(CLASS1), 2);
+
+ } 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);
+ Assert.assertEquals("Class2 is missing", getCountElementByName(CLASS2), 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 is 2 Class1 and 2 Class2
+ Assert.assertEquals("Class1 copy is missing", getCountElementByName(CLASS1), 2);
+ Assert.assertEquals("Class2 copy is missing", getCountElementByName(CLASS2), 2);
+
+ } 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/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
new file mode 100644
index 0000000..4e25dae
--- /dev/null
+++ b/tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractDualHandlerTest.java
@@ -0,0 +1,196 @@
+/*****************************************************************************
+ * 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.IAdaptable;
+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.facet.util.core.internal.exported.FileUtils;
+import org.eclipse.emf.transaction.RunnableWithResult;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
+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();
+ if(visibleElement[0] instanceof IAdaptable) {
+ modelRoot = (EObject)((IAdaptable)visibleElement[0]).getAdapter(EObject.class);
+ }
+
+ 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$
+ }
+
+
+
+}
diff --git a/tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractHandlerTest.java b/tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractHandlerTest.java
index 481420d..8c8c950 100644
--- a/tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractHandlerTest.java
+++ b/tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractHandlerTest.java
@@ -78,30 +78,30 @@ public abstract class AbstractHandlerTest {
protected static final String FILE_NAME = "model"; //$NON-NLS-1$
/** the name of the project used to test the handler */
- private static final String PROJECT_NAME = "Project Handler Test"; //$NON-NLS-1$
+ protected static final String PROJECT_NAME = "Project Handler Test"; //$NON-NLS-1$
/** the id of the model explorer */
public static final String viewId = "org.eclipse.papyrus.views.modelexplorer.modelexplorer"; //$NON-NLS-1$
/** the root of the model */
- private EObject modelRoot;
+ protected EObject modelRoot;
- private ModelExplorerView modelExplorerView;
+ protected ModelExplorerView modelExplorerView;
protected Command testedCommand;
- private CommonViewer commonViewer;
+ protected CommonViewer commonViewer;
- private ISelectionService selectionService;
+ protected ISelectionService selectionService;
- private final String commandId;
+ protected final String commandId;
- private CoreMultiDiagramEditor editor;
+ protected CoreMultiDiagramEditor editor;
/**
* the bundle to use to get the model to test
*/
- private final Bundle bundle;
+ protected final Bundle bundle;
/**
*