Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2013-07-24 09:02:23 +0000
committerCamille Letavernier2013-07-24 09:02:23 +0000
commit6e109e8db7159055446a32881742e152f65bbea6 (patch)
tree5399ce708717fb40b79e08e5e53497f66331cfa2 /tests/junit/plugins/junit
parent9ab021e479d8f243341388dd84d4a4d886bc7bc9 (diff)
downloadorg.eclipse.papyrus-6e109e8db7159055446a32881742e152f65bbea6.tar.gz
org.eclipse.papyrus-6e109e8db7159055446a32881742e152f65bbea6.tar.xz
org.eclipse.papyrus-6e109e8db7159055446a32881742e152f65bbea6.zip
408491: Papyrus shall enable to easily switch between local and
registered profiles. https://bugs.eclipse.org/bugs/show_bug.cgi?id=408491 Add test case
Diffstat (limited to 'tests/junit/plugins/junit')
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF6
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/Activator.java6
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/HandlerUtils.java3
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/ModelExplorerUtils.java2
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/ModelUtils.java62
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/PackageExplorerUtils.java3
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/tests/AbstractEditorTest.java115
7 files changed, 190 insertions, 7 deletions
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF
index 14468846b8d..0ebfd2da24e 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/META-INF/MANIFEST.MF
@@ -14,8 +14,10 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="0.10.1",
org.eclipse.papyrus.uml.tools;bundle-version="0.10.1",
org.eclipse.papyrus.editor;bundle-version="0.10.1",
- org.junit;bundle-version="4.10.0"
-Export-Package: org.eclipse.papyrus.junit.utils
+ org.junit;bundle-version="4.10.0",
+ org.eclipse.papyrus.infra.core.log;bundle-version="0.10.1"
+Export-Package: org.eclipse.papyrus.junit.utils,
+ org.eclipse.papyrus.junit.utils.tests
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
Bundle-Version: 0.10.1.qualifier
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/Activator.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/Activator.java
index 1e0b101def1..703f0b176b3 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/Activator.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/Activator.java
@@ -13,6 +13,7 @@
*****************************************************************************/
package org.eclipse.papyrus.junit.utils;
+import org.eclipse.papyrus.infra.core.log.LogHelper;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -27,6 +28,8 @@ public class Activator extends AbstractUIPlugin {
// The shared instance
private static Activator plugin;
+ public static LogHelper log;
+
/**
* The constructor
*/
@@ -38,9 +41,11 @@ public class Activator extends AbstractUIPlugin {
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
+ @Override
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
+ log = new LogHelper(this);
}
/*
@@ -48,6 +53,7 @@ public class Activator extends AbstractUIPlugin {
*
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
+ @Override
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/HandlerUtils.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/HandlerUtils.java
index e76df3ba15b..a2f0000a7e9 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/HandlerUtils.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/HandlerUtils.java
@@ -13,14 +13,13 @@
*****************************************************************************/
package org.eclipse.papyrus.junit.utils;
-import junit.framework.Assert;
-
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
+import org.junit.Assert;
/**
*
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/ModelExplorerUtils.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/ModelExplorerUtils.java
index 8b6cf40f984..994bc52eb5d 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/ModelExplorerUtils.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/ModelExplorerUtils.java
@@ -154,7 +154,7 @@ public class ModelExplorerUtils {
((AbstractHandler)handler).setEnabled(commandToTest);
}
boolean res = handler.isEnabled();
- Assert.assertEquals(wantedResult, res);;
+ Assert.assertEquals(wantedResult, res);
}
/**
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/ModelUtils.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/ModelUtils.java
new file mode 100644
index 00000000000..ac7bb43356d
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/ModelUtils.java
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.junit.utils;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.resource.ModelMultiException;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.utils.DiResourceSet;
+
+/**
+ * Helper class for manipulating Papyrus ModelSets
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class ModelUtils {
+
+ /**
+ * Loads a ModelSet and associates a TransactionalEditingDomain to it
+ *
+ * Use {@link #getEditingDomain(ModelSet)} to retrieve the EditingDomain
+ *
+ * @param uri
+ * @param resolveAll
+ * @return
+ * @throws ModelMultiException
+ */
+ public static ModelSet loadModelSet(URI uri, boolean resolveAll) throws ModelMultiException {
+ ModelSet modelSet = new DiResourceSet();
+ TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(modelSet);
+
+ modelSet.loadModels(uri);
+
+ if(resolveAll) {
+ EcoreUtil.resolveAll(modelSet);
+ }
+
+ return modelSet;
+ }
+
+ public static ModelSet loadModelSet(IPath workspacePath, boolean resolveAll) throws ModelMultiException {
+ URI workspaceURI = URI.createPlatformResourceURI(workspacePath.toString(), true);
+ return loadModelSet(workspaceURI, resolveAll);
+ }
+
+ public static TransactionalEditingDomain getEditingDomain(ModelSet modelSet) {
+ return TransactionalEditingDomain.Factory.INSTANCE.getEditingDomain(modelSet);
+ }
+
+}
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/PackageExplorerUtils.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/PackageExplorerUtils.java
index 1c1266d93ba..d6ef585d17e 100644
--- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/PackageExplorerUtils.java
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/PackageExplorerUtils.java
@@ -15,14 +15,13 @@ package org.eclipse.papyrus.junit.utils;
import java.util.List;
-import junit.framework.Assert;
-
import org.eclipse.jdt.ui.IPackagesViewPart;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
+import org.junit.Assert;
/**
*
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/tests/AbstractEditorTest.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/tests/AbstractEditorTest.java
new file mode 100644
index 00000000000..a5f4b1ccb65
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/tests/AbstractEditorTest.java
@@ -0,0 +1,115 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.junit.utils.tests;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.junit.utils.Activator;
+import org.eclipse.papyrus.junit.utils.EditorUtils;
+import org.eclipse.papyrus.junit.utils.PapyrusProjectUtils;
+import org.eclipse.papyrus.junit.utils.ProjectUtils;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.junit.After;
+import org.junit.Assert;
+import org.osgi.framework.Bundle;
+
+
+public abstract class AbstractEditorTest {
+
+ protected IMultiDiagramEditor editor;
+
+ protected IProject project;
+
+ /**
+ *
+ * @return
+ * the current bundle
+ */
+ protected Bundle getBundle() {
+ return Activator.getDefault().getBundle();
+ }
+
+ /**
+ * Inits this.editor
+ * Fails or throws an exception if an error occurs
+ *
+ * @param bundle
+ * TODO
+ */
+ protected void initModel(String projectName, String modelName, Bundle bundle) throws Exception {
+ project = ProjectUtils.createProject(projectName);
+ final IFile diModelFile = PapyrusProjectUtils.copyPapyrusModel(project, bundle, getSourcePath(), modelName);
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ try {
+ editor = EditorUtils.openPapyrusEditor(diModelFile);
+ } catch (Exception ex) {
+ Activator.log.error(ex);
+ Assert.fail(ex.getMessage());
+ }
+ }
+ });
+
+ Assert.assertNotNull(editor);
+ }
+
+ @After
+ public void dispose() throws Exception {
+ if(editor != null) {
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ ((IEditorPart)editor).getSite().getPage().closeEditor(editor, false);
+ }
+ });
+
+ editor = null;
+ }
+
+ if(project != null) {
+ project.delete(true, new NullProgressMonitor());
+ project = null;
+ }
+ }
+
+ protected IPageManager getPageManager() throws ServiceException {
+ return getServicesRegistry().getService(IPageManager.class);
+ }
+
+ protected ServicesRegistry getServicesRegistry() throws ServiceException {
+ return editor.getServicesRegistry();
+ }
+
+ protected TransactionalEditingDomain getTransactionalEditingDomain() throws ServiceException {
+ return getServicesRegistry().getService(TransactionalEditingDomain.class);
+ }
+
+ protected ModelSet getModelSet() throws ServiceException {
+ return getServicesRegistry().getService(ModelSet.class);
+ }
+
+ /**
+ * The path to the source model folder
+ *
+ * @return
+ */
+ protected abstract String getSourcePath();
+}

Back to the top