Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristian W. Damus2015-10-20 19:29:38 +0000
committerChristian W. Damus2015-10-20 19:42:16 +0000
commitae2c68880f709564816906155158b226878bf01d (patch)
treed4e0fd9301a1b84d68220fcf07b8845d1bfba927 /tests
parentacf25ad9cf01b32f7b7a0db61e315f2b9057f7e6 (diff)
downloadorg.eclipse.papyrus-ae2c68880f709564816906155158b226878bf01d.tar.gz
org.eclipse.papyrus-ae2c68880f709564816906155158b226878bf01d.tar.xz
org.eclipse.papyrus-ae2c68880f709564816906155158b226878bf01d.zip
Bug 480221: [Filters] NPE in the ProfileAppliedFilter when using URIs
https://bugs.eclipse.org/bugs/show_bug.cgi?id=480221 Update the ProfileApplied filter's match algorithm to avoid pointless loading of profiles that aren't the profiles matched by the filter. This is verified by a new regression test. This change also exposes errors in tests defined earlier: * the core ProfileApplied::match test changed the filter's URI to make the referenced profile unresolvable. However, the correct test is to make the mode's actual applied profile unresolvable but still match the URI expected by the filter * a test model in the Diagram Assistants tests had a ProfileApplied filter that was misspecified: it did not use the correct URI in referencing the expected profile Change-Id: If197a1023e9c9ce965f6f48759f76f878211b9cc
Diffstat (limited to 'tests')
-rw-r--r--tests/junit/plugins/infra/gmfdiag/assistant/org.eclipse.papyrus.infra.gmfdiag.assistant.tests/org.eclipse.papyrus.infra.gmfdiag.assistant.tests.launch2
-rw-r--r--tests/junit/plugins/infra/gmfdiag/assistant/org.eclipse.papyrus.infra.gmfdiag.assistant.tests/resources/j2ee-usecase.assistants2
-rw-r--r--tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/StandaloneResourceSetFixture.java179
-rw-r--r--tests/junit/plugins/suites/org.eclipse.papyrus.tests.diagramassistants/Papyrus Diagram Assistants tests.launch2
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/META-INF/MANIFEST.MF3
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/org.eclipse.papyrus.uml.filters.tests.launch5
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src-gen/org/eclipse/papyrus/uml/filters/tests/ProfileAppliedTest.java20
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/AllTests.java5
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/ProfileAppliedRegressionTest.java109
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/bug480221.profile.uml28
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/bug480221.uml21
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/my.profile.uml28
12 files changed, 390 insertions, 14 deletions
diff --git a/tests/junit/plugins/infra/gmfdiag/assistant/org.eclipse.papyrus.infra.gmfdiag.assistant.tests/org.eclipse.papyrus.infra.gmfdiag.assistant.tests.launch b/tests/junit/plugins/infra/gmfdiag/assistant/org.eclipse.papyrus.infra.gmfdiag.assistant.tests/org.eclipse.papyrus.infra.gmfdiag.assistant.tests.launch
index dc6a17a4c71..2a71b1833b8 100644
--- a/tests/junit/plugins/infra/gmfdiag/assistant/org.eclipse.papyrus.infra.gmfdiag.assistant.tests/org.eclipse.papyrus.infra.gmfdiag.assistant.tests.launch
+++ b/tests/junit/plugins/infra/gmfdiag/assistant/org.eclipse.papyrus.infra.gmfdiag.assistant.tests/org.eclipse.papyrus.infra.gmfdiag.assistant.tests.launch
@@ -24,7 +24,7 @@
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
-<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.papyrus.infra.gmfdiag.assistant.tests.AllTests"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.papyrus.infra.gmfdiag.assistant.tests"/>
diff --git a/tests/junit/plugins/infra/gmfdiag/assistant/org.eclipse.papyrus.infra.gmfdiag.assistant.tests/resources/j2ee-usecase.assistants b/tests/junit/plugins/infra/gmfdiag/assistant/org.eclipse.papyrus.infra.gmfdiag.assistant.tests/resources/j2ee-usecase.assistants
index ac81b0d7075..a605fb70a24 100644
--- a/tests/junit/plugins/infra/gmfdiag/assistant/org.eclipse.papyrus.infra.gmfdiag.assistant.tests/resources/j2ee-usecase.assistants
+++ b/tests/junit/plugins/infra/gmfdiag/assistant/org.eclipse.papyrus.infra.gmfdiag.assistant.tests/resources/j2ee-usecase.assistants
@@ -22,7 +22,7 @@
<ownedFilter xsi:type="assistant:ElementTypeFilter" name="Constraint Constrained Element" elementTypeID="org.eclipse.papyrus.uml.diagram.usecase.ConstraintConstrainedElement_4012"/>
<ownedFilter xsi:type="assistant:ElementTypeFilter" name="Package" elementTypeID="org.eclipse.papyrus.uml.diagram.usecase.Package_1000"/>
<ownedFilter xsi:type="filters:CompoundFilter" name="pertains to Profile j2ee" filter="//@ownedFilter.21/@ownedFilter.0 //@ownedFilter.21/@ownedFilter.1" operator="or">
- <ownedFilter xsi:type="umlfilters:ProfileApplied" name="j2ee is applied in context" profileQualifiedName="j2ee" profileURI="platform:/resource/Assistants/j2ee.profile.uml#_raLqoEigEeSRp-p9nf2EsA"/>
+ <ownedFilter xsi:type="umlfilters:ProfileApplied" name="j2ee is applied in context" profileQualifiedName="j2ee" profileURI="platform:/plugin/org.eclipse.papyrus.infra.gmfdiag.assistant.tests/resources/j2ee.profile.uml#_raLqoEigEeSRp-p9nf2EsA"/>
<ownedFilter xsi:type="assistant:AssistedElementTypeFilter"/>
</ownedFilter>
<ownedFilter xsi:type="assistant:ElementTypeFilter" name="Association" elementTypeID="org.eclipse.papyrus.uml.diagram.usecase.Association_4011"/>
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/StandaloneResourceSetFixture.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/StandaloneResourceSetFixture.java
new file mode 100644
index 00000000000..2bc1745a2df
--- /dev/null
+++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/StandaloneResourceSetFixture.java
@@ -0,0 +1,179 @@
+/*****************************************************************************
+ * 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.junit.utils.rules;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import java.net.URL;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.plugin.EcorePlugin;
+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.junit.utils.JUnitUtils;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+import com.google.common.collect.Iterables;
+
+/**
+ * A {@link ResourceSet} fixture rule that is compatible with stand-alone JUnit
+ * execution (not in an Eclipse instance). It uses the {@link JavaResource}
+ * annotation (only, not also {@link PluginResource}) to identify test resources
+ * to load into the resource set on set-up.
+ *
+ * @param <T>
+ * the kind of model fixture element to load
+ */
+public class StandaloneResourceSetFixture<T extends EObject> extends TestWatcher {
+
+ private final Class<? extends T> modelType;
+
+ private ResourceSet resourceSet;
+ private Resource resource;
+ private T model;
+
+ /**
+ * Initializes me with the kind of model fixture element to load.
+ *
+ * @param modelType
+ * the model fixture element's type
+ */
+ public StandaloneResourceSetFixture(Class<? extends T> modelType) {
+ super();
+
+ this.modelType = modelType;
+ }
+
+ /**
+ * Obtains the resource set in which the {@linkplain #getModel() model fixture} is loaded.
+ *
+ * @see #getModel()
+ */
+ public ResourceSet getResourceSet() {
+ return resourceSet;
+ }
+
+ /**
+ * Obtains the resource containing the {@linkplain #getModel() model fixture}.
+ *
+ * @see #getModel()
+ */
+ public Resource getResource() {
+ return resource;
+ }
+
+ public Resource getResource(URI uri, boolean loadOnDemand) {
+ return getResourceSet().getResource(uri, loadOnDemand);
+ }
+
+ /**
+ * Obtains the model fixture.
+ */
+ public T getModel() {
+ return model;
+ }
+
+ /**
+ * Obtains the root model element of the specified type from my resource set.
+ *
+ * @param modelType
+ * the type of model to retrieve, or {@code null} if none is found
+ */
+ public <E extends EObject> E getModel(Class<E> modelType) {
+ E result = null;
+
+ Resource resource;
+ for (Iterator<Resource> iter = resourceSet.getResources().iterator(); (result == null) && iter.hasNext();) {
+ resource = iter.next();
+ result = Iterables.getFirst(Iterables.filter(resource.getContents(), modelType), null);
+ }
+
+ return result;
+ }
+
+ public static <T extends EObject> StandaloneResourceSetFixture<T> create(Class<T> modelType) {
+ return new StandaloneResourceSetFixture<>(modelType);
+ }
+
+ @Override
+ protected void starting(Description description) {
+ JavaResource annotation = JUnitUtils.getAnnotation(description, JavaResource.class);
+ assertThat("No @JavaResource annotation found in test case.", annotation, notNullValue());
+
+ resourceSet = new ResourceSetImpl();
+
+ if (!EcorePlugin.IS_ECLIPSE_RUNNING) {
+ // EMF ensures that additional invocations have no effect
+ EcorePlugin.ExtensionProcessor.process(null);
+ }
+
+ final Class<?> testClass = JUnitUtils.getTestClass(description);
+ for (String next : annotation.value()) {
+ resourceSet.getResource(getTestResourceURI(next, testClass), true);
+ }
+
+ model = getModel(modelType);
+
+ assertThat("No model of type " + modelType.getSimpleName() + " loaded.", model, notNullValue());
+ resource = model.eResource();
+ }
+
+ @Override
+ protected void finished(Description description) {
+ for (Iterator<Resource> iter = resourceSet.getResources().iterator(); iter.hasNext();) {
+ Resource next = iter.next();
+
+ next.unload();
+ iter.remove();
+
+ next.eAdapters().clear();
+ }
+
+ resourceSet.eAdapters().clear();
+ resourceSet = null;
+ resource = null;
+ model = null;
+ }
+
+ /**
+ * Obtains the URI of a test resource.
+ *
+ * @param path
+ * the path of the test resource. Absolute paths are searched on the classpath
+ * and relative paths are searched relative to the given {@code context} class
+ * @param context
+ * the context class for resolution of relative resource paths
+ *
+ * @return the URI of the referenced test resource
+ */
+ protected URI getTestResourceURI(String path, Class<?> context) {
+ URL resultURL;
+
+ IPath resourcePath = new Path(path);
+ if (resourcePath.isAbsolute()) {
+ resultURL = context.getClassLoader().getResource(path);
+ } else {
+ resultURL = context.getResource(path);
+ }
+
+ return URI.createURI(resultURL.toString(), true);
+ }
+}
diff --git a/tests/junit/plugins/suites/org.eclipse.papyrus.tests.diagramassistants/Papyrus Diagram Assistants tests.launch b/tests/junit/plugins/suites/org.eclipse.papyrus.tests.diagramassistants/Papyrus Diagram Assistants tests.launch
index ae12df13327..d3d9b3eb4e0 100644
--- a/tests/junit/plugins/suites/org.eclipse.papyrus.tests.diagramassistants/Papyrus Diagram Assistants tests.launch
+++ b/tests/junit/plugins/suites/org.eclipse.papyrus.tests.diagramassistants/Papyrus Diagram Assistants tests.launch
@@ -43,7 +43,7 @@
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
-<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.papyrus.tests.diagramassistants.AllTests"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.papyrus.tests.diagramassistants"/>
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/META-INF/MANIFEST.MF
index 85f850cd953..52072999418 100644
--- a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/META-INF/MANIFEST.MF
@@ -7,7 +7,8 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.uml2.types;bundle-version="2.0.0";visibility:=reexport,
org.eclipse.uml2.uml;bundle-version="5.1.0";visibility:=reexport,
org.eclipse.emf.ecore.xmi;bundle-version="2.11.0";visibility:=reexport,
- org.junit;visibility:=reexport
+ org.junit;visibility:=reexport,
+ org.eclipse.papyrus.junit.utils;bundle-version="1.2.0"
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/org.eclipse.papyrus.uml.filters.tests.launch b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/org.eclipse.papyrus.uml.filters.tests.launch
index 0c6a9229e8f..ba68412a97b 100644
--- a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/org.eclipse.papyrus.uml.filters.tests.launch
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/org.eclipse.papyrus.uml.filters.tests.launch
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/UMLFiltersAllTests.java"/>
+<listEntry value="/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/AllTests.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
@@ -11,6 +11,7 @@
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
-<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.papyrus.uml.filters.tests.UMLFiltersAllTests"/>
+<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.papyrus.uml.filters.tests.AllTests"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.papyrus.uml.filters.tests"/>
</launchConfiguration>
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src-gen/org/eclipse/papyrus/uml/filters/tests/ProfileAppliedTest.java b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src-gen/org/eclipse/papyrus/uml/filters/tests/ProfileAppliedTest.java
index 2d4eaeed203..25e97a4e6b9 100644
--- a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src-gen/org/eclipse/papyrus/uml/filters/tests/ProfileAppliedTest.java
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src-gen/org/eclipse/papyrus/uml/filters/tests/ProfileAppliedTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2014 Christian W. Damus and others.
+ * Copyright (c) 2014, 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
@@ -16,8 +16,6 @@ import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assume.assumeThat;
-import junit.framework.TestCase;
-import junit.textui.TestRunner;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
@@ -35,6 +33,9 @@ import org.eclipse.uml2.uml.UMLFactory;
import org.eclipse.uml2.uml.UMLPackage;
import org.eclipse.uml2.uml.resource.UMLResource;
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+
/**
* <!-- begin-user-doc -->
* A test case for the model object '<em><b>Profile Applied</b></em>'.
@@ -146,7 +147,7 @@ public class ProfileAppliedTest extends TestCase {
// Dispose the resource set, making sure any CacheAdapters are purged
ResourceSet rset = fixture.eResource().getResourceSet();
- for(Resource next : rset.getResources()) {
+ for (Resource next : rset.getResources()) {
next.unload();
next.eAdapters().clear();
}
@@ -168,6 +169,7 @@ public class ProfileAppliedTest extends TestCase {
rset.getResources().add(modelResource);
Package model = UMLFactory.eINSTANCE.createPackage();
+ modelResource.getContents().add(model);
model.setName("model1");
Class foo = model.createOwnedClass("Foo", false);
@@ -181,9 +183,13 @@ public class ProfileAppliedTest extends TestCase {
// Profile is applied
assertThat(getFixture().matches(foo), is(true));
- getFixture().setProfileURI("bogus://profile1.uml#_0");
+ // Destroy the profile resource: makes the profile an unresolvable proxy
+ Resource profileResource = profile.eResource();
+ profileResource.unload();
+ profileResource.getResourceSet().getResources().remove(profileResource);
+ profileResource.eAdapters().clear();
- // Even if profile cannot be resolved, the qualified name is an inexact backup
+ // Even if profile cannot be resolved, the URIs are still known and can be compared
assertThat(getFixture().matches(foo), is(true));
}
@@ -206,4 +212,4 @@ public class ProfileAppliedTest extends TestCase {
assertThat(getFixture().resolveProfile(getFixture()), nullValue());
}
-} //ProfileAppliedTest
+} // ProfileAppliedTest
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/AllTests.java b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/AllTests.java
index a138c1f31d4..012f1173cf1 100644
--- a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/AllTests.java
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/AllTests.java
@@ -21,7 +21,10 @@ import org.junit.runners.Suite.SuiteClasses;
* The master test suite for the plug-in.
*/
@RunWith(Suite.class)
-@SuiteClasses(UMLFiltersAllTests.class)
+@SuiteClasses({
+ UMLFiltersAllTests.class,
+ ProfileAppliedRegressionTest.class,
+})
public class AllTests {
// Nothing required
}
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/ProfileAppliedRegressionTest.java b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/ProfileAppliedRegressionTest.java
new file mode 100644
index 00000000000..59720988014
--- /dev/null
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/ProfileAppliedRegressionTest.java
@@ -0,0 +1,109 @@
+/*****************************************************************************
+ * 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.filters.tests;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.fail;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.papyrus.junit.utils.rules.JavaResource;
+import org.eclipse.papyrus.junit.utils.rules.StandaloneResourceSetFixture;
+import org.eclipse.papyrus.uml.filters.ProfileApplied;
+import org.eclipse.papyrus.uml.filters.UMLFiltersFactory;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Profile;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Specific bug regression tests for the {@link ProfileApplied} filter.
+ */
+public class ProfileAppliedRegressionTest {
+
+ @Rule
+ public final StandaloneResourceSetFixture<Package> model = StandaloneResourceSetFixture.create(Package.class);
+
+ public ProfileAppliedRegressionTest() {
+ super();
+ }
+
+ /**
+ * Verify that a filter that doesn't match a package doesn't cause its profile
+ * to be loaded as a side-effect.
+ */
+ @JavaResource("bug480221.uml")
+ @Test
+ public void profileAppliedFilterDoesNotLoadProfiles_miss_bug480221() {
+ ProfileApplied filter = UMLFiltersFactory.eINSTANCE.createProfileApplied();
+ filter.setProfileQualifiedName("bug480221profile::nested::profile");
+
+ URI profileResourceURI = model.getResource().getURI().trimSegments(1).appendSegment("bug480221.profile.uml");
+ filter.setProfileURI(profileResourceURI.appendFragment("_0").toString());
+
+ // Verify that the filter does not load the profile that it references
+ Package nested = model.getModel().getNestedPackage("nested");
+ assertThat("Package reports as having profile applied", filter.matches(nested), is(false));
+ assertThat("Filter loaded the profile", model.getResource(profileResourceURI, false), nullValue());
+
+ // Unless you ask it to
+ Profile resolved = filter.resolveProfile(nested);
+ assertThat(resolved, notNullValue());
+ assertThat(resolved.eIsProxy(), is(false));
+ }
+
+ /**
+ * Control test for the case of a filter for a profile that is actually applied.
+ */
+ @JavaResource("bug480221.uml")
+ @Test
+ public void profileAppliedFilterDoesNotLoadProfiles_hit_bug480221() {
+ ProfileApplied filter = UMLFiltersFactory.eINSTANCE.createProfileApplied();
+ filter.setProfileQualifiedName("my::nested::myprofile");
+
+ URI profileResourceURI = model.getResource().getURI().trimSegments(1).appendSegment("my.profile.uml");
+ filter.setProfileURI(profileResourceURI.appendFragment("_0").toString());
+
+ // Verify that the filter does actually work for a profile that is applied
+ Package nested = model.getModel().getNestedPackage("nested");
+ assertThat("Package does not report as having profile applied", filter.matches(nested), is(true));
+ }
+
+ /**
+ * Test that a filter specifying a resource URI instead of an object URI in
+ * reference to the profile doesn't cause NPEs.
+ */
+ @JavaResource("bug480221.uml")
+ @Test
+ public void profileAppliedFilterResourceURI_bug480221() {
+ ProfileApplied filter = UMLFiltersFactory.eINSTANCE.createProfileApplied();
+ filter.setProfileQualifiedName("bug480221profile::nested::profile");
+
+ URI profileResourceURI = model.getResource().getURI().trimSegments(1).appendSegment("bug480221.profile.uml");
+ filter.setProfileURI(profileResourceURI.toString()); // No fragment
+
+ try {
+ // The filter does not load the profile that it references nor does it NPE
+ Package nested = model.getModel().getNestedPackage("nested");
+ assertThat("Package reports as having profile applied", filter.matches(nested), is(false));
+ assertThat("Filter loaded the profile", model.getResource(profileResourceURI, false), nullValue());
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail(e.getClass().getSimpleName() + " thrown: " + e.getMessage());
+ }
+ }
+
+}
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/bug480221.profile.uml b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/bug480221.profile.uml
new file mode 100644
index 00000000000..384ccdbad14
--- /dev/null
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/bug480221.profile.uml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Package 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="_6iFHkHdAEeWAjOWixlHAwg" name="bug480221profile" URI="http://www.eclipse.org/papyrus/2015/test/profileapplied">
+ <packagedElement xmi:type="uml:Package" xmi:id="_DParIHdBEeWAjOWixlHAwg" name="nested">
+ <packagedElement xmi:type="uml:Profile" xmi:id="_0" name="profile" URI="http://www.eclipse.org/papyrus/2015/test/profileapplied/profile" metaclassReference="_K5Vp4HdBEeWAjOWixlHAwg">
+ <eAnnotations xmi:id="_R_f0QHdBEeWAjOWixlHAwg" source="http://www.eclipse.org/uml2/2.0.0/UML">
+ <contents xmi:type="ecore:EPackage" xmi:id="_R_f0QXdBEeWAjOWixlHAwg" name="profile" nsURI="http://www.eclipse.org/papyrus/2015/test/profileapplied/profile" nsPrefix="profile">
+ <eClassifiers xmi:type="ecore:EClass" xmi:id="_R_f0QndBEeWAjOWixlHAwg" name="Context">
+ <eAnnotations xmi:id="_R_f0Q3dBEeWAjOWixlHAwg" source="http://www.eclipse.org/uml2/2.0.0/UML" references="_NLq44HdBEeWAjOWixlHAwg"/>
+ <eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_R_f0RHdBEeWAjOWixlHAwg" name="base_Classifier" ordered="false" lowerBound="1">
+ <eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Classifier"/>
+ </eStructuralFeatures>
+ </eClassifiers>
+ </contents>
+ </eAnnotations>
+ <elementImport xmi:id="_K5Vp4HdBEeWAjOWixlHAwg">
+ <importedElement xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Classifier"/>
+ </elementImport>
+ <packagedElement xmi:type="uml:Stereotype" xmi:id="_NLq44HdBEeWAjOWixlHAwg" name="Context">
+ <ownedAttribute xmi:id="_Qn0PoHdBEeWAjOWixlHAwg" name="base_Classifier" association="_QnzokHdBEeWAjOWixlHAwg">
+ <type xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Classifier"/>
+ </ownedAttribute>
+ </packagedElement>
+ <packagedElement xmi:type="uml:Extension" xmi:id="_QnzokHdBEeWAjOWixlHAwg" name="Classifier_Context" memberEnd="_QnzokXdBEeWAjOWixlHAwg _Qn0PoHdBEeWAjOWixlHAwg">
+ <ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_QnzokXdBEeWAjOWixlHAwg" name="extension_Context" type="_NLq44HdBEeWAjOWixlHAwg" aggregation="composite" association="_QnzokHdBEeWAjOWixlHAwg"/>
+ </packagedElement>
+ </packagedElement>
+ </packagedElement>
+</uml:Package>
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/bug480221.uml b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/bug480221.uml
new file mode 100644
index 00000000000..71195692937
--- /dev/null
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/bug480221.uml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:myprofile="http://www.eclipse.org/papyrus/2015/test/profileapplied/myprofile" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xsi:schemaLocation="http://www.eclipse.org/papyrus/2015/test/profileapplied/myprofile my.profile.uml#_arTRUXdCEeWAjOWixlHAwg">
+ <uml:Package xmi:id="_EBhoEHdCEeWAjOWixlHAwg" name="bug480221">
+ <packagedElement xmi:type="uml:Package" xmi:id="_JMsFYHdCEeWAjOWixlHAwg" name="nested">
+ <packagedElement xmi:type="uml:Class" xmi:id="_hg3a8HdCEeWAjOWixlHAwg" name="Foo"/>
+ </packagedElement>
+ <profileApplication xmi:id="_IIsRwHdCEeWAjOWixlHAwg">
+ <eAnnotations xmi:id="_IIxxUHdCEeWAjOWixlHAwg" 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 href="pathmap://UML_PROFILES/Standard.profile.uml#_0"/>
+ </profileApplication>
+ <profileApplication xmi:id="_gJKoMHdCEeWAjOWixlHAwg">
+ <eAnnotations xmi:id="_gJLPQHdCEeWAjOWixlHAwg" source="http://www.eclipse.org/uml2/2.0.0/UML">
+ <references xmi:type="ecore:EPackage" href="my.profile.uml#_arTRUXdCEeWAjOWixlHAwg"/>
+ </eAnnotations>
+ <appliedProfile href="my.profile.uml#_0"/>
+ </profileApplication>
+ </uml:Package>
+ <myprofile:Context xmi:id="_jYvikHdCEeWAjOWixlHAwg" base_Classifier="_hg3a8HdCEeWAjOWixlHAwg"/>
+</xmi:XMI>
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/my.profile.uml b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/my.profile.uml
new file mode 100644
index 00000000000..74c5c561a95
--- /dev/null
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.filters.tests/src/org/eclipse/papyrus/uml/filters/tests/my.profile.uml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Package 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="_6iFHkHdAEeWAjOWixlHAwg" name="my" URI="http://www.eclipse.org/papyrus/2015/test/profileapplied">
+ <packagedElement xmi:type="uml:Package" xmi:id="_DParIHdBEeWAjOWixlHAwg" name="nested">
+ <packagedElement xmi:type="uml:Profile" xmi:id="_0" name="myprofile" URI="http://www.eclipse.org/papyrus/2015/test/profileapplied/myprofile" metaclassReference="_K5Vp4HdBEeWAjOWixlHAwg">
+ <eAnnotations xmi:id="_arTRUHdCEeWAjOWixlHAwg" source="http://www.eclipse.org/uml2/2.0.0/UML">
+ <contents xmi:type="ecore:EPackage" xmi:id="_arTRUXdCEeWAjOWixlHAwg" name="myprofile" nsURI="http://www.eclipse.org/papyrus/2015/test/profileapplied/myprofile" nsPrefix="myprofile">
+ <eClassifiers xmi:type="ecore:EClass" xmi:id="_arTRUndCEeWAjOWixlHAwg" name="Context">
+ <eAnnotations xmi:id="_arTRU3dCEeWAjOWixlHAwg" source="http://www.eclipse.org/uml2/2.0.0/UML" references="_NLq44HdBEeWAjOWixlHAwg"/>
+ <eStructuralFeatures xmi:type="ecore:EReference" xmi:id="_arTRVHdCEeWAjOWixlHAwg" name="base_Classifier" ordered="false" lowerBound="1">
+ <eType xmi:type="ecore:EClass" href="http://www.eclipse.org/uml2/5.0.0/UML#//Classifier"/>
+ </eStructuralFeatures>
+ </eClassifiers>
+ </contents>
+ </eAnnotations>
+ <elementImport xmi:id="_K5Vp4HdBEeWAjOWixlHAwg">
+ <importedElement xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Classifier"/>
+ </elementImport>
+ <packagedElement xmi:type="uml:Stereotype" xmi:id="_NLq44HdBEeWAjOWixlHAwg" name="Context">
+ <ownedAttribute xmi:id="_Qn0PoHdBEeWAjOWixlHAwg" name="base_Classifier" association="_QnzokHdBEeWAjOWixlHAwg">
+ <type xmi:type="uml:Class" href="pathmap://UML_METAMODELS/UML.metamodel.uml#Classifier"/>
+ </ownedAttribute>
+ </packagedElement>
+ <packagedElement xmi:type="uml:Extension" xmi:id="_QnzokHdBEeWAjOWixlHAwg" name="Classifier_Context" memberEnd="_QnzokXdBEeWAjOWixlHAwg _Qn0PoHdBEeWAjOWixlHAwg">
+ <ownedEnd xmi:type="uml:ExtensionEnd" xmi:id="_QnzokXdBEeWAjOWixlHAwg" name="extension_Context" type="_NLq44HdBEeWAjOWixlHAwg" aggregation="composite" association="_QnzokHdBEeWAjOWixlHAwg"/>
+ </packagedElement>
+ </packagedElement>
+ </packagedElement>
+</uml:Package>

Back to the top