From 95db010923165701ebc5b4f36ac663370b056a87 Mon Sep 17 00:00:00 2001 From: Benoit Maggi Date: Tue, 25 Mar 2014 11:08:50 +0100 Subject: Patch some modelexplorer tests Signed-off-by: Benoit Maggi --- .../META-INF/MANIFEST.MF | 3 +- .../tests/ModelExplorerViewTests.java | 450 ++++++++++----------- .../tests/AbstractDualHandlerTest.java | 6 +- .../modelexplorer/tests/AbstractHandlerTest.java | 7 +- 4 files changed, 228 insertions(+), 238 deletions(-) (limited to 'tests/junit') 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 bf1d3e4ac23..d43fda6fbed 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 @@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.ui, org.junit;bundle-version="4.10.0", org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0", org.eclipse.papyrus.infra.core, - org.eclipse.papyrus.emf.facet.custom.metamodel + org.eclipse.papyrus.emf.facet.custom.metamodel, + org.eclipse.papyrus.infra.emf 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/ModelExplorerViewTests.java b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/ModelExplorerViewTests.java index 60e5533aa5d..5bc0218f5c5 100644 --- a/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/ModelExplorerViewTests.java +++ b/tests/junit/plugins/uml/modelexplorer/org.eclipse.papyrus.uml.modelexplorer.tests/src/org/eclipse/papyrus/uml/modelexplorer/tests/ModelExplorerViewTests.java @@ -1,228 +1,222 @@ -/***************************************************************************** - * 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 java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.jface.viewers.IStructuredSelection; -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.NamedElement; -import org.eclipse.uml2.uml.Package; -import org.junit.Assert; -import org.junit.Test; - - -public class ModelExplorerViewTests extends AbstractHandlerTest { - - /** - * - * Constructor. - * This plugin test the ModelExplorerView - */ - public ModelExplorerViewTests() { - super(Activator.getDefault().getBundle()); - } - - /** - * tests the method reveal semantic element on the root element - */ - @Test - public void revealSemanticElement_selectRootTest() { - final List selectedElement = new ArrayList(); - selectedElement.add(getRootOfTheModel()); - getModelExplorerView().revealSemanticElement(selectedElement); - RunnableWithResult activePartRunnable; - Display.getDefault().syncExec(activePartRunnable = new RunnableWithResult.Impl() { - - public void run() { - IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IWorkbenchPart activePart = activePage.getActivePart(); - setResult(activePart); - } - }); - - Assert.assertTrue("The active part is not the ModelExplorer", activePartRunnable.getResult() 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); - } - - Assert.assertEquals("The function revealSemanticElement seems doesn't work on the root of the model", getRootOfTheModel(), obj); - } - - - /** - * tests the method reveal semantic element selects the correct element - */ - @Test - public void revealSemanticElement_selectChildrenTest() { - final List selectedElement = new ArrayList(); - final Package pack = (Package)getRootOfTheModel(); - final List members = pack.getOwnedMembers(); - final int size = members.size(); - Assert.assertTrue(size != 0);//to be sure that the tested model is correct - for(NamedElement current : members) { - selectedElement.clear(); - selectedElement.add(current); - - RunnableWithResult runnable; - Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl() { - - public void run() { - getModelExplorerView().revealSemanticElement(selectedElement); - final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - final IWorkbenchPart activePart = activePage.getActivePart(); - - setResult(activePart); - } - }); - - IWorkbenchPart activePart = runnable.getResult(); - - Assert.assertTrue("The active part is not the ModelExplorer", activePart instanceof ModelExplorerPageBookView); //$NON-NLS-1$ - final IStructuredSelection currentSelection = getCurrentSelection(); - Assert.assertTrue("Only one element should be selected", currentSelection.size() == 1); //$NON-NLS-1$ - Object obj = currentSelection.getFirstElement(); - if(obj instanceof IAdaptable) { - obj = ((IAdaptable)obj).getAdapter(EObject.class); - } - Assert.assertTrue("The function revealSemanticElement seems doesn't work with children", obj == current); - } - } - - /** - * tests the method reveal semantic element on the root element - */ - @Test - public void revealSemanticElement_selectChildrenTestList() { - final List selectedElement = new ArrayList(); - final Package pack = (Package)getRootOfTheModel(); - final List members = pack.getOwnedMembers(); - final int size = members.size(); - Assert.assertTrue(size != 0);//to be sure that the tested model is correct - selectedElement.addAll(members); - - RunnableWithResult runnable; - Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl() { - - public void run() { - getModelExplorerView().revealSemanticElement(selectedElement); - final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - final IWorkbenchPart activePart = activePage.getActivePart(); - - setResult(activePart); - } - }); - - IWorkbenchPart activePart = runnable.getResult(); - - - Assert.assertTrue("The active part is not the ModelExplorer", activePart instanceof ModelExplorerPageBookView); //$NON-NLS-1$ - final IStructuredSelection currentSelection = getCurrentSelection(); - Assert.assertTrue("Multi selction doesn't work with the method revealSemanticElement", currentSelection.size() == size); //$NON-NLS-1$ - } - - /** - * tests the method reveal semantic element on the root element - */ - @Test - public void revealSemanticElement_selectImportedPackage() { - final List selectedElement = new ArrayList(); - final Package pack = (Package)getRootOfTheModel(); - final EList importedPackage = pack.getImportedPackages(); - final int size = importedPackage.size(); - Assert.assertTrue(size != 0);//to be sure that the tested model is correct - for(NamedElement current : importedPackage) { - - waitForPendingMessages(); - - selectedElement.clear(); - selectedElement.add(current); - getModelExplorerView().revealSemanticElement(selectedElement); - RunnableWithResult activePartRunnable; - Display.getDefault().syncExec(activePartRunnable = new RunnableWithResult.Impl() { - - public void run() { - IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IWorkbenchPart activePart = activePage.getActivePart(); - setResult(activePart); - } - }); - - Assert.assertTrue("The active part is not the ModelExplorer", activePartRunnable.getResult() instanceof ModelExplorerPageBookView); //$NON-NLS-1$ - final IStructuredSelection currentSelection = getCurrentSelection(); - Assert.assertEquals("I don't get the correct selection", 1, currentSelection.size()); //$NON-NLS-1$ - Object obj = currentSelection.getFirstElement(); - if(obj instanceof IAdaptable) { - obj = ((IAdaptable)obj).getAdapter(EObject.class); - } - Assert.assertEquals("The function revealSemanticElement seems doesn't work with importedPackage", current, obj); - } - } - - private void waitForPendingMessages() { - //Run all pending tasks to refresh the ModelExplorer - if(Display.getCurrent() != null) { - while(true) { - try { - if(!Display.getCurrent().readAndDispatch()) { - break; - } - } catch (Throwable t) { - Activator.log.error(t); - } - } - } - } - - @Test - public void revealSemanticElement_selectImportedPackageList() { - final List selectedElement = new ArrayList(); - final Package pack = (Package)getRootOfTheModel(); - final EList importedPackage = pack.getImportedPackages(); - final int size = importedPackage.size(); - Assert.assertNotSame(0, size);//to be sure that the tested model is correct - - //Run all pending tasks to refresh the ModelExplorer - waitForPendingMessages(); - - selectedElement.addAll(importedPackage); - getModelExplorerView().revealSemanticElement(selectedElement); - RunnableWithResult activePartRunnable; - Display.getDefault().syncExec(activePartRunnable = new RunnableWithResult.Impl() { - - public void run() { - IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IWorkbenchPart activePart = activePage.getActivePart(); - setResult(activePart); - } - }); - - Assert.assertTrue("The active part is not the ModelExplorer", activePartRunnable.getResult() instanceof ModelExplorerPageBookView); //$NON-NLS-1$ - final IStructuredSelection currentSelection = getCurrentSelection(); - Assert.assertEquals("I don't get the current selection for revealSemanticElement_importedPackageList", 1, currentSelection.size()); //$NON-NLS-1$ - } -} +/***************************************************************************** + * 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 java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +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.NamedElement; +import org.eclipse.uml2.uml.Package; +import org.junit.Assert; +import org.junit.Test; + + +public class ModelExplorerViewTests extends AbstractHandlerTest { + + /** + * + * Constructor. + * This plugin test the ModelExplorerView + */ + public ModelExplorerViewTests() { + super(Activator.getDefault().getBundle()); + } + + /** + * tests the method reveal semantic element on the root element + */ + @Test + public void revealSemanticElement_selectRootTest() { + final List selectedElement = new ArrayList(); + selectedElement.add(getRootOfTheModel()); + getModelExplorerView().revealSemanticElement(selectedElement); + RunnableWithResult activePartRunnable; + Display.getDefault().syncExec(activePartRunnable = new RunnableWithResult.Impl() { + + public void run() { + IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + IWorkbenchPart activePart = activePage.getActivePart(); + setResult(activePart); + } + }); + + Assert.assertTrue("The active part is not the ModelExplorer", activePartRunnable.getResult() 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(); + obj = EMFHelper.getEObject(obj); + + Assert.assertEquals("The function revealSemanticElement seems doesn't work on the root of the model", getRootOfTheModel(), obj); + } + + + /** + * tests the method reveal semantic element selects the correct element + */ + @Test + public void revealSemanticElement_selectChildrenTest() { + final List selectedElement = new ArrayList(); + final Package pack = (Package)getRootOfTheModel(); + final List members = pack.getOwnedMembers(); + final int size = members.size(); + Assert.assertTrue(size != 0);//to be sure that the tested model is correct + for(NamedElement current : members) { + selectedElement.clear(); + selectedElement.add(current); + + RunnableWithResult runnable; + Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl() { + + public void run() { + getModelExplorerView().revealSemanticElement(selectedElement); + final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + final IWorkbenchPart activePart = activePage.getActivePart(); + + setResult(activePart); + } + }); + + IWorkbenchPart activePart = runnable.getResult(); + + Assert.assertTrue("The active part is not the ModelExplorer", activePart instanceof ModelExplorerPageBookView); //$NON-NLS-1$ + final IStructuredSelection currentSelection = getCurrentSelection(); + Assert.assertTrue("Only one element should be selected", currentSelection.size() == 1); //$NON-NLS-1$ + Object obj = currentSelection.getFirstElement(); + obj = EMFHelper.getEObject(obj); + Assert.assertTrue("The function revealSemanticElement seems doesn't work with children", obj == current); + } + } + + /** + * tests the method reveal semantic element on the root element + */ + @Test + public void revealSemanticElement_selectChildrenTestList() { + final List selectedElement = new ArrayList(); + final Package pack = (Package)getRootOfTheModel(); + final List members = pack.getOwnedMembers(); + final int size = members.size(); + Assert.assertTrue(size != 0);//to be sure that the tested model is correct + selectedElement.addAll(members); + + RunnableWithResult runnable; + Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl() { + + public void run() { + getModelExplorerView().revealSemanticElement(selectedElement); + final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + final IWorkbenchPart activePart = activePage.getActivePart(); + + setResult(activePart); + } + }); + + IWorkbenchPart activePart = runnable.getResult(); + + + Assert.assertTrue("The active part is not the ModelExplorer", activePart instanceof ModelExplorerPageBookView); //$NON-NLS-1$ + final IStructuredSelection currentSelection = getCurrentSelection(); + Assert.assertTrue("Multi selction doesn't work with the method revealSemanticElement", currentSelection.size() == size); //$NON-NLS-1$ + } + + /** + * tests the method reveal semantic element on the root element + */ + @Test + public void revealSemanticElement_selectImportedPackage() { + final List selectedElement = new ArrayList(); + final Package pack = (Package)getRootOfTheModel(); + final EList importedPackage = pack.getImportedPackages(); + final int size = importedPackage.size(); + Assert.assertTrue(size != 0);//to be sure that the tested model is correct + for(NamedElement current : importedPackage) { + + waitForPendingMessages(); + + selectedElement.clear(); + selectedElement.add(current); + getModelExplorerView().revealSemanticElement(selectedElement); + RunnableWithResult activePartRunnable; + Display.getDefault().syncExec(activePartRunnable = new RunnableWithResult.Impl() { + + public void run() { + IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + IWorkbenchPart activePart = activePage.getActivePart(); + setResult(activePart); + } + }); + + Assert.assertTrue("The active part is not the ModelExplorer", activePartRunnable.getResult() instanceof ModelExplorerPageBookView); //$NON-NLS-1$ + final IStructuredSelection currentSelection = getCurrentSelection(); + Assert.assertEquals("I don't get the correct selection", 1, currentSelection.size()); //$NON-NLS-1$ + Object obj = currentSelection.getFirstElement(); + obj = EMFHelper.getEObject(obj); + Assert.assertEquals("The function revealSemanticElement seems doesn't work with importedPackage", current, obj); + } + } + + private void waitForPendingMessages() { + //Run all pending tasks to refresh the ModelExplorer + if(Display.getCurrent() != null) { + while(true) { + try { + if(!Display.getCurrent().readAndDispatch()) { + break; + } + } catch (Throwable t) { + Activator.log.error(t); + } + } + } + } + + @Test + public void revealSemanticElement_selectImportedPackageList() { + final List selectedElement = new ArrayList(); + final Package pack = (Package)getRootOfTheModel(); + final EList importedPackage = pack.getImportedPackages(); + final int size = importedPackage.size(); + Assert.assertNotSame(0, size);//to be sure that the tested model is correct + + //Run all pending tasks to refresh the ModelExplorer + waitForPendingMessages(); + + selectedElement.addAll(importedPackage); + getModelExplorerView().revealSemanticElement(selectedElement); + RunnableWithResult activePartRunnable; + Display.getDefault().syncExec(activePartRunnable = new RunnableWithResult.Impl() { + + public void run() { + IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + IWorkbenchPart activePart = activePage.getActivePart(); + setResult(activePart); + } + }); + + Assert.assertTrue("The active part is not the ModelExplorer", activePartRunnable.getResult() instanceof ModelExplorerPageBookView); //$NON-NLS-1$ + final IStructuredSelection currentSelection = getCurrentSelection(); + Assert.assertEquals("I don't get the current selection for revealSemanticElement_importedPackageList", 1, 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/AbstractDualHandlerTest.java b/tests/junit/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer.tests/src/org/eclipse/papyrus/views/modelexplorer/tests/AbstractDualHandlerTest.java index 14be65db9f6..023d3dcd457 100644 --- 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 @@ -24,7 +24,6 @@ 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; @@ -33,6 +32,7 @@ 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; @@ -155,9 +155,7 @@ public abstract class AbstractDualHandlerTest extends AbstractHandlerTest{ // store the root of the model Object[] visibleElement = commonViewer.getVisibleExpandedElements(); - if(visibleElement[0] instanceof IAdaptable) { - modelRoot = (EObject)((IAdaptable)visibleElement[0]).getAdapter(EObject.class); - } + modelRoot = EMFHelper.getEObject(visibleElement[0]); setStatus(Status.OK_STATUS); } 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 9473368cac8..c72717cd71f 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 @@ -24,7 +24,6 @@ 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; @@ -191,9 +190,7 @@ public abstract class AbstractHandlerTest { IStructuredSelection currentSelection = (IStructuredSelection)selectionService.getSelection(); 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); - } + obj = EMFHelper.getEObject(obj); Assert.assertSame("the current selected element is not the wanted element", elementToSelect, obj); //$NON-NLS-1$ } @@ -296,7 +293,7 @@ public abstract class AbstractHandlerTest { // store the root of the model Object[] visibleElement = commonViewer.getVisibleExpandedElements(); - modelRoot = EMFHelper.getEObject(visibleElement[0]); + modelRoot = EMFHelper.getEObject(visibleElement[0]); setStatus(Status.OK_STATUS); } -- cgit v1.2.3