diff options
Diffstat (limited to 'plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge')
10 files changed, 301 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/InstanceSpecificationClassifiersMergeTest.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/InstanceSpecificationClassifiersMergeTest.java new file mode 100644 index 000000000..ec60a99f2 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/InstanceSpecificationClassifiersMergeTest.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * 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: + * Philip Langer - initial API and implementation + *******************************************************************************/ +package org.eclipse.emf.compare.uml2.tests.merge; + +import java.io.IOException; +import java.util.Collections; + +import org.eclipse.emf.compare.uml2.tests.AbstractUMLInputData; +import org.eclipse.emf.compare.uml2.tests.AbstractUMLTest; +import org.eclipse.emf.compare.uml2.tests.merge.data.InstanceSpecificationClassifiersMergeInputData; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.uml2.uml.EnumerationLiteral; +import org.eclipse.uml2.uml.InstanceSpecification; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests merging changes of the feature {@link InstanceSpecification#getClassifiers()}. + * <p> + * Merging {@link InstanceSpecification#getClassifiers()} requires special handling, if the instance + * specification is an {@link EnumerationLiteral}, because {@link EnumerationLiteral} overwrites + * {@link InstanceSpecification#getClassifiers()}, so that it returns an unmodifiable UnionEObjectEList, which + * always contains the Enumeration as item. Thus, we have to handle changes of + * {@link EnumerationLiteral#getClassifiers()} as if this feature would be derived. + * </p> + * <p> + * See also <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=508665">bug 508665</a>. + * </p> + * + * @author Philip Langer <planger@eclipsesource.com> + */ +public class InstanceSpecificationClassifiersMergeTest extends AbstractUMLTest { + + private InstanceSpecificationClassifiersMergeInputData input = new InstanceSpecificationClassifiersMergeInputData(); + + @Override + protected AbstractUMLInputData getInput() { + return input; + } + + @BeforeClass + public static void setupClass() { + fillRegistries(); + } + + @AfterClass + public static void teardownClass() { + resetRegistries(); + } + + /** + * Tests merging a move an enumeration literal from one enumeration to another. + * <p> + * The model contains two enumerations, <i>Enumeration1</i> and <i>Enumeration2</i>. On the left-hand + * side, <i>Enumeration1</i> contains a literal. On the right-hand side, this literal is contained by + * <i>Enumeration2</i> instead. This test merges in both directions. + * </p> + * + * @throws IOException + * Thrown if example model could not be read. + */ + @Test + public void testMergeOfMovedEnumerationLiteral() throws IOException { + final Resource left = input.getInstanceSpec1Left(); + final Resource right = input.getInstanceSpec1Right(); + testMergeBothDirections(left, right); + } + + /** + * Tests merging a the addition / deletion of an enumeration literal. + * <p> + * The model contains two enumerations, <i>Enumeration1</i> and <i>Enumeration2</i>. On the left-hand + * side, <i>Enumeration1</i> contains an enumeration literal. On the right-hand side, it doesn't. This + * test merges in both directions to test the addition and the deletion in the merger. + * </p> + * + * @throws IOException + * Thrown if example model could not be read. + */ + @Test + public void testMergeOfAddedOrDeletedEnumerationLiteral() throws IOException { + final Resource left = input.getInstanceSpec2Left(); + final Resource right = input.getInstanceSpec2Right(); + testMergeBothDirections(left, right); + } + + /** + * Tests merging a the addition / deletion of an instance specification's classifier. + * <p> + * The intention of this test is to make sure that we don't break the correct merging of normal instance + * specification classifiers, while still support correctly merging + * {@link EnumerationLiteral#getClassifier()}. + * </p> + * <p> + * The model contains two enumerations, <i>Enumeration1</i> and <i>Enumeration2</i>, and an instance + * specification. On the left-hand side, <i>Enumeration1</i> is a classifier of the instance + * specification. On the right-hand side, it doesn't. This test merges in both directions to test the + * addition and the deletion in the merger. + * </p> + * + * @throws IOException + * Thrown if example model could not be read. + */ + @Test + public void testMergeOfAddedOrDeletedInstanceSpecificationClassifier() throws IOException { + final Resource left = input.getInstanceSpec3Left(); + final Resource right = input.getInstanceSpec3Right(); + testMergeBothDirections(left, right); + } + + /** + * Tests merging a the change of an instance specification's classifier. + * <p> + * The intention of this test is to make sure that we don't break the correct merging of normal instance + * specification classifiers, while still support correctly merging + * {@link EnumerationLiteral#getClassifier()}. + * </p> + * <p> + * The model contains two enumerations, <i>Enumeration1</i> and <i>Enumeration2</i>, and an instance + * specification. On the left-hand side, <i>Enumeration1</i> is a classifier of the instance + * specification. On the right-hand side, the instance specification's classifier is <i>Enumeration2</i>. + * This test merges in both directions to test the addition and the deletion in the merger. + * </p> + * + * @throws IOException + * Thrown if example model could not be read. + */ + @Test + public void testMergeOfChangedInstanceSpecificationClassifier() throws IOException { + final Resource left = input.getInstanceSpec4Left(); + final Resource right = input.getInstanceSpec4Right(); + testMergeBothDirections(left, right); + } + + private void testMergeBothDirections(Resource left, Resource right) throws IOException { + testMergeLeftToRight(left, right, null); + reload(left, right); + testMergeRightToLeft(left, right, null); + reload(left, right); + testMergeLeftToRight(right, left, null); + reload(left, right); + testMergeRightToLeft(right, left, null); + } + + private void reload(Resource... resources) throws IOException { + for (Resource resource : resources) { + resource.unload(); + resource.load(Collections.EMPTY_MAP); + } + } +} diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/InstanceSpecificationClassifiersMergeInputData.java b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/InstanceSpecificationClassifiersMergeInputData.java new file mode 100644 index 000000000..a5d9b84c9 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/InstanceSpecificationClassifiersMergeInputData.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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: + * Philip Langer - initial API and implementation + *******************************************************************************/ +package org.eclipse.emf.compare.uml2.tests.merge.data; + +import java.io.IOException; + +import org.eclipse.emf.compare.uml2.tests.AbstractUMLInputData; +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.uml2.uml.resources.util.UMLResourcesUtil; + +public class InstanceSpecificationClassifiersMergeInputData extends AbstractUMLInputData { + public Resource getInstanceSpec1Left() throws IOException { + return loadFromClassLoader("instancespec1/left.uml", createResourceSet()); //$NON-NLS-1$ + } + + public Resource getInstanceSpec1Right() throws IOException { + return loadFromClassLoader("instancespec1/right.uml", createResourceSet()); //$NON-NLS-1$ + } + + public Resource getInstanceSpec2Left() throws IOException { + return loadFromClassLoader("instancespec2/left.uml", createResourceSet()); //$NON-NLS-1$ + } + + public Resource getInstanceSpec2Right() throws IOException { + return loadFromClassLoader("instancespec2/right.uml", createResourceSet()); //$NON-NLS-1$ + } + + public Resource getInstanceSpec3Left() throws IOException { + return loadFromClassLoader("instancespec3/left.uml", createResourceSet()); //$NON-NLS-1$ + } + + public Resource getInstanceSpec3Right() throws IOException { + return loadFromClassLoader("instancespec3/right.uml", createResourceSet()); //$NON-NLS-1$ + } + + public Resource getInstanceSpec4Left() throws IOException { + return loadFromClassLoader("instancespec4/left.uml", createResourceSet()); //$NON-NLS-1$ + } + + public Resource getInstanceSpec4Right() throws IOException { + return loadFromClassLoader("instancespec4/right.uml", createResourceSet()); //$NON-NLS-1$ + } + + private ResourceSet createResourceSet() { + final ResourceSet resourceSet = new ResourceSetImpl(); + UMLResourcesUtil.init(resourceSet); + return resourceSet; + } +} diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec1/left.uml b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec1/left.uml new file mode 100644 index 000000000..084a72aa9 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec1/left.uml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_rootElement" name="RootElement"> + <packageImport xmi:type="uml:PackageImport" xmi:id="_packageImport"> + <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/> + </packageImport> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration1" name="Enumeration1"> + <ownedLiteral xmi:type="uml:EnumerationLiteral" xmi:id="_literal1" name="Literal1"/> + </packagedElement> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration2" name="Enumeration2" /> +</uml:Model> diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec1/right.uml b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec1/right.uml new file mode 100644 index 000000000..b5a2a8705 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec1/right.uml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_rootElement" name="RootElement"> + <packageImport xmi:type="uml:PackageImport" xmi:id="_packageImport"> + <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/> + </packageImport> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration1" name="Enumeration1" /> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration2" name="Enumeration2"> + <ownedLiteral xmi:type="uml:EnumerationLiteral" xmi:id="_literal1" name="Literal1"/> + </packagedElement> +</uml:Model> diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec2/left.uml b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec2/left.uml new file mode 100644 index 000000000..084a72aa9 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec2/left.uml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_rootElement" name="RootElement"> + <packageImport xmi:type="uml:PackageImport" xmi:id="_packageImport"> + <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/> + </packageImport> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration1" name="Enumeration1"> + <ownedLiteral xmi:type="uml:EnumerationLiteral" xmi:id="_literal1" name="Literal1"/> + </packagedElement> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration2" name="Enumeration2" /> +</uml:Model> diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec2/right.uml b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec2/right.uml new file mode 100644 index 000000000..f78268a8e --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec2/right.uml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_rootElement" name="RootElement"> + <packageImport xmi:type="uml:PackageImport" xmi:id="_packageImport"> + <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/> + </packageImport> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration1" name="Enumeration1" /> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration2" name="Enumeration2" /> +</uml:Model> diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec3/left.uml b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec3/left.uml new file mode 100644 index 000000000..ad9ef3f35 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec3/left.uml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_rootElement" name="RootElement"> + <packageImport xmi:type="uml:PackageImport" xmi:id="_packageImport"> + <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/> + </packageImport> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration1" name="Enumeration1"> + <ownedLiteral xmi:type="uml:EnumerationLiteral" xmi:id="_literal1" name="Literal1"/> + </packagedElement> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration2" name="Enumeration2" /> + <packagedElement xmi:type="uml:InstanceSpecification" xmi:id="_instanceSpecification" name="InstanceSpecification" classifier="_enumeration1"/> +</uml:Model> diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec3/right.uml b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec3/right.uml new file mode 100644 index 000000000..b01c02219 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec3/right.uml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_rootElement" name="RootElement"> + <packageImport xmi:type="uml:PackageImport" xmi:id="_packageImport"> + <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/> + </packageImport> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration1" name="Enumeration1"> + <ownedLiteral xmi:type="uml:EnumerationLiteral" xmi:id="_literal1" name="Literal1"/> + </packagedElement> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration2" name="Enumeration2" /> + <packagedElement xmi:type="uml:InstanceSpecification" xmi:id="_instanceSpecification" name="InstanceSpecification"/> +</uml:Model> diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec4/left.uml b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec4/left.uml new file mode 100644 index 000000000..ad9ef3f35 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec4/left.uml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_rootElement" name="RootElement"> + <packageImport xmi:type="uml:PackageImport" xmi:id="_packageImport"> + <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/> + </packageImport> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration1" name="Enumeration1"> + <ownedLiteral xmi:type="uml:EnumerationLiteral" xmi:id="_literal1" name="Literal1"/> + </packagedElement> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration2" name="Enumeration2" /> + <packagedElement xmi:type="uml:InstanceSpecification" xmi:id="_instanceSpecification" name="InstanceSpecification" classifier="_enumeration1"/> +</uml:Model> diff --git a/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec4/right.uml b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec4/right.uml new file mode 100644 index 000000000..5dac7dab7 --- /dev/null +++ b/plugins/org.eclipse.emf.compare.uml2.tests/src/org/eclipse/emf/compare/uml2/tests/merge/data/instancespec4/right.uml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_rootElement" name="RootElement"> + <packageImport xmi:type="uml:PackageImport" xmi:id="_packageImport"> + <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/> + </packageImport> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration1" name="Enumeration1"> + <ownedLiteral xmi:type="uml:EnumerationLiteral" xmi:id="_literal1" name="Literal1"/> + </packagedElement> + <packagedElement xmi:type="uml:Enumeration" xmi:id="_enumeration2" name="Enumeration2" /> + <packagedElement xmi:type="uml:InstanceSpecification" xmi:id="_instanceSpecification" name="InstanceSpecification" classifier="_enumeration2"/> +</uml:Model> |