Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Fleck2016-06-21 07:28:08 +0000
committerGerrit Code Review @ Eclipse.org2016-06-27 15:17:57 +0000
commit0a4fa8933935a3160633e4122eb26a14a0c4aa35 (patch)
tree75133884b80a14a6c9456eddc24e293368569757 /tests
parent4c1f28e71861ba3c933a6ca4d46d7c90644bb878 (diff)
downloadorg.eclipse.papyrus-0a4fa8933935a3160633e4122eb26a14a0c4aa35.tar.gz
org.eclipse.papyrus-0a4fa8933935a3160633e4122eb26a14a0c4aa35.tar.xz
org.eclipse.papyrus-0a4fa8933935a3160633e4122eb26a14a0c4aa35.zip
Bug 496307: [Profile Migration] Restrictive package pattern matching
- Add ProfileNamespaceURIPatterns to split namespace URIs into a versionless, identifying namespace URI and the version information. A namespace URI is matched by a given Regex pattern. The versionless namespace URI is a concatenation of all parts of the matches that are not in groups. The version information is a formatted string consisting of the parts matched through the groups in the pattern and therefore may be spread across the URI. The format of the resulting version string can be customized using a dedicated MessageFormat. - Add extension point for profile namespace URI patterns. - Add pattern registry that is initialized with extension points. - Add usage of profile namespace URI patterns when comparing URIs in the zombie stereotypes descriptor, if there is no perfect equality. If no registered pattern handles the URIs, the previous behavior is used as default. - Bump plugin version to 1.2.1 Includes tests for the pattern matching and splitting. Includes tests to test reported behavior and the improved behavior in the zombie stereotypes descriptor. Change-Id: I5f7744c2a19bb20ea2572247f6d47f948504f7b4 Signed-off-by: Martin Fleck <mfleck@eclipsesource.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/META-INF/MANIFEST.MF1
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/plugin.xml7
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/resources/regression/bug496307/model.uml27
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/StereotypeRepairRegressionTest.java146
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/internal/uripattern/ProfileNamespaceURIPatternTest.java545
-rw-r--r--tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/tests/AllTests.java5
6 files changed, 716 insertions, 15 deletions
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/META-INF/MANIFEST.MF
index fe304630c13..59ce8e0e82a 100644
--- a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/META-INF/MANIFEST.MF
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/META-INF/MANIFEST.MF
@@ -6,6 +6,7 @@ Require-Bundle: org.junit;bundle-version="4.10.0",
org.eclipse.uml2.uml;bundle-version="[5.2.0,6.0.0)",
org.eclipse.papyrus.infra.emf.readonly;bundle-version="[2.0.0,3.0.0)"
Export-Package: org.eclipse.papyrus.uml.modelrepair.internal.stereotypes,
+ org.eclipse.papyrus.uml.modelrepair.internal.uripattern,
org.eclipse.papyrus.uml.modelrepair.tests
Bundle-Vendor: %providerName
Bundle-Version: 1.2.0.qualifier
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/plugin.xml b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/plugin.xml
index c8f9d20ccbe..719f76fd306 100644
--- a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/plugin.xml
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/plugin.xml
@@ -41,4 +41,11 @@
path="pathmap://modelrepairtests/dynamicprofiles/dynamic.profile.uml">
</profile>
</extension>
+ <extension
+ point="org.eclipse.papyrus.uml.modelrepair.profileNamespaceURIPattern">
+ <profileNamespaceURIPattern
+ uriPattern="^http://www\.eclipse\.org/my/profile/test/([^/]+)/Language/.*$"
+ versionFormat="#{1}#">
+ </profileNamespaceURIPattern>
+ </extension>
</fragment>
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/resources/regression/bug496307/model.uml b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/resources/regression/bug496307/model.uml
new file mode 100644
index 00000000000..a23a34b54e0
--- /dev/null
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/resources/regression/bug496307/model.uml
@@ -0,0 +1,27 @@
+<?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:PackageA="http://www.eclipse.org/product/0.6.0/Language/PackageA"
+ xmlns:PackageB="http://www.eclipse.org/product/0.6.0/Language/PackageB"
+ xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
+ xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML"
+ xsi:schemaLocation="
+ http://www.eclipse.org/product/0.6.0/Language/PackageA http://www.eclipse.org/product/0.6.0/Language#//packageA
+ http://www.eclipse.org/product/0.6.0/Language/PackageB http://www.eclipse.org/product/0.6.0/Language#//packageB">
+ <uml:Model xmi:id="_j7ML4CdYEea7OLrFgBltsw" name="RootElement">
+ <packagedElement xmi:type="uml:Class" xmi:id="_mPfJwCdYEea7OLrFgBltsw" name="MyBlock"/>
+ <profileApplication xmi:type="uml:ProfileApplication" xmi:id="_j_rqUCdYEea7OLrFgBltsw">
+ <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_j_rqUSdYEea7OLrFgBltsw" source="http://www.eclipse.org/uml2/2.0.0/UML">
+ <references xmi:type="ecore:EPackage" href="http://www.eclipse.org/product/0.6.0/Language#//packageB"/>
+ </eAnnotations>
+ <appliedProfile xmi:type="uml:Profile" href="pathmap://NO_PROFILE/Language.profile.uml#_Gx8MgLX7EduFmqQsrNB9lw"/>
+ </profileApplication>
+ <profileApplication xmi:type="uml:ProfileApplication" xmi:id="_j_sRYCdYEea7OLrFgBltsw">
+ <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_j_sRYSdYEea7OLrFgBltsw" source="http://www.eclipse.org/uml2/2.0.0/UML">
+ <references xmi:type="ecore:EPackage" href="http://www.eclipse.org/product/0.6.0/Language#//packageA"/>
+ </eAnnotations>
+ <appliedProfile xmi:type="uml:Profile" href="pathmap://NO_PROFILE/Language.profile.uml#_fSw28LX7EduFmqQsrNB9lw"/>
+ </profileApplication>
+ </uml:Model>
+ <PackageA:Block xmi:id="_mPjbMCdYEea7OLrFgBltsw" isEncapsulated="true" base_Class="_mPfJwCdYEea7OLrFgBltsw"/>
+ <PackageB:ViewPoint xmi:id="_N_15cCdZEea7OLrFgBltsw" base_Class="_mPfJwCdYEea7OLrFgBltsw" purpose="This is just for testing."/>
+</xmi:XMI>
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/StereotypeRepairRegressionTest.java b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/StereotypeRepairRegressionTest.java
index e2eb655806a..c377703dd9a 100644
--- a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/StereotypeRepairRegressionTest.java
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/internal/stereotypes/StereotypeRepairRegressionTest.java
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2014, 2016 CEA, 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
@@ -9,10 +9,12 @@
* Contributors:
* Christian W. Damus (CEA) - Initial API and implementation
* Christian W. Damus - bugs 455248, 455329, 436666, 458736, 459488, 488791
+ * Martin Fleck - bug 496307
*
*/
package org.eclipse.papyrus.uml.modelrepair.internal.stereotypes;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
@@ -36,17 +38,22 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.common.util.ECollections;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xml.type.AnyType;
import org.eclipse.papyrus.infra.core.utils.TransactionHelper;
+import org.eclipse.papyrus.infra.tools.util.PlatformHelper;
import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
import org.eclipse.papyrus.junit.utils.rules.AbstractHouseKeeperRule.CleanUp;
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.uml.modelrepair.internal.stereotypes.StereotypeApplicationRepairSnippetTest.MyStereotypeApplicationRepairSnippet;
+import org.eclipse.papyrus.uml.modelrepair.internal.uripattern.ProfileNamespaceURIPattern;
+import org.eclipse.papyrus.uml.modelrepair.internal.uripattern.ProfileNamespaceURIPatternRegistry;
import org.eclipse.papyrus.uml.modelrepair.ui.IZombieStereotypePresenter;
import org.eclipse.uml2.common.util.UML2Util;
import org.eclipse.uml2.uml.Class;
@@ -62,6 +69,8 @@ import org.junit.Test;
import com.google.common.base.Function;
import com.google.common.base.Functions;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
@@ -99,7 +108,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
/**
* Tests that a scenario involving nested profiles and profile applications in nested packages that are all actually
* well-formed does not trigger the repair function.
- *
+ *
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=434302
*/
@Test
@@ -111,7 +120,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
/**
* Tests that a scenario involving a nested profile gone AWOL in profile applications in a nested packages is
* correctly repaired.
- *
+ *
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=434302
*/
@Test
@@ -140,7 +149,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
/**
* Tests that a scenario involving a single nested profile schema declaration gone AWOL in two different profile applications
* in two different nested packages is correctly repaired.
- *
+ *
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=434302
*/
@Test
@@ -180,7 +189,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
/**
* Tests that a scenario involving well-formed stereotypes contained in a simple package nested in a profile
* does not trigger the repair function.
- *
+ *
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=436666
*/
@Test
@@ -193,7 +202,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
/**
* Tests that a scenario involving stereotypes from a nested EPackage gone AWOL, which EPackage is defined by a nested
* simple package in the UML profile, is correctly repaired.
- *
+ *
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=436666
*/
@Test
@@ -222,7 +231,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
/**
* Tests that a scenario involving non-UML root elements that are recognizably not stereotype
* applications do not trigger the repair function.
- *
+ *
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=436666
*/
@Test
@@ -236,7 +245,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
* Tests that a sub-united model in which package units do not repeat profile applications,
* but rather just inherit them from parent units, such as might be imported from some other
* UML tool, does not falsely trigger repair.
- *
+ *
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=455248
*/
@Test
@@ -249,7 +258,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
/**
* Tests that a model applying a registered dynamic profile does not detect spurious broken
* stereotype applications.
- *
+ *
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=455329
*/
@Test
@@ -261,7 +270,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
/**
* Tests that orphaned stereotype instances are correctly detected where they are of the currently applied profile schema.
- *
+ *
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=436666
*/
@Test
@@ -280,7 +289,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
/**
* Tests that orphaned stereotype instances are correctly detected where they are of a profile version that is not currently applied.
- *
+ *
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=436666
*/
@Test
@@ -302,7 +311,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
* but rather just inherit them from parent units, such as might be imported from some other
* UML tool, does not falsely trigger repair in the case where sub-units are lazily loaded
* by cross-references after the main model has been loaded.
- *
+ *
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=458736
*/
@Test
@@ -318,7 +327,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
/**
* Tests that a scenario involving a malformed XSI schema-location for a profile schema in a non-package model fragment
* (sub-unit resource) is correctly detected and repaired.
- *
+ *
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=459488
*/
@Test
@@ -343,6 +352,105 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
assertThat("Stereotype1 application in wrong resource", class1.getStereotypeApplication(stereotype1).eResource(), is(class1.eResource()));
}
+ /**
+ * Tests that bug 496307 is present and there are cases where zombie stereotypes are not correctly
+ * assigned to the expected package, because the namespace URI (schema) is not understood correctly.
+ *
+ * In the test model we have one class with two stereotypes applied:
+ * - Block from PackageA with schema http://www.eclipse.org/product/0.6.0/Language/PackageA
+ * - ViewPoint from PackageB with schema http://www.eclipse.org/product/0.6.0/Language/PackageB
+ *
+ * Both schemas do not conform to the default pattern, so they are reduced to the schema
+ * http://www.eclipse.org/product/0.6.0/Language#/ during comparison.
+ * As a result, both zombie stereotypes are assigned to both schemas and wrongly assigned
+ * zombie stereotypes may be deleted.
+ *
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=496307
+ */
+ @Test
+ @Bug("496307")
+ @PluginResource("/resources/regression/bug496307/model.uml")
+ public void incorrectZombieGroupingWithoutProfileNamespaceURIPattern_bug496307() {
+ Collection<? extends IAdaptable> schemata = zombies.getZombieSchemas();
+ assertThat("Expected two schemata", schemata.size(), is(2));
+
+ Optional<? extends IAdaptable> packageA = Iterables.tryFind(schemata,
+ ePackage("http://www.eclipse.org/product/0.6.0/Language/PackageA"));
+ assertThat("PackageA not found", packageA.isPresent());
+
+ Optional<? extends IAdaptable> packageB = Iterables.tryFind(schemata,
+ ePackage("http://www.eclipse.org/product/0.6.0/Language/PackageB"));
+ assertThat("PackageB not found", packageB.isPresent());
+
+ Collection<? extends EObject> packageAzombies = zombies.getZombies(packageA.get());
+ assertThat("Expected two zombies in PackageA", packageAzombies.size(), is(2));
+
+ Collection<? extends EObject> packageBzombies = zombies.getZombies(packageB.get());
+ assertThat("Expected two zombies in PackageB", packageBzombies.size(), is(2));
+
+ assertThat("Same zombies in PackageA and PackageB expected", packageAzombies.containsAll(packageBzombies));
+ }
+
+ /**
+ * Tests that bug 496307 is resolved through {@link ProfileNamespaceURIPattern}s which provide a mechanism to
+ * understand namespace URI schemas.
+ *
+ * In the test model we have one class with two stereotypes applied:
+ * - Block from PackageA with package schema http://www.eclipse.org/product/0.6.0/Language/PackageA
+ * - ViewPoint from PackageB with package schema http://www.eclipse.org/product/0.6.0/Language/PackageB
+ *
+ * Both schemas do not conform to the default pattern, but we provide the namespace URI pattern
+ * ^http://www\\.eclipse\\.org/product/([^/]+)/Language/.*$ during comparison.
+ * As a result, both zombie stereotypes are correctly assigned to their respective schema.
+ *
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=496307
+ */
+ @Test
+ @Bug("496307")
+ @PluginResource("/resources/regression/bug496307/model.uml")
+ public void correctZombieGroupingWithProfileNamespaceURIPattern_bug496307() {
+ ProfileNamespaceURIPatternRegistry registry = ProfileNamespaceURIPatternRegistry.INSTANCE;
+ ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(
+ "^http://www\\.eclipse\\.org/product/([^/]+)/Language/.*$");
+
+ try {
+ registry.register(pattern);
+
+ Collection<? extends IAdaptable> schemata = zombies.getZombieSchemas();
+
+ assertThat("Expected two schemata", schemata.size(), is(2));
+
+ Optional<? extends IAdaptable> packageA = Iterables.tryFind(schemata,
+ ePackage("http://www.eclipse.org/product/0.6.0/Language/PackageA"));
+ assertThat("PackageA not found", packageA.isPresent());
+
+ Optional<? extends IAdaptable> packageB = Iterables.tryFind(schemata,
+ ePackage("http://www.eclipse.org/product/0.6.0/Language/PackageB"));
+ assertThat("PackageB not found", packageB.isPresent());
+
+ Collection<? extends EObject> packageAzombies = zombies.getZombies(packageA.get());
+ assertThat("Expected one zombies in PackageA", packageAzombies.size(), is(1));
+
+ EObject packageAzombie = packageAzombies.iterator().next();
+ assertThat("Expected zombie stereotype (AnyType)", packageAzombie, instanceOf(AnyType.class));
+
+ EClass packageAzombieClass = packageAzombie.eClass();
+ assertThat("PackageA zombie should be Block", packageAzombieClass.getName(), is("Block"));
+
+ Collection<? extends EObject> packageBzombies = zombies.getZombies(packageB.get());
+ assertThat("Expected one zombies in PackageB", packageBzombies.size(), is(1));
+
+ EObject packageBzombie = packageBzombies.iterator().next();
+ assertThat("Expected zombie stereotype (AnyType)", packageBzombie, instanceOf(AnyType.class));
+
+ EClass packageBzombieClass = packageBzombie.eClass();
+ assertThat("PackageB zombie should be ViewPoint", packageBzombieClass.getName(), is("ViewPoint"));
+ } finally {
+ // ensure that the pattern is unregistered for further tests
+ registry.unregister(pattern);
+ }
+ }
+
//
// Test framework
//
@@ -425,7 +533,7 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
}), "dispose", modelSet.getResourceSet());
}
- @Bug({ "436666bis", "455248", "455329" })
+ @Bug({ "436666bis", "455248", "455329", "496307" })
protected MyStereotypeApplicationRepairSnippet createSimpleFixture() {
return houseKeeper.cleanUpLater(new MyStereotypeApplicationRepairSnippet(null, Functions.constant((Profile) null)), "dispose", modelSet.getResourceSet());
}
@@ -506,6 +614,16 @@ public class StereotypeRepairRegressionTest extends AbstractPapyrusTest {
sync.await();
}
+ Predicate<IAdaptable> ePackage(final String uri) {
+ return new Predicate<IAdaptable>() {
+ @Override
+ public boolean apply(IAdaptable adaptable) {
+ EPackage ePackage = PlatformHelper.getAdapter(adaptable, EPackage.class);
+ return ePackage != null && ePackage.getNsURI() != null && ePackage.getNsURI().equals(uri);
+ }
+ };
+ }
+
//
// Nested types
//
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/internal/uripattern/ProfileNamespaceURIPatternTest.java b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/internal/uripattern/ProfileNamespaceURIPatternTest.java
new file mode 100644
index 00000000000..84c336563f8
--- /dev/null
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/internal/uripattern/ProfileNamespaceURIPatternTest.java
@@ -0,0 +1,545 @@
+/*******************************************************************************
+ * Copyright (c) 2016 EclipseSource Services GmbH 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:
+ * Martin Fleck - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.uml.modelrepair.internal.uripattern;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest;
+import org.eclipse.papyrus.uml.modelrepair.internal.stereotypes.StereotypeRepairRegressionTest;
+import org.junit.Test;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests for {@link ProfileNamespaceURIPattern}s and the related functionality.
+ * The extended profile migration capabilities provided through the profile namespace URI patterns is tested in {@link StereotypeRepairRegressionTest}.
+ *
+ * @author Martin Fleck <mfleck@eclipsesource.com>
+ */
+public class ProfileNamespaceURIPatternTest extends AbstractPapyrusTest {
+
+ // no version in URI
+
+ private static final String NO_VERSION_PATTERN = "^http://www\\.eclipse\\.org/my/profile/Language/.*$"; //$NON-NLS-1$
+
+ private static final String NO_VERSION_FORMAT = "{0}"; //$NON-NLS-1$
+
+ private static final String NO_VERSION_A_URI = "http://www.eclipse.org/my/profile/Language/PackageA"; //$NON-NLS-1$
+
+ private static final String NO_VERSION_B_URI = "http://www.eclipse.org/my/profile/Language/PackageB"; //$NON-NLS-1$
+
+ private static final String NO_VERSION_VERSION_DEFAULT = ""; //$NON-NLS-1$
+
+ // single version in URI
+
+ private static final String SINGLE_VERSION_PATTERN = "^http://www\\.eclipse\\.org/my/profile/version/([^/]+)/Language/.*$"; //$NON-NLS-1$
+
+ private static final String SINGLE_VERSION_FORMAT = "-{1}-"; //$NON-NLS-1$
+
+ private static final String SINGLE_VERSION_A7_URI = "http://www.eclipse.org/my/profile/version/7/Language/PackageA"; //$NON-NLS-1$
+
+ private static final String SINGLE_VERSION_A7_VERSIONLESS_URI = "http://www.eclipse.org/my/profile/version//Language/PackageA"; //$NON-NLS-1$
+
+ private static final String SINGLE_VERSION_A7_VERSION_DEFAULT = "7"; //$NON-NLS-1$
+
+ private static final String SINGLE_VERSION_A7_VERSION_FORMAT = "-7-"; //$NON-NLS-1$
+
+ private static final String SINGLE_VERSION_B7_URI = "http://www.eclipse.org/my/profile/version/7/Language/PackageB"; //$NON-NLS-1$
+
+ private static final String SINGLE_VERSION_A8_URI = "http://www.eclipse.org/my/profile/version/8/Language/PackageA"; //$NON-NLS-1$
+
+ private static final String SINGLE_VERSION_NONMATCHING_URI = "http://www.eclipse.org/different/profile/version/7/Language/PackageA"; //$NON-NLS-1$
+
+ // multiple versions in URI
+
+ private static final String MULTI_VERSION_PATTERN = "^http://www\\.eclipse\\.org/my/profile/version/([^/]+)/Language/([^/]+)/.*$"; //$NON-NLS-1$
+
+ private static final String MULTI_VERSION_FORMAT = "{1} - {2}"; //$NON-NLS-1$
+
+ private static final String MULTI_VERSION_A7_701_URI = "http://www.eclipse.org/my/profile/version/7/Language/7.0.1/PackageA"; //$NON-NLS-1$
+
+ private static final String MULTI_VERSION_A7_701_VERSIONLESS_URI = "http://www.eclipse.org/my/profile/version//Language//PackageA"; //$NON-NLS-1$
+
+ private static final String MULTI_VERSION_A7_701_VERSION_DEFAULT = "7,7.0.1"; // comma-separated //$NON-NLS-1$
+
+ private static final String MULTI_VERSION_A7_701_VERSION_FORMAT = "7 - 7.0.1"; //$NON-NLS-1$
+
+ private static final String MULTI_VERSION_B7_701_URI = "http://www.eclipse.org/my/profile/version/7/Language/7.0.1/PackageB"; //$NON-NLS-1$
+
+ private static final String MULTI_VERSION_A7_702_URI = "http://www.eclipse.org/my/profile/version/7/Language/7.0.2/PackageA"; //$NON-NLS-1$
+
+ // non-matching pattern
+
+ private static final String NON_MATCHING_PATTERN = "^http://www\\.eclipse\\.org/no/match/version/([^/]+)/Language/([^/]+)/.*$"; //$NON-NLS-1$
+
+ // pattern registered via extension point
+
+ private static final String EXTENSION_POINT_PATTERN = "^http://www\\.eclipse\\.org/my/profile/test/([^/]+)/Language/.*$"; //$NON-NLS-1$
+
+ private static final String EXTENSION_POINT_URI = "http://www.eclipse.org/my/profile/test/7/Language/PackageA"; //$NON-NLS-1$
+
+ private static final String EXTENSION_POINT_VERSIONLESS_URI = "http://www.eclipse.org/my/profile/test//Language/PackageA"; //$NON-NLS-1$
+
+ private static final String EXTENSION_POINT_VERSION = "#7#"; // custom version format: #{0}# //$NON-NLS-1$
+
+
+ /**
+ * Predicate that evaluates whether a specific pattern is the one we registered via an extension point.
+ *
+ * @return new predicate
+ */
+ protected static Predicate<ProfileNamespaceURIPattern> isExtensionPointPattern() {
+ return new Predicate<ProfileNamespaceURIPattern>() {
+ @Override
+ public boolean apply(ProfileNamespaceURIPattern pattern) {
+ return pattern.getRegexPattern() != null && EXTENSION_POINT_PATTERN.equals(pattern.getRegexPattern().pattern()) &&
+ pattern.getVersionFormat() != null;
+ }
+ };
+ }
+
+ // no version matching behavior
+
+ /**
+ * Tests whether the pattern match yields the correct results for an URI with no version part
+ * and the default version format. When there is no versioning information, the versionless URI
+ * and the given URI should be the same.
+ */
+ @Test
+ public void matchNoVersionCorrectURIDefaultVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(NO_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternMatchResult match = pattern.match(NO_VERSION_A_URI);
+
+ assertThat("Pattern should have matched.", match.hasMatched());
+ assertThat("Matched namespace URI should be equal to given namesapce URI.",
+ match.getNamespaceURI(), is(NO_VERSION_A_URI));
+ assertThat("Wrong extracted versionless namespace URI.",
+ match.getVersionlessNamespaceURI(), is(NO_VERSION_A_URI));
+ assertThat("Wrong extracted version.",
+ match.getVersion(), is(NO_VERSION_VERSION_DEFAULT));
+ }
+
+ /**
+ * Tests whether the pattern match yields the correct results for an URI with no version part
+ * and a given version format. When there is no versioning information and the format is '{0}',
+ * the versionless URI, the version and the given URI should be the same.
+ */
+ @Test
+ public void matchNoVersionCorrectURIGivenVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(NO_VERSION_PATTERN, NO_VERSION_FORMAT);
+ final ProfileNamespaceURIPatternMatchResult match = pattern.match(NO_VERSION_A_URI);
+
+ assertThat("Pattern should have matched.", match.hasMatched());
+ assertThat("Matched namespace URI should be equal to given namesapce URI.",
+ match.getNamespaceURI(), is(NO_VERSION_A_URI));
+ assertThat("Wrong extracted versionless namespace URI.",
+ match.getVersionlessNamespaceURI(), is(NO_VERSION_A_URI));
+ assertThat("Wrong extracted version.",
+ match.getVersion(), is(NO_VERSION_A_URI));
+ }
+
+ // single version matching behavior
+
+ /**
+ * Tests whether the pattern match yields the correct results for an URI with a single version part
+ * and the default version format.
+ */
+ @Test
+ public void matchSingleVersionCorrectURIDefaultVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(SINGLE_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternMatchResult match = pattern.match(SINGLE_VERSION_A7_URI);
+
+ assertThat("Pattern should have matched.", match.hasMatched());
+ assertThat("Matched namespace URI should be equal to given namesapce URI.",
+ match.getNamespaceURI(), is(SINGLE_VERSION_A7_URI));
+ assertThat("Wrong extracted versionless namespace URI.",
+ match.getVersionlessNamespaceURI(), is(SINGLE_VERSION_A7_VERSIONLESS_URI));
+ assertThat("Wrong extracted version.",
+ match.getVersion(), is(SINGLE_VERSION_A7_VERSION_DEFAULT));
+ }
+
+ /**
+ * Tests whether the pattern match yields the correct results for an URI with a single version part
+ * and a given version format.
+ */
+ @Test
+ public void matchSingleVersionCorrectURIGivenVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(SINGLE_VERSION_PATTERN, SINGLE_VERSION_FORMAT);
+ final ProfileNamespaceURIPatternMatchResult match = pattern.match(SINGLE_VERSION_A7_URI);
+
+ assertThat("Pattern should have matched.", match.hasMatched());
+ assertThat("Matched namespace URI should be equal to given namesapce URI.",
+ match.getNamespaceURI(), is(SINGLE_VERSION_A7_URI));
+ assertThat("Wrong extracted versionless namespace URI.",
+ match.getVersionlessNamespaceURI(), is(SINGLE_VERSION_A7_VERSIONLESS_URI));
+ assertThat("Wrong extracted version.",
+ match.getVersion(), is(SINGLE_VERSION_A7_VERSION_FORMAT));
+ }
+
+ // multiple version matching behavior
+
+ /**
+ * Tests whether the pattern match yields the correct results for an URI with a multiple version parts
+ * and the default version format.
+ */
+ @Test
+ public void matchMultipleVersionCorrectURIDefaultVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(MULTI_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternMatchResult match = pattern.match(MULTI_VERSION_A7_701_URI);
+
+ assertThat("Pattern should have matched.", match.hasMatched());
+ assertThat("Matched namespace URI should be equal to given namesapce URI.",
+ match.getNamespaceURI(), is(MULTI_VERSION_A7_701_URI));
+ assertThat("Wrong extracted versionless namespace URI.",
+ match.getVersionlessNamespaceURI(), is(MULTI_VERSION_A7_701_VERSIONLESS_URI));
+ assertThat("Wrong extracted version.",
+ match.getVersion(), is(MULTI_VERSION_A7_701_VERSION_DEFAULT));
+ }
+
+ /**
+ * Tests whether the pattern match yields the correct results for an URI with a multiple version parts
+ * and a given version format.
+ */
+ @Test
+ public void matchMultipleVersionCorrectURIGivenVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(MULTI_VERSION_PATTERN, MULTI_VERSION_FORMAT);
+ final ProfileNamespaceURIPatternMatchResult match = pattern.match(MULTI_VERSION_A7_701_URI);
+
+ assertThat("Pattern should have matched.", match.hasMatched());
+ assertThat("Matched namespace URI should be equal to given namesapce URI.",
+ match.getNamespaceURI(), is(MULTI_VERSION_A7_701_URI));
+ assertThat("Wrong extracted versionless namespace URI.",
+ match.getVersionlessNamespaceURI(), is(MULTI_VERSION_A7_701_VERSIONLESS_URI));
+ assertThat("Wrong extracted version.",
+ match.getVersion(), is(MULTI_VERSION_A7_701_VERSION_FORMAT));
+ }
+
+ // no match behavior
+
+ /**
+ * Tests whether the pattern match yields the correct results for an URI that does not match the pattern.
+ * The namespace URI, the versionless namespace URI and the version should be null.
+ */
+ @Test
+ public void matchCorrectNoMatchBehavior() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(NON_MATCHING_PATTERN);
+ final ProfileNamespaceURIPatternMatchResult match = pattern.match(MULTI_VERSION_A7_701_URI);
+
+ assertThat("Pattern should not have matched.", !match.hasMatched());
+ assertThat("Unmatched URI should yield null namespace URI.",
+ match.getNamespaceURI(), nullValue());
+ assertThat("Unmatched versionless URI should be null.",
+ match.getVersionlessNamespaceURI(), nullValue());
+ assertThat("Unmatched version should be null.",
+ match.getVersion(), nullValue());
+ }
+
+ /**
+ * Tests whether the pattern match yields the correct results for the NO_MATCH constant.
+ * The namespace URI, the versionless namespace URI and the version should be null.
+ */
+ @Test
+ public void matchCorrectNoMatchConstantBehavior() {
+ final ProfileNamespaceURIPatternMatchResult match = ProfileNamespaceURIPatternMatchResult.NO_MATCH;
+
+ assertThat("Pattern should not have matched.", !match.hasMatched());
+ assertThat("Unmatched URI should yield null namespace URI.",
+ match.getNamespaceURI(), nullValue());
+ assertThat("Unmatched versionless URI should be null.",
+ match.getVersionlessNamespaceURI(), nullValue());
+ assertThat("Unmatched version should be null.",
+ match.getVersion(), nullValue());
+ }
+
+ // no version comparison behavior
+
+ /**
+ * Tests whether the comparison between two identical URIs with no version part yields the expected,
+ * equal result.
+ */
+ @Test
+ public void compareNoVersionSameURI() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(NO_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(NO_VERSION_A_URI, NO_VERSION_A_URI);
+
+ assertThat("Comparison should be valid.", comparison.isValid());
+ assertThat("Same URI should be equal to itself (namespace URI).", comparison.isEqualNamespaceURI());
+ assertThat("Same URI should be equal to itself (versionless URI).", comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Same URI should be equal to itself (version).", comparison.isEqualVersion());
+ }
+
+ /**
+ * Tests whether the comparison between two different URIs with no version part yields the expected,
+ * result.
+ */
+ @Test
+ public void compareNoVersionDifferentURI() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(NO_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(NO_VERSION_A_URI, NO_VERSION_B_URI);
+
+ assertThat("Comparison should be valid.", comparison.isValid());
+ assertThat("Should not be the same namespace URI.", !comparison.isEqualNamespaceURI());
+ assertThat("Should not be the same versionless URI.", !comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Should be the same version (no version).", comparison.isEqualVersion());
+ }
+
+ // single version comparison behavior
+
+ /**
+ * Tests whether the comparison between two identical URIs with a single version part yields the expected,
+ * equal result.
+ */
+ @Test
+ public void compareSingleVersionSameURISameVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(SINGLE_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(SINGLE_VERSION_A7_URI, SINGLE_VERSION_A7_URI);
+
+ assertThat("Comparison should be valid.", comparison.isValid());
+ assertThat("Same URI should be equal to itself (namespace URI).", comparison.isEqualNamespaceURI());
+ assertThat("Same URI should be equal to itself (versionless URI).", comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Same URI should be equal to itself (version).", comparison.isEqualVersion());
+ }
+
+ /**
+ * Tests whether the comparison between two versionless URI-equal but version-different URIs with a single version
+ * part yields the expected result.
+ */
+ @Test
+ public void compareSingleVersionSameURIDifferentVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(SINGLE_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(SINGLE_VERSION_A7_URI, SINGLE_VERSION_A8_URI);
+
+ assertThat("Comparison should be valid.", comparison.isValid());
+ assertThat("Should be different namespace URI.", !comparison.isEqualNamespaceURI());
+ assertThat("Should be the same versionless URI.", comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Should be different versions (7 and 8).", !comparison.isEqualVersion());
+ }
+
+ /**
+ * Tests whether the comparison between two versionless URI-different but version-equal URIs with a single version
+ * part yields the expected result.
+ */
+ @Test
+ public void compareSingleVersionDifferentURISameVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(SINGLE_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(SINGLE_VERSION_A7_URI, SINGLE_VERSION_B7_URI);
+
+ assertThat("Comparison should be valid.", comparison.isValid());
+ assertThat("Should be different namespace URI.", !comparison.isEqualNamespaceURI());
+ assertThat("Should be different versionless URI.", !comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Should be the same version (7 and 7).", comparison.isEqualVersion());
+ }
+
+ /**
+ * Tests whether the comparison between two versionless URI-different and version-different URIs with a single version
+ * part yields the expected result.
+ */
+ @Test
+ public void compareSingleVersionDifferentURIDifferentVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(SINGLE_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(SINGLE_VERSION_A8_URI, SINGLE_VERSION_B7_URI);
+
+ assertThat("Comparison should be valid.", comparison.isValid());
+ assertThat("Should be different namespace URI.", !comparison.isEqualNamespaceURI());
+ assertThat("Should be different versionless URI.", !comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Should be different versions (8 and 7).", !comparison.isEqualVersion());
+ }
+
+ // multiple version comparison behavior
+
+ /**
+ * Tests whether the comparison between two identical URIs with multiple version parts yields the expected,
+ * equal result.
+ */
+ @Test
+ public void compareMultiVersionSameURISameVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(MULTI_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(MULTI_VERSION_A7_701_URI, MULTI_VERSION_A7_701_URI);
+
+ assertThat("Comparison should be valid.", comparison.isValid());
+ assertThat("Same URI should be equal to itself (namespace URI).", comparison.isEqualNamespaceURI());
+ assertThat("Same URI should be equal to itself (versionless URI).", comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Same URI should be equal to itself (version).", comparison.isEqualVersion());
+ }
+
+ /**
+ * Tests whether the comparison between two versionless URI-equal but version-different URIs with multiple version
+ * parts yields the expected result.
+ */
+ @Test
+ public void compareMultiVersionSameURIDifferentVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(MULTI_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(MULTI_VERSION_A7_701_URI, MULTI_VERSION_A7_702_URI);
+
+ assertThat("Comparison should be valid.", comparison.isValid());
+ assertThat("Should be different namespace URI.", !comparison.isEqualNamespaceURI());
+ assertThat("Should be the same versionless URI.", comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Should be different versions (7,7.0.1 and 7,7.0.2).", !comparison.isEqualVersion());
+ }
+
+ /**
+ * Tests whether the comparison between two versionless URI-different but version-equal URIs with multiple version
+ * parts yields the expected result.
+ */
+ @Test
+ public void compareMultiVersionDifferentURISameVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(MULTI_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(MULTI_VERSION_A7_701_URI, MULTI_VERSION_B7_701_URI);
+
+ assertThat("Comparison should be valid.", comparison.isValid());
+ assertThat("Should be different namespace URI.", !comparison.isEqualNamespaceURI());
+ assertThat("Should be different versionless URI.", !comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Should be the same version (7,7.0.1 and 7,7.0.1).", comparison.isEqualVersion());
+ }
+
+ /**
+ * Tests whether the comparison between two versionless URI-different and version-different URIs with multiple version
+ * parts yields the expected result.
+ */
+ @Test
+ public void compareMultiVersionDifferentURIDifferentVersion() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(MULTI_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(MULTI_VERSION_A7_702_URI, MULTI_VERSION_B7_701_URI);
+
+ assertThat("Comparison should be valid.", comparison.isValid());
+ assertThat("Should be different namespace URI.", !comparison.isEqualNamespaceURI());
+ assertThat("Should be the same versionless URI.", !comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Should be the same version (7,7.0.2 and 7,7.0.1).", !comparison.isEqualVersion());
+ }
+
+
+ // invalid comparison behavior
+
+ /**
+ * Tests whether the comparison of two non-matching URIs yields the expected, invalid results.
+ */
+ @Test
+ public void compareCorrectInvalidComparisonBehaviorWrongPattern() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(NON_MATCHING_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(SINGLE_VERSION_A7_URI, SINGLE_VERSION_A7_URI);
+
+ assertThat("Comparison should not be valid.", !comparison.isValid());
+ assertThat("Namespace URIs should not be equal due to invalid comparison.", !comparison.isEqualNamespaceURI());
+ assertThat("Versionless URIs should not be equal due to invalid comparison.", !comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Versions should not be equal due to invalid comparison.", !comparison.isEqualVersion());
+ }
+
+ /**
+ * Tests whether the comparison of one non-matching URIs on the left-hand side yields the expected, invalid results.
+ */
+ @Test
+ public void compareCorrectInvalidComparisonBehaviorWrongLHS() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(SINGLE_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(SINGLE_VERSION_NONMATCHING_URI, SINGLE_VERSION_A7_URI);
+
+ assertThat("Comparison should not be valid.", !comparison.isValid());
+ assertThat("Namespace URIs should not be equal due to invalid comparison.", !comparison.isEqualNamespaceURI());
+ assertThat("Versionless URIs should not be equal due to invalid comparison.", !comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Versions should not be equal due to invalid comparison.", !comparison.isEqualVersion());
+ }
+
+ /**
+ * Tests whether the comparison of one non-matching URIs on the right-hand side yields the expected, invalid results.
+ */
+ @Test
+ public void compareCorrectInvalidComparisonBehaviorWrongRHS() {
+ final ProfileNamespaceURIPattern pattern = new ProfileNamespaceURIPattern(SINGLE_VERSION_PATTERN);
+ final ProfileNamespaceURIPatternComparison comparison = pattern.compare(SINGLE_VERSION_A7_URI, SINGLE_VERSION_NONMATCHING_URI);
+
+ assertThat("Comparison should not be valid.", !comparison.isValid());
+ assertThat("Namespace URIs should not be equal due to invalid comparison.", !comparison.isEqualNamespaceURI());
+ assertThat("Versionless URIs should not be equal due to invalid comparison.", !comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Versions should not be equal due to invalid comparison.", !comparison.isEqualVersion());
+ }
+
+ /**
+ * Tests whether the INVALID comparison constant yields the expected, invalid results.
+ */
+ @Test
+ public void compareCorrectInvalidComparisonConstantBehavior() {
+ final ProfileNamespaceURIPatternComparison comparison = ProfileNamespaceURIPatternComparison.INVALID;
+
+ assertThat("Comparison should not be valid.", !comparison.isValid());
+ assertThat("Namespace URIs should not be equal due to invalid comparison.", !comparison.isEqualNamespaceURI());
+ assertThat("Versionless URIs should not be equal due to invalid comparison.", !comparison.isEqualVersionlessNamespaceURI());
+ assertThat("Versions should not be equal due to invalid comparison.", !comparison.isEqualVersion());
+ }
+
+ // registry behavior
+
+ /**
+ * Tests whether the extension point provided through the plugin.xml is correctly loaded into the registry.
+ */
+ @Test
+ public void registryExtensionPointRegistered() {
+ ProfileNamespaceURIPatternRegistry registry = ProfileNamespaceURIPatternRegistry.INSTANCE;
+ assertThat("Pattern from extension point should be in registry.",
+ Iterables.any(registry.getProfileNamespaceURIPatterns(), isExtensionPointPattern()));
+ }
+
+ /**
+ * Tests whether the extension point provided through the plugin.xml behaves as expected, i.e., matches a given string.
+ * This is important to ensure that there are no encoding/decoding issues between the strings when loaded from the extension point.
+ */
+ @Test
+ public void registryExtensionPointCorrectMatch() {
+ ProfileNamespaceURIPatternRegistry registry = ProfileNamespaceURIPatternRegistry.INSTANCE;
+ Iterable<ProfileNamespaceURIPattern> registeredPatterns = Iterables.filter(
+ registry.getProfileNamespaceURIPatterns(), isExtensionPointPattern());
+
+ // pattern has only been registered once
+ ProfileNamespaceURIPattern registeredPattern = Iterables.getOnlyElement(registeredPatterns);
+ ProfileNamespaceURIPatternMatchResult match = registeredPattern.match(EXTENSION_POINT_URI);
+
+ assertThat("Pattern should have matched.", match.hasMatched());
+ assertThat("Wrong extracted versionless URI.",
+ match.getVersionlessNamespaceURI(), is(EXTENSION_POINT_VERSIONLESS_URI));
+ assertThat("Wrong extracted version.",
+ match.getVersion(), is(EXTENSION_POINT_VERSION));
+ }
+
+ /**
+ * Tests whether registering and unregistering patterns through the registry API works as expected.
+ * Unregistering a pattern actually removes the pattern from the registry.
+ * Registering a pattern actually adds the pattern to the registry.
+ * Unregistering a non-existing pattern leaves the registry unchanged.
+ */
+ @Test
+ public void registryCorrectUnregisterAndRegister() {
+ ProfileNamespaceURIPatternRegistry registry = ProfileNamespaceURIPatternRegistry.INSTANCE;
+ Iterable<ProfileNamespaceURIPattern> registeredPatterns = Iterables.filter(
+ registry.getProfileNamespaceURIPatterns(), isExtensionPointPattern());
+
+ ProfileNamespaceURIPattern registeredPattern = Iterables.getOnlyElement(registeredPatterns);
+ int originalSize = registry.getProfileNamespaceURIPatterns().size();
+
+ // unregister existing pattern
+ registry.unregister(registeredPattern);
+ assertThat("Registry should have one entry less.",
+ registry.getProfileNamespaceURIPatterns().size(),
+ is(originalSize - 1));
+
+ // register new pattern
+ registry.register(registeredPattern);
+ assertThat("Registry should have all entries.",
+ registry.getProfileNamespaceURIPatterns().size(),
+ is(originalSize));
+
+ // unregister non-existing pattern
+ registry.unregister(new ProfileNamespaceURIPattern("non-existing"));
+ assertThat("Registry should not have lost an entry.",
+ registry.getProfileNamespaceURIPatterns().size(),
+ is(originalSize));
+ }
+}
diff --git a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/tests/AllTests.java b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/tests/AllTests.java
index 6eb70b151cc..5dedb7e08c4 100644
--- a/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/tests/AllTests.java
+++ b/tests/junit/plugins/uml/org.eclipse.papyrus.uml.modelrepair.tests/src/org/eclipse/papyrus/uml/modelrepair/tests/AllTests.java
@@ -9,6 +9,7 @@
* Contributors:
* Christian W. Damus (CEA) - Initial API and implementation
* Christian W. Damus - bug 485220
+ * Martin Fleck - bug 496307
*
*/
package org.eclipse.papyrus.uml.modelrepair.tests;
@@ -17,6 +18,7 @@ import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite;
import org.eclipse.papyrus.junit.framework.runner.Headless;
import org.eclipse.papyrus.uml.modelrepair.internal.stereotypes.StereotypeApplicationRepairSnippetTest;
import org.eclipse.papyrus.uml.modelrepair.internal.stereotypes.StereotypeRepairRegressionTest;
+import org.eclipse.papyrus.uml.modelrepair.internal.uripattern.ProfileNamespaceURIPatternTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite.SuiteClasses;
@@ -26,7 +28,8 @@ import org.junit.runners.Suite.SuiteClasses;
*/
@Headless
@RunWith(ClassificationSuite.class)
-@SuiteClasses({ StereotypeApplicationRepairSnippetTest.class, StereotypeRepairRegressionTest.class })
+@SuiteClasses({ StereotypeApplicationRepairSnippetTest.class, StereotypeRepairRegressionTest.class,
+ ProfileNamespaceURIPatternTest.class })
public class AllTests {
// JUnit 4 Test Suite
}

Back to the top