diff options
author | Christian W. Damus | 2017-02-08 22:48:27 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2017-02-10 13:24:46 +0000 |
commit | abb87bf02f8c9757901218de8a87b85467d969a6 (patch) | |
tree | 72a550a196768e3ac658931009c4f77db0210ab1 /tests | |
parent | 2cbd9bda39f505f21db9ed6e4c0563599d55e474 (diff) | |
download | org.eclipse.papyrus-abb87bf02f8c9757901218de8a87b85467d969a6.tar.gz org.eclipse.papyrus-abb87bf02f8c9757901218de8a87b85467d969a6.tar.xz org.eclipse.papyrus-abb87bf02f8c9757901218de8a87b85467d969a6.zip |
Bug 511942: [Properties] Property widgets create new UML elements using the static factory
Ensure that the contextual resource set's local factory is used
to instantiate an EClass, if such local factory is available.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=511942
Change-Id: Ia56fc63632b8bd1afa0e67f3d778a41d9689a4c7
(🍒-picked from streams/2.0-maintenance)
Diffstat (limited to 'tests')
4 files changed, 100 insertions, 4 deletions
diff --git a/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/META-INF/MANIFEST.MF index ee95e4dd762..860d1c750e1 100644 --- a/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/META-INF/MANIFEST.MF @@ -3,11 +3,11 @@ Require-Bundle: org.junit;bundle-version="4.10.0", org.eclipse.papyrus.junit.framework;bundle-version="1.2.0", com.google.guava;bundle-version="11.0.0", org.eclipse.papyrus.junit.utils;bundle-version="2.0.0", - org.eclipse.papyrus.infra.properties.ui;bundle-version="1.2.1", + org.eclipse.papyrus.infra.properties.ui;bundle-version="2.0.0", org.eclipse.uml2.uml;bundle-version="5.2.0" Export-Package: org.eclipse.papyrus.infra.properties.ui.tests Bundle-Vendor: Eclipse Modeling Project -Bundle-Version: 1.2.1.qualifier +Bundle-Version: 2.0.0.qualifier Bundle-Name: Papyrus Properties UI Tests Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.papyrus.infra.properties.ui.tests;singleton:=true diff --git a/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/pom.xml b/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/pom.xml index e5ba074f348..28aaa790c67 100644 --- a/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/pom.xml +++ b/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/pom.xml @@ -10,6 +10,6 @@ </parent> <groupId>org.eclipse.papyrus.tests</groupId> <artifactId>org.eclipse.papyrus.infra.properties.ui.tests</artifactId> - <version>1.2.1-SNAPSHOT</version> + <version>2.0.0-SNAPSHOT</version> <packaging>eclipse-test-plugin</packaging> </project> diff --git a/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/src/org/eclipse/papyrus/infra/properties/ui/tests/AllTests.java b/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/src/org/eclipse/papyrus/infra/properties/ui/tests/AllTests.java index a7e1ab23c56..aa7fc7ed4fa 100644 --- a/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/src/org/eclipse/papyrus/infra/properties/ui/tests/AllTests.java +++ b/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/src/org/eclipse/papyrus/infra/properties/ui/tests/AllTests.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2016 Christian W. Damus and others. + * Copyright (c) 2016, 2017 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 @@ -24,6 +24,7 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(ClassificationSuite.class) @SuiteClasses({ PropertiesHeaderLabelProviderTest.class, + EcorePropertyEditorFactoryTest.class, }) public class AllTests { diff --git a/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/src/org/eclipse/papyrus/infra/properties/ui/tests/EcorePropertyEditorFactoryTest.java b/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/src/org/eclipse/papyrus/infra/properties/ui/tests/EcorePropertyEditorFactoryTest.java new file mode 100644 index 00000000000..8ceaed09997 --- /dev/null +++ b/tests/junit/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui.tests/src/org/eclipse/papyrus/infra/properties/ui/tests/EcorePropertyEditorFactoryTest.java @@ -0,0 +1,95 @@ +/***************************************************************************** + * Copyright (c) 2017 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.properties.ui.tests; + +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.MatcherAssert.assertThat; + +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EFactory; +import org.eclipse.emf.ecore.impl.EPackageRegistryImpl; +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.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.infra.properties.ui.creation.EcorePropertyEditorFactory; +import org.eclipse.swt.widgets.Control; +import org.eclipse.uml2.uml.UMLFactory; +import org.eclipse.uml2.uml.UMLPackage; +import org.junit.Test; + +/** + * Regression test cases for the {@link EcorePropertyEditorFactory} class. + */ +public class EcorePropertyEditorFactoryTest { + + public EcorePropertyEditorFactoryTest() { + super(); + } + + @SuppressWarnings("serial") + @Test + public void createWithLocalFactory() { + EcorePropertyEditorFactory editorFactory = new EcorePropertyEditorFactory(UMLPackage.Literals.NAMESPACE__OWNED_RULE) { + @Override + protected EClass chooseEClass(Control widget) { + // Force the choice + return UMLPackage.Literals.CONSTRAINT; + } + + @Override + protected Object createObject(Control widget, Object context, Object source) { + // Don't show a dialog + return source; + } + }; + + ResourceSet rset = new ResourceSetImpl(); + try { + Resource resource = rset.createResource(URI.createURI("bogus://test.uml")); + org.eclipse.uml2.uml.Package package_ = UMLFactory.eINSTANCE.createPackage(); + resource.getContents().add(package_); + + List<EClass> created = new ArrayList<>(); + + EFactory custom = (EFactory) Proxy.newProxyInstance(UMLPackage.class.getClassLoader(), new Class<?>[] { EFactory.class }, + (proxy, method, args) -> { + switch (method.getName()) { + case "create": + EClass eClass = (EClass) args[0]; + created.add(eClass); + return UMLFactory.eINSTANCE.create(eClass); + default: + return method.invoke(UMLFactory.eINSTANCE, args); + } + }); + rset.setPackageRegistry(new EPackageRegistryImpl(rset.getPackageRegistry()) { + @Override + protected EFactory delegatedGetEFactory(String nsURI) { + return UMLPackage.eNS_URI.equals(nsURI) ? custom : super.delegatedGetEFactory(nsURI); + } + }); + editorFactory.createObject(null, package_); + + assertThat("Custom factory not invoked", created, hasItem(UMLPackage.Literals.CONSTRAINT)); + } finally { + EMFHelper.unload(rset); + } + } +} |