Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian W. Damus2015-01-28 23:28:27 +0000
committerChristian W. Damus2015-01-29 20:54:17 +0000
commit0e184d2e01f20e7e38518978e3861b6ac80e8f69 (patch)
treed322c5b1227f6b86990b1b4c9db89f7d3ae1a595 /tests
parentae909d159bc6d4db71583fd91664cc23b2b9300d (diff)
downloadorg.eclipse.papyrus-0e184d2e01f20e7e38518978e3861b6ac80e8f69.tar.gz
org.eclipse.papyrus-0e184d2e01f20e7e38518978e3861b6ac80e8f69.tar.xz
org.eclipse.papyrus-0e184d2e01f20e7e38518978e3861b6ac80e8f69.zip
458197: [Profile Applications] Customized DSML palettes not enabled in UI when loading Profile Applications
https://bugs.eclipse.org/bugs/show_bug.cgi?id=458197 Implement a new Profile Application Listener exactly analogous to the StereotypeElementListener (and, in fact, installed by the same service) that notifies interested parties when profiles are applied to and unapplied from packages in the UML model. As for stereotype applications in which there is no real feature on which to make the notifications, the custom notifications injected by the ProfileApplicationListener are dispatched via the affected Package and reference an applied or unapplied Profile. Includes a new test suite for the ProfileApplicationListener (same test scenarios as the previous patch) in the existing test plug-in for oep.uml.tools, alongside the StereotypeElementListener tests. Change-Id: I1ac73c7fc4aa8b5cec6c0c6abe4be243ba06e9f3
Diffstat (limited to 'tests')
-rw-r--r--tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/.classpath14
-rw-r--r--tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/.settings/org.eclipse.jdt.core.prefs6
-rw-r--r--tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/META-INF/MANIFEST.MF5
-rw-r--r--tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/profile_application_listener/model.di2
-rw-r--r--tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/profile_application_listener/model.notation37
-rw-r--r--tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/profile_application_listener/model.uml29
-rw-r--r--tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/AllTests.java5
-rw-r--r--tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/ProfileApplicationListenerTest.java282
8 files changed, 366 insertions, 14 deletions
diff --git a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/.classpath b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/.classpath
index 2d1a4302f04..ad32c83a788 100644
--- a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/.classpath
+++ b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/.classpath
@@ -1,7 +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>
+<?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/JavaSE-1.6"/>
+ <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/uml/tools/org.eclipse.papyrus.uml.tools.tests/.settings/org.eclipse.jdt.core.prefs b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/.settings/org.eclipse.jdt.core.prefs
index 4759947300a..410244d65a6 100644
--- a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/.settings/org.eclipse.jdt.core.prefs
+++ b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/.settings/org.eclipse.jdt.core.prefs
@@ -1,10 +1,10 @@
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.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
diff --git a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/META-INF/MANIFEST.MF
index 8bc104a61bb..ba099ea54eb 100644
--- a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/META-INF/MANIFEST.MF
@@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.1.0",
org.eclipse.papyrus.uml.extensionpoints;bundle-version="1.1.0",
org.eclipse.papyrus.junit.utils;bundle-version="1.1.0",
- org.eclipse.papyrus.sysml;bundle-version="1.1.0"
+ org.eclipse.papyrus.sysml;bundle-version="1.1.0",
+ com.google.guava;bundle-version="11.0.0"
Export-Package: org.eclipse.papyrus.uml.tools.tests,
org.eclipse.papyrus.uml.tools.tests.tests
Bundle-Vendor: Eclipse Modeling Project
@@ -25,6 +26,6 @@ Bundle-ManifestVersion: 2
Bundle-Activator: org.eclipse.papyrus.uml.tools.tests.Activator
Bundle-SymbolicName: org.eclipse.papyrus.uml.tools.tests;singleton:=tr
ue
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/profile_application_listener/model.di b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/profile_application_listener/model.di
new file mode 100644
index 00000000000..bf9abab340f
--- /dev/null
+++ b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/profile_application_listener/model.di
@@ -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/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/profile_application_listener/model.notation b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/profile_application_listener/model.notation
new file mode 100644
index 00000000000..c985337e936
--- /dev/null
+++ b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/profile_application_listener/model.notation
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<notation:Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:configuration="http://www.eclipse.org/papyrus/infra/viewpoints/configuration" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:style="http://www.eclipse.org/papyrus/infra/viewpoints/policy/style" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_kUz00KaiEeSMDtdtp4w6Xg" type="PapyrusUMLClassDiagram" name="packages" measurementUnit="Pixel">
+ <children xmi:type="notation:Shape" xmi:id="_lcRzMKaiEeSMDtdtp4w6Xg" type="2007">
+ <children xmi:type="notation:DecorationNode" xmi:id="_lcWrsKaiEeSMDtdtp4w6Xg" type="5026"/>
+ <children xmi:type="notation:DecorationNode" xmi:id="_lcX50KaiEeSMDtdtp4w6Xg" type="7016">
+ <styles xmi:type="notation:TitleStyle" xmi:id="_lcX50aaiEeSMDtdtp4w6Xg"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_lcX50qaiEeSMDtdtp4w6Xg"/>
+ </children>
+ <element xmi:type="uml:Package" href="model.uml#_lbrWQKaiEeSMDtdtp4w6Xg"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_lcRzMaaiEeSMDtdtp4w6Xg" x="123" y="127"/>
+ </children>
+ <children xmi:type="notation:Shape" xmi:id="_mu7G0KaiEeSMDtdtp4w6Xg" type="2007">
+ <children xmi:type="notation:DecorationNode" xmi:id="_mu7G0qaiEeSMDtdtp4w6Xg" type="5026"/>
+ <children xmi:type="notation:DecorationNode" xmi:id="_mu7G06aiEeSMDtdtp4w6Xg" type="7016">
+ <styles xmi:type="notation:TitleStyle" xmi:id="_mu7G1KaiEeSMDtdtp4w6Xg"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_mu7G1aaiEeSMDtdtp4w6Xg"/>
+ </children>
+ <element xmi:type="uml:Package" href="model.uml#_mu5RoKaiEeSMDtdtp4w6Xg"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_mu7G0aaiEeSMDtdtp4w6Xg" x="424" y="128"/>
+ </children>
+ <children xmi:type="notation:Shape" xmi:id="_ngyooKaiEeSMDtdtp4w6Xg" type="2007">
+ <children xmi:type="notation:DecorationNode" xmi:id="_ngyooqaiEeSMDtdtp4w6Xg" type="5026"/>
+ <children xmi:type="notation:DecorationNode" xmi:id="_ngzPsKaiEeSMDtdtp4w6Xg" type="7016">
+ <styles xmi:type="notation:TitleStyle" xmi:id="_ngzPsaaiEeSMDtdtp4w6Xg"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_ngzPsqaiEeSMDtdtp4w6Xg"/>
+ </children>
+ <element xmi:type="uml:Package" href="model.uml#_ngxagKaiEeSMDtdtp4w6Xg"/>
+ <layoutConstraint xmi:type="notation:Bounds" xmi:id="_ngyooaaiEeSMDtdtp4w6Xg" x="265" y="380"/>
+ </children>
+ <styles xmi:type="notation:StringValueStyle" xmi:id="_kUz00aaiEeSMDtdtp4w6Xg" name="diagram_compatibility_version" stringValue="1.0.0"/>
+ <styles xmi:type="notation:DiagramStyle" xmi:id="_kUz00qaiEeSMDtdtp4w6Xg"/>
+ <styles xmi:type="style:PapyrusViewStyle" xmi:id="_kUz006aiEeSMDtdtp4w6Xg">
+ <owner xmi:type="uml:Model" href="model.uml#_kQFs4KaiEeSMDtdtp4w6Xg"/>
+ <configuration xmi:type="configuration:PapyrusDiagram" href="platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/builtin/default.configuration#_7wLmpNxhEeOqHvRyiN87hA"/>
+ </styles>
+ <element xmi:type="uml:Model" href="model.uml#_kQFs4KaiEeSMDtdtp4w6Xg"/>
+</notation:Diagram>
diff --git a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/profile_application_listener/model.uml b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/profile_application_listener/model.uml
new file mode 100644
index 00000000000..1e136aea7cf
--- /dev/null
+++ b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/resources/profile_application_listener/model.uml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_kQFs4KaiEeSMDtdtp4w6Xg" name="Model">
+ <packageImport xmi:type="uml:PackageImport" xmi:id="_kQFs4aaiEeSMDtdtp4w6Xg">
+ <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
+ </packageImport>
+ <packagedElement xmi:type="uml:Package" xmi:id="_lbrWQKaiEeSMDtdtp4w6Xg" name="OneProfile">
+ <profileApplication xmi:type="uml:ProfileApplication" xmi:id="_r5ZAkKaiEeSMDtdtp4w6Xg">
+ <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_r5u-0KaiEeSMDtdtp4w6Xg" source="http://www.eclipse.org/uml2/2.0.0/UML">
+ <references xmi:type="ecore:EPackage" href="http://www.eclipse.org/uml2/5.0.0/UML/Profile/Standard#/"/>
+ </eAnnotations>
+ <appliedProfile xmi:type="uml:Profile" href="pathmap://UML_PROFILES/Standard.profile.uml#_0"/>
+ </profileApplication>
+ </packagedElement>
+ <packagedElement xmi:type="uml:Package" xmi:id="_mu5RoKaiEeSMDtdtp4w6Xg" name="TwoProfiles">
+ <profileApplication xmi:type="uml:ProfileApplication" xmi:id="_vSwwIKaiEeSMDtdtp4w6Xg">
+ <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_vTDrEKaiEeSMDtdtp4w6Xg" source="http://www.eclipse.org/uml2/2.0.0/UML">
+ <references xmi:type="ecore:EPackage" href="pathmap://UML_PROFILES/Ecore.profile.uml#_z1OFcHjqEdy8S4Cr8Rc_NA"/>
+ </eAnnotations>
+ <appliedProfile xmi:type="uml:Profile" href="pathmap://UML_PROFILES/Ecore.profile.uml#_0"/>
+ </profileApplication>
+ <profileApplication xmi:type="uml:ProfileApplication" xmi:id="_vTESIKaiEeSMDtdtp4w6Xg">
+ <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_vTX0IKaiEeSMDtdtp4w6Xg" source="http://www.eclipse.org/uml2/2.0.0/UML">
+ <references xmi:type="ecore:EPackage" href="http://www.eclipse.org/uml2/5.0.0/UML/Profile/Standard#/"/>
+ </eAnnotations>
+ <appliedProfile xmi:type="uml:Profile" href="pathmap://UML_PROFILES/Standard.profile.uml#_0"/>
+ </profileApplication>
+ </packagedElement>
+ <packagedElement xmi:type="uml:Package" xmi:id="_ngxagKaiEeSMDtdtp4w6Xg" name="NoProfile"/>
+</uml:Model>
diff --git a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/AllTests.java b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/AllTests.java
index 0902cb96264..3e1d24dc50a 100644
--- a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/AllTests.java
+++ b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/AllTests.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2012, 2014 CEA LIST and others.
+ * Copyright (c) 2012, 2015 CEA LIST, 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
@@ -9,6 +9,7 @@
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 440108
+ * Christian W. Damus - bug 458197
*
*****************************************************************************/
package org.eclipse.papyrus.uml.tools.tests.tests;
@@ -20,7 +21,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ ContentProviderTest.class, UMLStereotypePropertyContentProviderTest.class, DependencyManagementTest.class,
- NamedElementValidatorTest.class, StereotypeElementListenerTest.class
+ NamedElementValidatorTest.class, StereotypeElementListenerTest.class, ProfileApplicationListenerTest.class
})
public class AllTests {
diff --git a/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/ProfileApplicationListenerTest.java b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/ProfileApplicationListenerTest.java
new file mode 100644
index 00000000000..d0d751d8e47
--- /dev/null
+++ b/tests/junit/plugins/uml/tools/org.eclipse.papyrus.uml.tools.tests/src/org/eclipse/papyrus/uml/tools/tests/tests/ProfileApplicationListenerTest.java
@@ -0,0 +1,282 @@
+/*****************************************************************************
+ * Copyright (c) 2015 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.uml.tools.tests.tests;
+
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Method;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.transaction.NotificationFilter;
+import org.eclipse.emf.transaction.ResourceSetChangeEvent;
+import org.eclipse.emf.transaction.ResourceSetListenerImpl;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.utils.TransactionHelper;
+import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
+import org.eclipse.papyrus.junit.utils.rules.HouseKeeper;
+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.tools.listeners.ProfileApplicationListener;
+import org.eclipse.uml2.common.util.UML2Util;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.ProfileApplication;
+import org.eclipse.uml2.uml.UMLPackage;
+import org.eclipse.uml2.uml.resource.UMLResource;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Multimap;
+
+/**
+ * Tests the service-registered {@link ProfileApplicationListener}.
+ */
+@PluginResource("resources/profile_application_listener/model.di")
+public class ProfileApplicationListenerTest extends AbstractPapyrusTest {
+
+ @Rule
+ public final HouseKeeper houseKeeper = new HouseKeeper();
+
+ @Rule
+ public final ModelSetFixture modelSet = new ServiceRegistryModelSetFixture();
+
+ private ListenerFixture fixture = new ListenerFixture();
+
+ private boolean _transactionLatch;
+
+ private Profile ecoreProfile;
+
+ private Profile standardProfile;
+
+ private Package noProfile;
+
+ private Package oneProfile;
+
+ private Package twoProfiles;
+
+ public ProfileApplicationListenerTest() {
+ super();
+ }
+
+ @Test
+ public void simpleNewProfileApplication() {
+ if (inTransaction()) {
+ noProfile.applyProfile(standardProfile);
+ } else {
+ fixture.assertApplied(noProfile, standardProfile);
+ }
+ }
+
+ @Test
+ public void simpleProfileUnapplication() {
+ if (inTransaction()) {
+ oneProfile.unapplyProfile(standardProfile);
+ } else {
+ fixture.assertUnapplied(oneProfile, standardProfile);
+ }
+ }
+
+ @Test
+ public void twoProfilesApplied() {
+ if (inTransaction()) {
+ noProfile.applyProfile(standardProfile);
+ noProfile.applyProfile(ecoreProfile);
+ } else {
+ fixture.assertApplied(noProfile, standardProfile);
+ fixture.assertApplied(noProfile, ecoreProfile);
+ }
+ }
+
+ @Test
+ public void twoProfilesUnapplied() {
+ if (inTransaction()) {
+ // Unapply them by different means
+ twoProfiles.unapplyProfile(standardProfile);
+ twoProfiles.getProfileApplication(ecoreProfile).eUnset(UMLPackage.Literals.PROFILE_APPLICATION__APPLIED_PROFILE);
+ } else {
+ fixture.assertUnapplied(twoProfiles, standardProfile);
+ fixture.assertUnapplied(twoProfiles, ecoreProfile);
+ }
+ }
+
+ @Test
+ public void profileReplacedInAnApplication() {
+ if (inTransaction()) {
+ ProfileApplication application = oneProfile.getProfileApplication(standardProfile);
+ application.setAppliedProfile(ecoreProfile);
+ } else {
+ // The net effect is that the Ecore profile was applied
+ fixture.assertApplied(oneProfile, ecoreProfile);
+
+ // And the Standard profile was unapplied
+ fixture.assertUnapplied(oneProfile, standardProfile);
+ }
+ }
+
+ @Test
+ public void profileAppliedThenReplacedInSameApplication() {
+ if (inTransaction()) {
+ noProfile.applyProfile(standardProfile);
+ ProfileApplication application = noProfile.getProfileApplication(standardProfile);
+ application.setAppliedProfile(ecoreProfile);
+ } else {
+ // The net effect is that the Ecore profile was applied
+ fixture.assertApplied(noProfile, ecoreProfile);
+
+ // The Standard profile was not applied and then unapplied
+ fixture.assertNotApplied(noProfile, standardProfile);
+ fixture.assertNotUnapplied(noProfile, standardProfile);
+ }
+ }
+
+ @Test
+ public void moveProfileApplication() {
+ if (inTransaction()) {
+ ProfileApplication application = oneProfile.getProfileApplication(standardProfile);
+ noProfile.getProfileApplications().add(application);
+ } else {
+ // The net effect is that the Standard profile was unapplied from the one package
+ fixture.assertUnapplied(oneProfile, standardProfile);
+
+ // and applied to the other
+ fixture.assertApplied(noProfile, standardProfile);
+ }
+ }
+
+ @Test
+ public void applyProfileThenMoveApplication() {
+ if (inTransaction()) {
+ noProfile.applyProfile(ecoreProfile);
+ ProfileApplication application = noProfile.getProfileApplication(ecoreProfile);
+ oneProfile.getProfileApplications().add(application);
+ } else {
+ // The net effect is that the Ecore profile was unapplied to the one package
+ fixture.assertApplied(oneProfile, ecoreProfile);
+
+ // and not applied to nor unapplied from the other
+ fixture.assertNotApplied(noProfile, ecoreProfile);
+ fixture.assertNotUnapplied(noProfile, ecoreProfile);
+ }
+ }
+
+ //
+ // Test framework
+ //
+
+ @Before
+ public void setup() throws ServiceException {
+ ecoreProfile = UML2Util.load(modelSet.getResourceSet(), URI.createURI(UMLResource.ECORE_PROFILE_URI), UMLPackage.Literals.PROFILE);
+ standardProfile = UML2Util.load(modelSet.getResourceSet(), URI.createURI(UMLResource.STANDARD_PROFILE_URI), UMLPackage.Literals.PROFILE);
+
+ oneProfile = modelSet.getModel().getNestedPackage("OneProfile"); //$NON-NLS-1$
+ twoProfiles = modelSet.getModel().getNestedPackage("TwoProfiles"); //$NON-NLS-1$
+ noProfile = modelSet.getModel().getNestedPackage("NoProfile"); //$NON-NLS-1$
+
+ modelSet.getEditingDomain().addResourceSetListener(fixture);
+ fixture.clear();
+ }
+
+ private boolean inTransaction() {
+ boolean result = _transactionLatch;
+
+ if (!result) {
+ _transactionLatch = true;
+ try {
+ final Method method = getClass().getMethod(houseKeeper.getTestName());
+ TransactionHelper.run(modelSet.getEditingDomain(), new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ method.invoke(ProfileApplicationListenerTest.this);
+ } catch (Exception e) {
+ throw new Error("Failed to reflectively invoke test within transaction", e); //$NON-NLS-1$
+ }
+ }
+ });
+ } catch (Exception e) {
+ throw new Error("Failed to reflectively invoke test within transaction", e); //$NON-NLS-1$
+ } finally {
+ _transactionLatch = false;
+ }
+ }
+
+ return result;
+ }
+
+ private static class ListenerFixture extends ResourceSetListenerImpl {
+ private Multimap<Package, Profile> applications = LinkedHashMultimap.create();
+ private Multimap<Package, Profile> unapplications = LinkedHashMultimap.create();
+
+ ListenerFixture() {
+ super(new NotificationFilter.Custom() {
+ @Override
+ public boolean matches(Notification notification) {
+ return notification instanceof ProfileApplicationListener.ProfileApplicationNotification;
+ }
+ });
+ }
+
+ @Override
+ public boolean isPostcommitOnly() {
+ return true;
+ }
+
+ @Override
+ public void resourceSetChanged(ResourceSetChangeEvent event) {
+ for (ProfileApplicationListener.ProfileApplicationNotification next : Iterables.filter(event.getNotifications(), ProfileApplicationListener.ProfileApplicationNotification.class)) {
+ switch (next.getEventType()) {
+ case ProfileApplicationListener.ProfileApplicationNotification.PROFILE_APPLIED:
+ applications.put(next.getNotifyingPackage(), next.getAppliedProfile());
+ break;
+ case ProfileApplicationListener.ProfileApplicationNotification.PROFILE_UNAPPLIED:
+ unapplications.put(next.getNotifyingPackage(), next.getUnappliedProfile());
+ break;
+ default:
+ fail("Odd sort of a notification to have received: " + next.getEventType());
+ break; // Unreachable
+ }
+ }
+ }
+
+ void clear() {
+ applications.clear();
+ unapplications.clear();
+ }
+
+ void assertApplied(Package package_, Profile profile) {
+ assertThat(applications.get(package_), hasItem(profile));
+ }
+
+ void assertUnapplied(Package package_, Profile profile) {
+ assertThat(unapplications.get(package_), hasItem(profile));
+ }
+
+ void assertNotApplied(Package package_, Profile profile) {
+ assertThat(applications.get(package_), not(hasItem(profile)));
+ }
+
+ void assertNotUnapplied(Package package_, Profile profile) {
+ assertThat(unapplications.get(package_), not(hasItem(profile)));
+ }
+ }
+}

Back to the top