Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/junit/plugins/infra')
-rw-r--r--tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/META-INF/MANIFEST.MF7
-rw-r--r--tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/pom.xml2
-rw-r--r--tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/tests/CreateEditBasedElementCommandTest.java125
-rw-r--r--tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/tests/AllTests.java4
4 files changed, 133 insertions, 5 deletions
diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/META-INF/MANIFEST.MF
index 9676e8c81a5..bb2e1a825c0 100644
--- a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/META-INF/MANIFEST.MF
@@ -7,12 +7,13 @@ Require-Bundle: org.junit;bundle-version="4.10.0",
org.eclipse.papyrus.infra.gmfdiag.canonical;bundle-version="1.2.0",
org.eclipse.uml2.uml;bundle-version="5.1.0",
org.eclipse.papyrus.infra.types.core;bundle-version="[3.0.0,4.0.0)",
- org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.2.0",
- org.eclipse.papyrus.uml.diagram.clazz;bundle-version="2.0.0"
+ org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="3.0.0",
+ org.eclipse.papyrus.uml.diagram.clazz;bundle-version="2.0.0",
+ org.eclipse.papyrus.uml.service.types;bundle-version="2.0.0"
Export-Package: org.eclipse.papyrus.infra.gmfdiag.common.tests,
org.eclipse.papyrus.infra.gmfdiag.common.utils
Bundle-Vendor: %providerName
-Bundle-Version: 1.2.0.qualifier
+Bundle-Version: 3.0.0.qualifier
Bundle-Name: %pluginName
Bundle-Localization: plugin
Bundle-ManifestVersion: 2
diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/pom.xml b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/pom.xml
index 204b9103979..889089da13b 100644
--- a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/pom.xml
+++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/pom.xml
@@ -10,6 +10,6 @@
</parent>
<groupId>org.eclipse.papyrus</groupId>
<artifactId>org.eclipse.papyrus.infra.gmfdiag.common.tests</artifactId>
- <version>1.2.0-SNAPSHOT</version>
+ <version>3.0.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
</project>
diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/tests/CreateEditBasedElementCommandTest.java b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/tests/CreateEditBasedElementCommandTest.java
new file mode 100644
index 00000000000..a4d2d200e2b
--- /dev/null
+++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/tests/CreateEditBasedElementCommandTest.java
@@ -0,0 +1,125 @@
+/*****************************************************************************
+ * Copyright (c) 2016 Christian W. Damus and others.
+ *
+ * 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.commands.tests;
+
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EFactory;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.CreateEditBasedElementCommand;
+import org.eclipse.papyrus.junit.utils.rules.ModelSetFixture;
+import org.eclipse.papyrus.junit.utils.rules.PluginResource;
+import org.eclipse.papyrus.junit.utils.rules.ServiceRegistryModelSetFixture;
+import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Tests for the {@link CreateEditBasedElementCommand} class.
+ */
+@PluginResource("models/ExpansionModelTest.di")
+public class CreateEditBasedElementCommandTest {
+
+ @Rule
+ public final ModelSetFixture fixture = new ServiceRegistryModelSetFixture();
+
+ private List<String> invocations = new ArrayList<>();
+
+ @Test
+ public void createElement() {
+ CreateElementRequest request = new CreateElementRequest(fixture.getModel(), UMLElementTypes.CLASS);
+ CreateEditBasedElementCommand command = new CreateEditBasedElementCommand(request);
+ assertThat(command.canExecute(), is(true));
+
+ fixture.execute(command);
+
+ // A new class is always given a default name by edit advice
+ assertThat(invocations, hasItem("setName"));
+ }
+
+ //
+ // Test framework
+ //
+
+ @Before
+ public void installUMLFactory() {
+ // Install reflective proxies for the standard package and factory that
+ // create reflective proxies for model elements
+ ClassLoader cl = getClass().getClassLoader();
+
+ EFactory[] eFactory = { null };
+ EPackage[] ePackage = { null };
+
+ ePackage[0] = (EPackage) Proxy.newProxyInstance(cl, new Class[] { UMLPackage.class },
+ (__, method, args) -> {
+ switch (method.getName()) {
+ case "getEFactoryInstance":
+ case "getUMLFactory":
+ return eFactory[0];
+ default:
+ return method.invoke(UMLPackage.eINSTANCE, args);
+ }
+ });
+ eFactory[0] = (EFactory) Proxy.newProxyInstance(cl, new Class[] { UMLFactory.class },
+ (__, method, args) -> {
+ switch (method.getName()) {
+ case "getEPackage":
+ case "getUMLPackage":
+ return ePackage[0];
+ case "create":
+ EClass eClass = (EClass) args[0];
+ EObject realObject = (EObject) method.invoke(UMLFactory.eINSTANCE, args);
+ return Proxy.newProxyInstance(cl, new Class[] {
+ eClass.getInstanceClass(),
+ InternalEObject.class,
+ }, (___, method1, args1) -> {
+ recordInvocation(method1.getName());
+ return method1.invoke(realObject, args1);
+ });
+ default:
+ return method.invoke(UMLFactory.eINSTANCE, args);
+ }
+ });
+
+ EPackage.Registry registry = fixture.getResourceSet().getPackageRegistry();
+
+ // Replace all registrations of the UML package
+ for (Map.Entry<String, Object> next : registry.entrySet()) {
+ if (next.getValue() instanceof UMLPackage) {
+ next.setValue(ePackage[0]);
+ }
+ }
+
+ // Just to make sure
+ registry.put(ePackage[0].getNsURI(), ePackage[0]);
+ }
+
+ void recordInvocation(String methodName) {
+ invocations.add(methodName);
+ }
+}
diff --git a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/tests/AllTests.java b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/tests/AllTests.java
index 19729d7cdc0..e5a16370b03 100644
--- a/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/tests/AllTests.java
+++ b/tests/junit/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common.tests/src/org/eclipse/papyrus/infra/gmfdiag/common/tests/AllTests.java
@@ -8,10 +8,11 @@
*
* Contributors:
* Christian W. Damus (CEA) - initial API and implementation
- * Christian W. Damus - bugs 465416, 474467
+ * Christian W. Damus - bugs 465416, 474467, 507618
*/
package org.eclipse.papyrus.infra.gmfdiag.common.tests;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.tests.CreateEditBasedElementCommandTest;
import org.eclipse.papyrus.infra.gmfdiag.common.providers.tests.NotationLabelProviderTest;
import org.eclipse.papyrus.infra.gmfdiag.common.sync.tests.SyncTests;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafeTest;
@@ -37,6 +38,7 @@ import org.junit.runners.Suite.SuiteClasses;
GMFUnsafeTest.class,
SyncTests.class,
NotationLabelProviderTest.class,
+ CreateEditBasedElementCommandTest.class,
})
public class AllTests {

Back to the top