Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorytanguy2011-06-15 08:48:48 +0000
committerytanguy2011-06-15 08:48:48 +0000
commit72ed79987d46c5dcfbb9537cb98adf980b206bea (patch)
tree343c4ed195381460c28e02239da3494685a91e3f /tests
parent3a2403b83cac629298dbda9773677bfbc09cb8ff (diff)
downloadorg.eclipse.papyrus-72ed79987d46c5dcfbb9537cb98adf980b206bea.tar.gz
org.eclipse.papyrus-72ed79987d46c5dcfbb9537cb98adf980b206bea.tar.xz
org.eclipse.papyrus-72ed79987d46c5dcfbb9537cb98adf980b206bea.zip
NEW - bug 348832: [Element Edit Service] JUnit tests the Element Edit Service
https://bugs.eclipse.org/bugs/show_bug.cgi?id=348832
Diffstat (limited to 'tests')
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/.classpath7
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/.project28
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/.settings/org.eclipse.jdt.core.prefs8
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/META-INF/MANIFEST.MF9
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/about.html28
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/build.properties4
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/model/EmptyModel.di9
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/model/EmptyModel.notation2
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/model/EmptyModel.uml2
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/plugin.properties14
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/AbstractTestElementEditService.java104
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/commands/TestConfigureFeatureCommandFactory.java78
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/commands/TestConfigureFeatureListCommandFactory.java87
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/context/TestClientContext.java24
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/edit/helper/EPackageEditHelper.java35
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditService.java114
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditServiceProvider.java159
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditServiceProviderFactory.java37
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditServiceUtils.java42
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/utils/TestElementTypeValidator.java32
-rw-r--r--tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/utils/TestGMFCommandUtils.java56
21 files changed, 879 insertions, 0 deletions
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/.classpath b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/.project b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/.project
new file mode 100644
index 00000000000..9bd83add45a
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.service.edit.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/.settings/org.eclipse.jdt.core.prefs b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..a9c958114ad
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Thu Jun 09 15:15:42 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/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..9b287648d41
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,9 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.papyrus.service.edit.tests
+Bundle-Version: 0.8.0.qualifier
+Bundle-Vendor: %providerName
+Fragment-Host: org.eclipse.papyrus.service.edit;bundle-version="0.8.0"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.junit;bundle-version="4.8.2"
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/about.html b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/about.html
new file mode 100644
index 00000000000..82d49bf5f81
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/build.properties b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/build.properties
new file mode 100644
index 00000000000..41eb6ade2b4
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/model/EmptyModel.di b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/model/EmptyModel.di
new file mode 100644
index 00000000000..67cd21c0e77
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/model/EmptyModel.di
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="ASCII"?>
+<di:SashWindowsMngr xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.eclipse.org/papyrus/0.7.0/sashdi">
+ <pageList/>
+ <sashModel currentSelection="//@sashModel/@windows.0/@children.0">
+ <windows>
+ <children xsi:type="di:TabFolder"/>
+ </windows>
+ </sashModel>
+</di:SashWindowsMngr>
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/model/EmptyModel.notation b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/model/EmptyModel.notation
new file mode 100644
index 00000000000..8634d4c00e0
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/model/EmptyModel.notation
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"/>
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/model/EmptyModel.uml b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/model/EmptyModel.uml
new file mode 100644
index 00000000000..d208fdf1a1f
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/model/EmptyModel.uml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_UV0P8EAREeCMpNWxgNcrog" name="model"/>
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/plugin.properties b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/plugin.properties
new file mode 100644
index 00000000000..8cd059de3ac
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/plugin.properties
@@ -0,0 +1,14 @@
+#################################################################################
+# 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:
+#
+# CEA LIST - Initial API and Implementation.
+#
+##################################################################################
+pluginName=Papyrus Edit Service Tests (Incubation)
+providerName=Eclipse Modeling Project
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/AbstractTestElementEditService.java b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/AbstractTestElementEditService.java
new file mode 100644
index 00000000000..f9167e9d4ae
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/AbstractTestElementEditService.java
@@ -0,0 +1,104 @@
+package org.eclipse.papyrus.service.edit.tests;
+
+import static org.junit.Assert.fail;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.gmf.runtime.emf.type.core.ClientContextManager;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.MetamodelType;
+import org.eclipse.papyrus.service.edit.Activator;
+import org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.service.edit.service.IElementEditServiceProvider;
+import org.eclipse.papyrus.service.edit.tests.edit.helper.EPackageEditHelper;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+/**
+ * Abstract Papyrus initialization class (required to get Service activation).
+ */
+public abstract class AbstractTestElementEditService {
+
+ protected static final String PAPYRUS_CONTEXT_ID = "org.eclipse.papyrus.service.edit.TypeContext"; //$NON-NLS-1$
+
+ protected IElementType eClassType;
+ protected IElementType ePackgType;
+
+ protected IElementEditServiceProvider service;
+
+ @BeforeClass
+ public static void openPapyrusWithAnEmptyProject() {
+
+ try {
+ // Prepare new project for tests
+ IProject testProject = ResourcesPlugin.getWorkspace().getRoot().getProject("TestProject");
+ if (! testProject.exists()) {
+ testProject.create(new NullProgressMonitor());
+ }
+ if (! testProject.isOpen()) {
+ testProject.open(new NullProgressMonitor());
+ }
+
+ // Copy EmptyModel from bundle to the test project
+ IFile emptyModel_di = testProject.getFile("EmptyModel.di");
+ IFile emptyModel_no = testProject.getFile("EmptyModel.notation");
+ IFile emptyModel_uml = testProject.getFile("EmptyModel.uml");
+
+ emptyModel_di.create(Activator.getDefault().getBundle().getResource("/model/EmptyModel.di").openStream(), true, new NullProgressMonitor());
+ emptyModel_no.create(Activator.getDefault().getBundle().getResource("/model/EmptyModel.notation").openStream(), true, new NullProgressMonitor());
+ emptyModel_uml.create(Activator.getDefault().getBundle().getResource("/model/EmptyModel.uml").openStream(), true, new NullProgressMonitor());
+
+ // Open the EmptyModel.di file with Papyrus (assumed to be the default editor for "di" files here).
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(emptyModel_di.getName());
+ page.openEditor(new FileEditorInput(emptyModel_di), desc.getId());
+
+ } catch (Exception e) {
+ fail("Papyrus initialization failed ("+ e.getMessage() +")."); // $NON-NLS-1$
+ }
+ }
+
+ @Before
+ public void setUp() {
+ // To prepare this test two element types are added to Papyrus Client Context
+ ElementTypeRegistry.getInstance().register(new MetamodelType("ECLASS_TEST_ID", null, "ECLASS", EcorePackage.eINSTANCE.getEClass(), null)); //$NON-NLS-1$
+ ElementTypeRegistry.getInstance().register(new MetamodelType("EPACKG_TEST_ID", null, "EPACKG", EcorePackage.eINSTANCE.getEPackage(), new EPackageEditHelper())); //$NON-NLS-1$
+
+ eClassType = ElementTypeRegistry.getInstance().getType("ECLASS_TEST_ID");
+ ePackgType = ElementTypeRegistry.getInstance().getType("EPACKG_TEST_ID");
+
+ IClientContext context = ClientContextManager.getInstance().getClientContext(PAPYRUS_CONTEXT_ID);
+ context.bindId("ECLASS_TEST_ID"); //$NON-NLS-1$
+ context.bindId("EPACKG_TEST_ID"); //$NON-NLS-1$
+
+ service = ElementEditServiceUtils.getEditServiceProvider();
+ }
+
+ @AfterClass
+ public static void closePapyrusAndCleanProject() {
+ // Close all editors
+ boolean closed = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
+ if (! closed) {
+ fail("Could not close editors correctly.");
+ }
+
+ // Delete test project
+ IProject testProject = ResourcesPlugin.getWorkspace().getRoot().getProject("TestProject");
+ try {
+ testProject.delete(true, new NullProgressMonitor());
+ } catch (CoreException e) {
+ fail("Could delete test project correctly ("+e.getMessage()+").");
+ }
+ }
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/commands/TestConfigureFeatureCommandFactory.java b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/commands/TestConfigureFeatureCommandFactory.java
new file mode 100644
index 00000000000..0fd6333e392
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/commands/TestConfigureFeatureCommandFactory.java
@@ -0,0 +1,78 @@
+package org.eclipse.papyrus.service.edit.tests.commands;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.ClientContextManager;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.service.edit.commands.ConfigureFeatureCommandFactory;
+import org.eclipse.papyrus.service.edit.commands.IConfigureCommandFactory;
+import org.eclipse.papyrus.service.edit.internal.ElementEditService;
+import org.eclipse.papyrus.service.edit.service.IElementEditService;
+import org.eclipse.papyrus.service.edit.tests.AbstractTestElementEditService;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link ConfigureFeatureCommandFactory} class.
+ */
+public class TestConfigureFeatureCommandFactory extends AbstractTestElementEditService {
+
+ IClientContext context;
+
+ IElementEditService ePckgService;
+
+ EPackage ePckg;
+
+ @Before
+ public void setUp() {
+ super.setUp();
+
+ context = ClientContextManager.getInstance().getClientContext(PAPYRUS_CONTEXT_ID);
+ ePckgService = new ElementEditService(ePackgType, context);
+ ePckg = EcoreFactory.eINSTANCE.createEPackage();
+ }
+
+ @Test
+ public void testGetEditCommand() {
+ try {
+
+ ICommand correctCommand = ePckgService.getEditCommand(prepareCorrectRequest());
+
+ // Try to execute command and make quick result verification.
+ assertTrue("The service command should be executable.", correctCommand.canExecute());
+ correctCommand.execute(new NullProgressMonitor(), null);
+ assertTrue("The service command result is incorrect.", !ePckg.getESubpackages().isEmpty());
+ assertTrue("The service configure command result is incorrect.", "ASpecificName".equals(ePckg.getESubpackages().get(0).getName()));
+
+ } catch (ServiceException e) {
+ fail("Test aborted - Papyrus editing domain not found.");
+ } catch (ExecutionException e) {
+ fail("Test aborted - Command execution failed.");
+ }
+ }
+
+ /** Prepare a creation request (create a EPackage in an EPackage) and adds a ConfigureFeatureCommand */
+ @SuppressWarnings("unchecked")
+ private IEditCommandRequest prepareCorrectRequest() throws ServiceException {
+ TransactionalEditingDomain editingDomain = ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain();
+ IEditCommandRequest request = new CreateElementRequest(editingDomain, ePckg, ePackgType);
+
+ // Create a configure command factory and add it to the request
+ IConfigureCommandFactory factory = new ConfigureFeatureCommandFactory(EcorePackage.eINSTANCE.getENamedElement_Name(), "ASpecificName");
+ request.getParameters().put(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, factory);
+
+ return request;
+ }
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/commands/TestConfigureFeatureListCommandFactory.java b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/commands/TestConfigureFeatureListCommandFactory.java
new file mode 100644
index 00000000000..0199a99ddf4
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/commands/TestConfigureFeatureListCommandFactory.java
@@ -0,0 +1,87 @@
+package org.eclipse.papyrus.service.edit.tests.commands;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.ClientContextManager;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.service.edit.commands.ConfigureFeatureListCommandFactory;
+import org.eclipse.papyrus.service.edit.commands.IConfigureCommandFactory;
+import org.eclipse.papyrus.service.edit.internal.ElementEditService;
+import org.eclipse.papyrus.service.edit.service.IElementEditService;
+import org.eclipse.papyrus.service.edit.tests.AbstractTestElementEditService;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link ConfigureFeatureListCommandFactory} class.
+ */
+public class TestConfigureFeatureListCommandFactory extends AbstractTestElementEditService {
+
+ IClientContext context;
+
+ IElementEditService ePckgService;
+
+ EPackage ePckg;
+
+ @Before
+ public void setUp() {
+ super.setUp();
+
+ context = ClientContextManager.getInstance().getClientContext(PAPYRUS_CONTEXT_ID);
+ ePckgService = new ElementEditService(ePackgType, context);
+ ePckg = EcoreFactory.eINSTANCE.createEPackage();
+ }
+
+ @Test
+ public void testGetEditCommand() {
+ try {
+
+ ICommand correctCommand = ePckgService.getEditCommand(prepareCorrectRequest());
+
+ // Try to execute command and make quick result verification.
+ assertTrue("The service command should be executable.", correctCommand.canExecute());
+ correctCommand.execute(new NullProgressMonitor(), null);
+ assertTrue("The service command result is incorrect.", !ePckg.getESubpackages().isEmpty());
+ assertTrue("The service configure command result is incorrect.", "ASpecificName".equals(ePckg.getESubpackages().get(0).getName()));
+ assertTrue("The service configure command result is incorrect.", "ASpecificNsURI".equals(ePckg.getESubpackages().get(0).getNsURI()));
+
+ } catch (ServiceException e) {
+ fail("Test aborted - Papyrus editing domain not found.");
+ } catch (ExecutionException e) {
+ fail("Test aborted - Command execution failed.");
+ }
+ }
+
+ /** Prepare a creation request (create a EPackage in an EPackage) and adds a ConfigureFeatureCommand */
+ @SuppressWarnings("unchecked")
+ private IEditCommandRequest prepareCorrectRequest() throws ServiceException {
+ TransactionalEditingDomain editingDomain = ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain();
+ IEditCommandRequest request = new CreateElementRequest(editingDomain, ePckg, ePackgType);
+
+ // Create a configure command factory and add it to the request
+ Map<EStructuralFeature, Object> featureValueMap = new HashMap<EStructuralFeature, Object>();
+ featureValueMap.put(EcorePackage.eINSTANCE.getENamedElement_Name(), "ASpecificName");
+ featureValueMap.put(EcorePackage.eINSTANCE.getEPackage_NsURI(), "ASpecificNsURI");
+
+ IConfigureCommandFactory factory = new ConfigureFeatureListCommandFactory(featureValueMap);
+ request.getParameters().put(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, factory);
+
+ return request;
+ }
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/context/TestClientContext.java b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/context/TestClientContext.java
new file mode 100644
index 00000000000..f7befede79a
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/context/TestClientContext.java
@@ -0,0 +1,24 @@
+package org.eclipse.papyrus.service.edit.tests.context;
+
+import static org.junit.Assert.fail;
+
+import org.eclipse.gmf.runtime.emf.type.core.ClientContextManager;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.junit.Test;
+
+/**
+ * JUnit tests Papyrus ElementTypeRegistry binding context.
+ */
+public class TestClientContext {
+
+ private static final String PAPYRUS_CONTEXT_ID = "org.eclipse.papyrus.service.edit.TypeContext"; //$NON-NLS-1$
+
+ @Test
+ public void testClientContextExist() {
+ IClientContext context = ClientContextManager.getInstance().getClientContext(PAPYRUS_CONTEXT_ID);
+ if (context == null) {
+ fail("Papyrus IClientContext could not be found.");
+ }
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/edit/helper/EPackageEditHelper.java b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/edit/helper/EPackageEditHelper.java
new file mode 100644
index 00000000000..ce0a62cea7f
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/edit/helper/EPackageEditHelper.java
@@ -0,0 +1,35 @@
+/*****************************************************************************
+ * 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:
+ *
+ * Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.service.edit.tests.edit.helper;
+
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.papyrus.service.edit.commands.IConfigureCommandFactory;
+
+public class EPackageEditHelper extends AbstractEditHelper {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected ICommand getConfigureCommand(ConfigureRequest req) {
+ if (req.getParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID) != null) {
+ IConfigureCommandFactory factory = (IConfigureCommandFactory) req.getParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID);
+ return factory.create(req);
+ }
+ return super.getConfigureCommand(req);
+ }
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditService.java b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditService.java
new file mode 100644
index 00000000000..63504f4554d
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditService.java
@@ -0,0 +1,114 @@
+package org.eclipse.papyrus.service.edit.tests.service;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.ClientContextManager;
+import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.service.edit.internal.ElementEditService;
+import org.eclipse.papyrus.service.edit.service.IElementEditService;
+import org.eclipse.papyrus.service.edit.tests.AbstractTestElementEditService;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link ElementEditService} class.
+ */
+public class TestElementEditService extends AbstractTestElementEditService {
+
+ // IElementType declared for testing purpose in super class:
+ // MetamodelType("ECLASS_TEST_ID", null, "ECLASS", EcorePackage.eINSTANCE.getEClass(), null); //$NON-NLS-1$
+ // MetamodelType("EPACKG_TEST_ID", null, "EPACKG", EcorePackage.eINSTANCE.getEPackage(), null); //$NON-NLS-1$
+
+ IClientContext context;
+
+ IElementEditService ePckgService;
+
+ IElementEditService eClassService;
+
+ EPackage ePckg;
+
+ EClass eClass;
+
+ @Before
+ public void setUp() {
+ super.setUp();
+
+ context = ClientContextManager.getInstance().getClientContext(PAPYRUS_CONTEXT_ID);
+
+ ePckgService = new ElementEditService(ePackgType, context);
+ eClassService = new ElementEditService(eClassType, context);
+
+ ePckg = EcoreFactory.eINSTANCE.createEPackage();
+ eClass = EcoreFactory.eINSTANCE.createEClass();
+ }
+
+ @Test
+ public void testCanEdit() {
+ try {
+ assertTrue("The service should be able to edit the request.", ePckgService.canEdit(prepareCorrectRequest()));
+ assertFalse("The service should not be able to edit the request.", ePckgService.canEdit(prepareIncorrectRequest()));
+ } catch (ServiceException e) {
+ fail("Test aborted - Papyrus editing domain not found.");
+ }
+ }
+
+ @Test
+ public void testGetEditCommand() {
+ try {
+
+ ICommand correctCommand = ePckgService.getEditCommand(prepareCorrectRequest());
+ ICommand incorrectCommand = ePckgService.getEditCommand(prepareIncorrectRequest());
+
+ // Try to execute command and make quick result verification.
+ assertTrue("The service command should be executable.", correctCommand.canExecute());
+ correctCommand.execute(new NullProgressMonitor(), null);
+ assertTrue("The service command result is incorrect.", !ePckg.getESubpackages().isEmpty());
+
+ // With incorrect request the command should not be executable.
+ assertFalse("The service command should not be executable.", incorrectCommand.canExecute());
+
+ } catch (ServiceException e) {
+ fail("Test aborted - Papyrus editing domain not found.");
+ } catch (ExecutionException e) {
+ fail("Test aborted - Command execution failed.");
+ }
+ }
+
+ @Test
+ public void testGetDisplayName() {
+ String displayName = ePckgService.getDisplayName();
+ assertTrue("Incorrect display name retrieved.", displayName.equals("EPACKG"));
+ }
+
+ @Test
+ public void testGetAdapter() {
+ IElementType type = (IElementType)ePckgService.getAdapter(IElementType.class);
+ assertTrue("Incorrect type adaptation.", type == ePackgType);
+ }
+
+ /** Correct creation request (create a EPackage in an EPackage) */
+ private IEditCommandRequest prepareCorrectRequest() throws ServiceException {
+ TransactionalEditingDomain editingDomain = ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain();
+ return new CreateElementRequest(editingDomain, ePckg, ePackgType);
+ }
+
+ /** Incorrect creation request (create a EClass in an EPackage) */
+ private IEditCommandRequest prepareIncorrectRequest() throws ServiceException {
+ TransactionalEditingDomain editingDomain = ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain();
+ return new CreateElementRequest(editingDomain, eClass, ePackgType);
+ }
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditServiceProvider.java b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditServiceProvider.java
new file mode 100644
index 00000000000..7b39a5bb675
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditServiceProvider.java
@@ -0,0 +1,159 @@
+package org.eclipse.papyrus.service.edit.tests.service;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.IMetamodelType;
+import org.eclipse.gmf.runtime.emf.type.core.MetamodelType;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.service.edit.internal.ElementEditServiceProvider;
+import org.eclipse.papyrus.service.edit.service.IElementEditService;
+import org.eclipse.papyrus.service.edit.service.IElementEditServiceProvider;
+import org.eclipse.papyrus.service.edit.tests.AbstractTestElementEditService;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link ElementEditServiceProvider} class.
+ */
+public class TestElementEditServiceProvider extends AbstractTestElementEditService {
+
+ IElementEditServiceProvider provider;
+
+ @Before
+ public void setUp() {
+ super.setUp();
+
+ try {
+ provider = ElementEditServiceProvider.getInstance();
+ } catch (ServiceException e) {
+ fail("Test aborted - Singleton IElementEditServiceProvider not found.");
+ }
+ }
+
+ @Test
+ public void testGetEditService_EClass() {
+
+ try {
+ IElementEditService attService = provider.getEditService(EcorePackage.eINSTANCE.getEAttribute());
+ assertTrue("No IElementEditService found for EAttribute.", attService != null);
+ String attServiceDisplayName = attService.getDisplayName();
+ assertTrue("Default IElementEditService should match EAttribute.", attServiceDisplayName.equals("Generic Element"));
+
+ IElementEditService packService = provider.getEditService(EcorePackage.eINSTANCE.getEPackage());
+ assertTrue("No IElementEditService found for EPackage.", packService != null);
+ // Check result
+ assertTrue("The IElementEditService should be EPackage related.", packService.getDisplayName().equals("EPACKG"));
+
+ } catch (ServiceException e) {
+ fail("Test aborted - Service exception in ElementEditServiceProvider::getEditService(EClass).");
+ }
+ }
+
+ @Test
+ public void testGetEditService_EObject() {
+
+ try {
+ EAttribute att = EcoreFactory.eINSTANCE.createEAttribute();
+ EPackage pack = EcoreFactory.eINSTANCE.createEPackage();
+
+ IElementEditService attService = provider.getEditService(att);
+ assertTrue("No IElementEditService found for EAttribute.", attService != null);
+ String attServiceDisplayName = attService.getDisplayName();
+ assertTrue("Default IElementEditService should match EAttribute.", attServiceDisplayName.equals("Generic Element"));
+
+ IElementEditService packService = provider.getEditService(pack);
+ assertTrue("No IElementEditService found for EPackage.", packService != null);
+
+ // Check result
+ assertTrue("The IElementEditService should be EPackage related.", packService.getDisplayName().equals("EPACKG"));
+
+ } catch (ServiceException e) {
+ fail("Test aborted - Service exception in ElementEditServiceProvider::getEditService(EObject).");
+ }
+ }
+
+ @Test
+ public void testGetEditService_IElementType() {
+
+ try {
+
+ IElementEditService packService = provider.getEditService(ePackgType);
+ assertTrue("No IElementEditService found for EPackage.", packService != null);
+ // Check result
+ assertTrue("The IElementEditService should be EPackage related.", packService.getDisplayName().equals("EPACKG"));
+
+ } catch (ServiceException e) {
+ fail("Test aborted - Service exception in ElementEditServiceProvider::getEditService(EObject).");
+ }
+
+ try {
+
+ ElementTypeRegistry.getInstance().register(new MetamodelType("ETT_TEST_ID", null, "EATT", EcorePackage.eINSTANCE.getEAttribute(), null)); //$NON-NLS-1$
+ IElementType eAtt = ElementTypeRegistry.getInstance().getType("ETT_TEST_ID");
+ IElementEditService attService = provider.getEditService(eAtt);
+ assertTrue("No IElementEditService should match EAttribute.", attService == null);
+
+ } catch (ServiceException e) {
+ // Exception expected.
+ return;
+ }
+
+ fail("The service is supposed to thow exception when the IElementType is incorrect.");
+ }
+
+ @Test
+ public void testGetEditService_Unknown() {
+ try {
+ provider.getEditService("Incorrect_Object");
+ } catch (ServiceException e) {
+ // An exception should be thrown
+ return;
+ }
+
+ fail("No exception thrown will the object cannot be handled.");
+ }
+
+ @Test
+ public void testGetContainedTypeEditServices() {
+ EPackage aPackage = EcoreFactory.eINSTANCE.createEPackage();
+ EClass aClass = EcoreFactory.eINSTANCE.createEClass();
+
+ try {
+ List<IElementEditService> package_ESubpackages = provider.getContainedTypeEditServices(aPackage, EcorePackage.eINSTANCE.getEPackage_ESubpackages());
+ assertTrue("Only 1 IElementEditService should match EcorePackage.eINSTANCE.getEPackage_ESubpackages()", package_ESubpackages.size() == 1);
+
+ // Check result
+ IElementEditService service = package_ESubpackages.get(0);
+ assertTrue("The IElementEditService should be EPackage related.", service.getDisplayName().equals("EPACKG"));
+
+ List<IElementEditService> class_EOperations = provider.getContainedTypeEditServices(aClass, EcorePackage.eINSTANCE.getEClass_EOperations());
+ assertTrue("No IElementEditService should match EcorePackage.eINSTANCE.getEClass_EOperations()", class_EOperations.size() == 0);
+
+ } catch (ServiceException e) {
+ fail("Test aborted - Service exception in ElementEditServiceProvider::getContainedTypeEditServices.");
+ }
+ }
+
+ @Test
+ public void testIsKnownElementType() {
+ assertFalse("Current IElementType id should not be known.", provider.isKnownElementType("unknown_id"));
+ assertTrue("Current IElementType id should be known.", provider.isKnownElementType(eClassType.getId()));
+
+ // Add an IElementType, not bound to Papyrus context - Should be considered as ignored
+ IMetamodelType eAttr = new MetamodelType("out_of_context_id", null, "EATTR", EcorePackage.eINSTANCE.getEAttribute(), null); //$NON-NLS-1$
+ ElementTypeRegistry.getInstance().register(eAttr);
+
+ assertFalse("Current IElementType id should not be known.", provider.isKnownElementType(eAttr.getId()));
+ }
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditServiceProviderFactory.java b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditServiceProviderFactory.java
new file mode 100644
index 00000000000..c926e505ef7
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditServiceProviderFactory.java
@@ -0,0 +1,37 @@
+package org.eclipse.papyrus.service.edit.tests.service;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.service.edit.internal.ElementEditServiceProviderFactory;
+import org.eclipse.papyrus.service.edit.service.IElementEditServiceProvider;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link ElementEditServiceProviderFactory} class.
+ * No specific implementation (no specific test) provided for start / dispose / init.
+ */
+public class TestElementEditServiceProviderFactory {
+
+ @Test
+ public void testCreateServiceInstance() {
+
+ Object service = null;
+
+ try {
+
+ ElementEditServiceProviderFactory factory = new ElementEditServiceProviderFactory();
+ service = factory.createServiceInstance();
+
+ } catch (ServiceException e) {
+ fail("Factory throws exception during service creation ("+e.getMessage()+").");
+ return;
+ }
+
+ assertNotNull("Created service is null.", service);
+ assertTrue("Unexpected kind of service created.", service instanceof IElementEditServiceProvider);
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditServiceUtils.java b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditServiceUtils.java
new file mode 100644
index 00000000000..b25b0e98dde
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/service/TestElementEditServiceUtils.java
@@ -0,0 +1,42 @@
+package org.eclipse.papyrus.service.edit.tests.service;
+
+import static org.junit.Assert.fail;
+
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.service.edit.service.IElementEditService;
+import org.eclipse.papyrus.service.edit.service.IElementEditServiceProvider;
+import org.eclipse.papyrus.service.edit.tests.AbstractTestElementEditService;
+import org.junit.Test;
+
+public class TestElementEditServiceUtils extends AbstractTestElementEditService {
+
+ @Test
+ public void testGetCommandProvider() {
+
+ // Test EPackage access
+ EPackage eP = EcoreFactory.eINSTANCE.createEPackage();
+ IElementEditService serviceForEPack = ElementEditServiceUtils.getCommandProvider(eP);
+
+ if(serviceForEPack == null) {
+ fail("No IElementEditService found for EPackage.");
+ }
+
+ // Try to get related IElementType to ensure a correct provider is returned
+ IElementType elementType = (IElementType)serviceForEPack.getAdapter(IElementType.class);
+ if(elementType != ePackgType) {
+ fail("The IElementEditService does not rely on the correct IElementType.");
+ }
+ }
+
+ @Test
+ public void testGetEditServiceProvider() {
+ IElementEditServiceProvider provider = ElementEditServiceUtils.getEditServiceProvider();
+ if(provider == null) {
+ fail("Element edit service can not be found.");
+ }
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/utils/TestElementTypeValidator.java b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/utils/TestElementTypeValidator.java
new file mode 100644
index 00000000000..a160866f33d
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/utils/TestElementTypeValidator.java
@@ -0,0 +1,32 @@
+package org.eclipse.papyrus.service.edit.tests.utils;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.papyrus.service.edit.tests.AbstractTestElementEditService;
+import org.eclipse.papyrus.service.edit.utils.ElementTypeValidator;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link ElementTypeValidator} class.
+ */
+public class TestElementTypeValidator extends AbstractTestElementEditService {
+
+ @Test
+ public void testValidate() {
+
+ // Prepare validator.
+ ElementTypeValidator validator = new ElementTypeValidator(ePackgType);
+
+ Object[] test1 = {EcoreFactory.eINSTANCE.createEPackage()};
+ assertTrue("Should validate EPackage.", validator.validate(test1).isOK());
+
+ Object[] test2 = {EcoreFactory.eINSTANCE.createEAttribute()};
+ assertFalse("Should not validate EAttribute.", validator.validate(test2).isOK());
+
+ Object[] test3 = {};
+ assertFalse("Should not validate empty selection.", validator.validate(test3).isOK());
+ }
+
+}
diff --git a/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/utils/TestGMFCommandUtils.java b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/utils/TestGMFCommandUtils.java
new file mode 100644
index 00000000000..1e62384211d
--- /dev/null
+++ b/tests/junit/plugins/core/org.eclipse.papyrus.service.edit.tests/src/org/eclipse/papyrus/service/edit/tests/utils/TestGMFCommandUtils.java
@@ -0,0 +1,56 @@
+package org.eclipse.papyrus.service.edit.tests.utils;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.utils.ServiceUtilsForActionHandlers;
+import org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.service.edit.tests.AbstractTestElementEditService;
+import org.eclipse.papyrus.service.edit.utils.GMFCommandUtils;
+import org.junit.Test;
+
+/**
+ * JUnit tests for {@link GMFCommandUtils} class.
+ */
+public class TestGMFCommandUtils extends AbstractTestElementEditService {
+
+ @Test
+ public void testGetCommandEObjectResult() {
+
+ try {
+
+ TransactionalEditingDomain editingDomain = ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain();
+
+ // Prepare and execute a command that adds a sub-EPackage
+ EPackage ePckg = EcoreFactory.eINSTANCE.createEPackage();
+ CreateElementRequest req = new CreateElementRequest(editingDomain, ePckg, ePackgType);
+ ICommand createCommand = ElementEditServiceUtils.getCommandProvider(ePckg).getEditCommand(req);
+
+ // Try to execute command and make quick result verification.
+ assertTrue("The service command should be executable.", createCommand.canExecute());
+ createCommand.execute(new NullProgressMonitor(), null);
+
+ // Inspect the result (should be a new EObject)
+ EObject eObject = GMFCommandUtils.getCommandEObjectResult(createCommand);
+ assertTrue("Could not get new element from command.", eObject != null);
+ assertTrue("New element from command should be an EPackage.", eObject instanceof EPackage);
+
+ } catch (ServiceException e) {
+ fail("Test aborted - Service exception.");
+
+ } catch (ExecutionException e) {
+ fail("Test aborted - Command execution failed.");
+ }
+
+ }
+
+}

Back to the top