From 50fa5c6a11f8118b9be13f10580284f680a9213e Mon Sep 17 00:00:00 2001 From: vlorenzo Date: Wed, 12 Oct 2011 13:00:35 +0000 Subject: Initial import : 360116: [Model Explorer] Papyrus ModelExplorer should be covered with JUnit Test https://bugs.eclipse.org/bugs/show_bug.cgi?id=360116 --- sandbox/org.eclipse.papyrus.test.common/.classpath | 7 + sandbox/org.eclipse.papyrus.test.common/.project | 28 +++ .../.settings/org.eclipse.jdt.core.prefs | 8 + .../META-INF/MANIFEST.MF | 18 ++ .../build.properties | 9 + .../documentation.pdoc | 4 + .../plugin.properties | 3 + .../org/eclipse/papyrus/test/common/Activator.java | 63 +++++++ .../papyrus/test/common/tests/AbstractTest.java | 204 +++++++++++++++++++++ 9 files changed, 344 insertions(+) create mode 100644 sandbox/org.eclipse.papyrus.test.common/.classpath create mode 100644 sandbox/org.eclipse.papyrus.test.common/.project create mode 100644 sandbox/org.eclipse.papyrus.test.common/.settings/org.eclipse.jdt.core.prefs create mode 100644 sandbox/org.eclipse.papyrus.test.common/META-INF/MANIFEST.MF create mode 100644 sandbox/org.eclipse.papyrus.test.common/build.properties create mode 100644 sandbox/org.eclipse.papyrus.test.common/documentation.pdoc create mode 100644 sandbox/org.eclipse.papyrus.test.common/plugin.properties create mode 100644 sandbox/org.eclipse.papyrus.test.common/src/org/eclipse/papyrus/test/common/Activator.java create mode 100644 sandbox/org.eclipse.papyrus.test.common/src/org/eclipse/papyrus/test/common/tests/AbstractTest.java diff --git a/sandbox/org.eclipse.papyrus.test.common/.classpath b/sandbox/org.eclipse.papyrus.test.common/.classpath new file mode 100644 index 00000000000..2d1a4302f04 --- /dev/null +++ b/sandbox/org.eclipse.papyrus.test.common/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/sandbox/org.eclipse.papyrus.test.common/.project b/sandbox/org.eclipse.papyrus.test.common/.project new file mode 100644 index 00000000000..652e3ca21df --- /dev/null +++ b/sandbox/org.eclipse.papyrus.test.common/.project @@ -0,0 +1,28 @@ + + + org.eclipse.papyrus.test.common + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/sandbox/org.eclipse.papyrus.test.common/.settings/org.eclipse.jdt.core.prefs b/sandbox/org.eclipse.papyrus.test.common/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..5671a8446dd --- /dev/null +++ b/sandbox/org.eclipse.papyrus.test.common/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Mon Oct 10 10:56:03 CEST 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/sandbox/org.eclipse.papyrus.test.common/META-INF/MANIFEST.MF b/sandbox/org.eclipse.papyrus.test.common/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..d9cba884ac1 --- /dev/null +++ b/sandbox/org.eclipse.papyrus.test.common/META-INF/MANIFEST.MF @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.test.common +Bundle-Version: 0.9.0.qualifier +Bundle-Activator: org.eclipse.papyrus.test.common.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.core.resources, + org.eclipse.ui.ide, + org.eclipse.emf.facet.util.core, + org.eclipse.emf.ecore;bundle-version="2.7.0", + org.eclipse.papyrus.core +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Export-Package: org.eclipse.papyrus.test.common.tests +Bundle-Vendor: %providerName +Bundle-Localization: plugin diff --git a/sandbox/org.eclipse.papyrus.test.common/build.properties b/sandbox/org.eclipse.papyrus.test.common/build.properties new file mode 100644 index 00000000000..86d84028606 --- /dev/null +++ b/sandbox/org.eclipse.papyrus.test.common/build.properties @@ -0,0 +1,9 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.properties,\ + documentation.pdoc +src.includes = plugin.properties,\ + documentation.pdoc,\ + META-INF/ diff --git a/sandbox/org.eclipse.papyrus.test.common/documentation.pdoc b/sandbox/org.eclipse.papyrus.test.common/documentation.pdoc new file mode 100644 index 00000000000..5e8b1ef0cbd --- /dev/null +++ b/sandbox/org.eclipse.papyrus.test.common/documentation.pdoc @@ -0,0 +1,4 @@ + + + + diff --git a/sandbox/org.eclipse.papyrus.test.common/plugin.properties b/sandbox/org.eclipse.papyrus.test.common/plugin.properties new file mode 100644 index 00000000000..bebf8acd297 --- /dev/null +++ b/sandbox/org.eclipse.papyrus.test.common/plugin.properties @@ -0,0 +1,3 @@ +#Properties file for org.eclipse.papyrus.test.common +providerName = Eclipse Modeling Project +pluginName = Common plugin for JUnit Tests \ No newline at end of file diff --git a/sandbox/org.eclipse.papyrus.test.common/src/org/eclipse/papyrus/test/common/Activator.java b/sandbox/org.eclipse.papyrus.test.common/src/org/eclipse/papyrus/test/common/Activator.java new file mode 100644 index 00000000000..dada27837f6 --- /dev/null +++ b/sandbox/org.eclipse.papyrus.test.common/src/org/eclipse/papyrus/test/common/Activator.java @@ -0,0 +1,63 @@ +/***************************************************************************** + * Copyright (c) 2011 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.test.common; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.papyrus.test.common"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/sandbox/org.eclipse.papyrus.test.common/src/org/eclipse/papyrus/test/common/tests/AbstractTest.java b/sandbox/org.eclipse.papyrus.test.common/src/org/eclipse/papyrus/test/common/tests/AbstractTest.java new file mode 100644 index 00000000000..e7aae82e710 --- /dev/null +++ b/sandbox/org.eclipse.papyrus.test.common/src/org/eclipse/papyrus/test/common/tests/AbstractTest.java @@ -0,0 +1,204 @@ +/***************************************************************************** + * Copyright (c) 2011 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.test.common.tests; + +import java.io.IOException; +import java.util.Collections; + +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.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.emf.facet.util.core.internal.FileUtils; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.papyrus.core.editor.CoreMultiDiagramEditor; +import org.eclipse.papyrus.core.services.ServiceException; +import org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.osgi.framework.Bundle; + +/** + * An abstract class to do JUnit test + * + * @author VL222926 + * + */ +public class AbstractTest { + + /** the di extension */ + protected static final String EXTENSION_DI = ".di"; //$NON-NLS-1$ + + /** the notation extension */ + protected static final String EXTENSION_NOTATION = ".notation"; //$NON-NLS-1$ + + /** the uml extension */ + protected static final String EXTENSION_UML = ".uml"; //$NON-NLS-1$ + + /** the ResourceSet of the model */ + private ResourceSet resourceSet; + + /** the Papyrus Editor */ + private IEditorPart editor; + + /** + * Clean the workspace and create the new project + * + * @param projectName + * the name of the new project + * @return + * return the new project + * @throws CoreException + */ + protected IProject createProject(final String projectName) throws CoreException { + //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(projectName); + testProject.create(new NullProgressMonitor()); + testProject.open(new NullProgressMonitor()); + return testProject; + } + + /** + * + * @param bundle + * the bundle containing the resources + * @param project + * the project name + * @param filename + * the name of the file to copy + * @throws IOException + * @throws CoreException + */ + protected void copyPapyrusProjectToBundle(final Bundle bundle, final IProject project, final String filename) throws IOException, CoreException { + copyFileFromBundle("/resources/" + filename + EXTENSION_UML, project, '/' + filename + EXTENSION_UML, bundle); //$NON-NLS-1$ + copyFileFromBundle("/resources/" + filename + EXTENSION_NOTATION, project, '/' + filename + EXTENSION_NOTATION, bundle); //$NON-NLS-1$ + copyFileFromBundle("/resources/" + filename + EXTENSION_DI, project, '/' + filename + EXTENSION_DI, bundle); //$NON-NLS-1$ + } + + /** + * + * @param file + * the file to open + * @return + * the opened editor + * @throws PartInitException + */ + protected IEditorPart openEditor(final IFile file) throws PartInitException { + IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + editor = IDE.openEditor(activePage, file); + return editor; + } + + /** + * + * @return + * the resourceSet to use for the test + */ + protected ResourceSet getResourceSet() { + if(resourceSet == null) { + if(editor != null) { + if(editor instanceof CoreMultiDiagramEditor) { + EObject diagram = ((CoreMultiDiagramEditor)editor).getDiagram(); + if(diagram != null) { + resourceSet = diagram.eResource().getResourceSet(); + } + } + } else { + //not tested + // resourceSet = new ResourceSetImpl(); + } + } + return resourceSet; + } + + /** + * + * @param projectName + * the project name + * @param filenameWithExtension + * the name of the file with its extension + * @return + */ + protected Resource getResource(final String projectName, final String filenameWithExtension) { + ResourceSet set = getResourceSet(); + URI uri = URI.createPlatformResourceURI(projectName + "/" + filenameWithExtension, true); //$NON-NLS-1$ + Resource res = set.getResource(uri, false); + if(res == null) { + res = set.createResource(uri); + } + return res; + } + + /** + * Returns the root of the model + * + * @param projectName + * the name of the project + * @param filename + * the name of the file + * @return + * the root of the models + * @throws IOException + */ + protected EObject getRootOfTheModel(final String projectName, final String filenameWithExtension) throws IOException { + Resource res = getResource(projectName, filenameWithExtension); + res.load(Collections.emptyMap()); + return res.getContents().get(0); + } + + /** + * Return the editing domain for the command + * + * @return + * the editing domain for the command + * @throws ServiceException + */ + protected TransactionalEditingDomain getEditingDomain() throws ServiceException { + TransactionalEditingDomain domain = null; + domain = ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain(); + return domain; + } + + /** + * + * @param sourcePath + * the source path + * @param project + * the project + * @param destinationPath + * the destination path + * @param bundle + * the bundle + * @throws IOException + * @throws CoreException + */ + protected void copyFileFromBundle(final String sourcePath, final IProject project, final String destinationPath, final Bundle bundle) throws IOException, CoreException { + FileUtils.copyFileFromBundle(sourcePath, project, destinationPath, bundle); + } +} -- cgit v1.2.3