diff options
author | Christian W. Damus | 2016-07-16 13:51:36 +0000 |
---|---|---|
committer | Christian W. Damus | 2016-07-16 14:49:02 +0000 |
commit | 8913218f77d1bbe0d9a42be8e13dcde8494a4e04 (patch) | |
tree | 1501e0c31a9f24a13f3c9abca0516845eb94c6b7 /tests/junit/extraplugins | |
parent | 86cfd7f722ea4f8f45a683024f50af247b8373af (diff) | |
download | org.eclipse.papyrus-8913218f77d1bbe0d9a42be8e13dcde8494a4e04.tar.gz org.eclipse.papyrus-8913218f77d1bbe0d9a42be8e13dcde8494a4e04.tar.xz org.eclipse.papyrus-8913218f77d1bbe0d9a42be8e13dcde8494a4e04.zip |
Bug 496653: [Model Import] Align header of imported capsule structure diagram
https://bugs.eclipse.org/bugs/show_bug.cgi?id=496653
Ensure that name labels are emitted as the first child of a node,
because some edit-parts require this in order to properly separate
the name from nested compartments.
Change-Id: I8e39cedfdcbadd2d46432fb6074dbaec9f0c5ac7
(cherry picked from commit 918478c20388983b69f52b8d797b6d0eefbfc61d)
Diffstat (limited to 'tests/junit/extraplugins')
2 files changed, 109 insertions, 8 deletions
diff --git a/tests/junit/extraplugins/migration/org.eclipse.papyrus.migration.rsa.tests/src/org/eclipse/papyrus/migration/rsa/tests/qvt/AbstractTransformationTest.java b/tests/junit/extraplugins/migration/org.eclipse.papyrus.migration.rsa.tests/src/org/eclipse/papyrus/migration/rsa/tests/qvt/AbstractTransformationTest.java index e2507af0b31..c0210f1439f 100644 --- a/tests/junit/extraplugins/migration/org.eclipse.papyrus.migration.rsa.tests/src/org/eclipse/papyrus/migration/rsa/tests/qvt/AbstractTransformationTest.java +++ b/tests/junit/extraplugins/migration/org.eclipse.papyrus.migration.rsa.tests/src/org/eclipse/papyrus/migration/rsa/tests/qvt/AbstractTransformationTest.java @@ -8,15 +8,22 @@ * * Contributors: * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation - * Christian W. Damus - bugs 496439, 461980 + * Christian W. Damus - bugs 496439, 461980, 496653 *****************************************************************************/ package org.eclipse.papyrus.migration.rsa.tests.qvt; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; + import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Objects; +import java.util.Queue; import java.util.stream.Collectors; import java.util.stream.StreamSupport; @@ -24,10 +31,13 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.core.resource.ModelSet; import org.eclipse.papyrus.infra.core.utils.ServiceUtils; import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject; @@ -43,10 +53,15 @@ import org.eclipse.papyrus.migration.rsa.transformation.ImportTransformation; import org.eclipse.papyrus.migration.rsa.transformation.ImportTransformationLauncher; import org.eclipse.papyrus.uml.tools.model.UmlModel; import org.eclipse.uml2.uml.Package; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Matcher; import org.junit.Assert; import org.junit.Before; import org.junit.Rule; +import com.google.common.collect.Queues; + public class AbstractTransformationTest extends AbstractPapyrusTest { @Rule @@ -118,13 +133,18 @@ public class AbstractTransformationTest extends AbstractPapyrusTest { } protected Diagram openDiagram(String name) throws Exception { + Diagram result = getDiagram(name); + ServiceUtilsForEObject.getInstance().getIPageManager(result).openPage(result); + DisplayUtils.flushEventLoop(); + return result; + } + + protected Diagram getDiagram(String name) throws Exception { List<Diagram> diagrams = getDiagrams(); Diagram result = diagrams.stream() .filter(d -> name.equals(d.getName())) .findAny() .orElseThrow(AssertionError::new); - ServiceUtilsForEObject.getInstance().getIPageManager(result).openPage(result); - DisplayUtils.flushEventLoop(); return result; } @@ -246,4 +266,63 @@ public class AbstractTransformationTest extends AbstractPapyrusTest { Assert.assertNotEquals("RSA Profiles should not be reference anymore", "epx", fileExtension); } } + + @SuppressWarnings("unchecked") + protected EList<View> children(View view) { + return view.getChildren(); + } + + protected View requireChild(View view, String type) { + View result = ViewUtil.getChildBySemanticHint(view, type); + assertThat("No child of type " + type, result, notNullValue()); + return result; + } + + protected <T extends View> T requireChild(View view, String type, Class<T> ofClass) { + View result = requireChild(view, type); + assertThat(result, instanceOf(ofClass)); + return ofClass.cast(result); + } + + @SafeVarargs + protected final <T> Matcher<Iterable<? extends T>> containsInOrder(T... elements) { + List<T> expected = Arrays.asList(elements); + + return new BaseMatcher<Iterable<? extends T>>() { + @Override + public void describeTo(Description description) { + description.appendText("contains ") + .appendValueList("(", ", ", ")", Arrays.asList(elements)) + .appendText(" in order"); + } + + @Override + public boolean matches(Object item) { + boolean result; + + if (!(item instanceof Iterable<?>)) { + result = false; + } else { + Queue<T> queue = Queues.newArrayDeque(expected); + Iterator<?> iter = ((Iterable<?>) item).iterator(); + for (T next = queue.peek(); (next != null) && iter.hasNext(); next = queue.peek()) { + while (iter.hasNext()) { + if (Objects.equals(iter.next(), next)) { + // Matched the next in the expected order. Advance + queue.remove(); + break; + } + } + } + + // Did we find them all, in order? + result = queue.isEmpty(); + } + + return result; + } + }; + + + } } diff --git a/tests/junit/extraplugins/migration/org.eclipse.papyrus.migration.rsa.tests/src/org/eclipse/papyrus/migration/rsa/tests/regression/StructureDiagramTest.java b/tests/junit/extraplugins/migration/org.eclipse.papyrus.migration.rsa.tests/src/org/eclipse/papyrus/migration/rsa/tests/regression/StructureDiagramTest.java index ed89f33b913..a184ed5c1f7 100644 --- a/tests/junit/extraplugins/migration/org.eclipse.papyrus.migration.rsa.tests/src/org/eclipse/papyrus/migration/rsa/tests/regression/StructureDiagramTest.java +++ b/tests/junit/extraplugins/migration/org.eclipse.papyrus.migration.rsa.tests/src/org/eclipse/papyrus/migration/rsa/tests/regression/StructureDiagramTest.java @@ -17,13 +17,16 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; +import java.util.List; + import org.eclipse.gmf.runtime.notation.Diagram; import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.Size; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.migration.rsa.tests.qvt.AbstractTransformationTest; +import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeCompartmentEditPart; import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeEditPart; +import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeNameEditPart; import org.junit.Test; /** @@ -50,13 +53,32 @@ public class StructureDiagramTest extends AbstractTransformationTest { // Need to open the diagram to convert the visual IDs to modern notation for assertions Diagram diagram = openDiagram("StructureDiagram1"); - View frameView = ViewUtil.getChildBySemanticHint(diagram, ClassCompositeEditPart.VISUAL_ID); - assertThat(frameView, instanceOf(Node.class)); - - Node frame = (Node) frameView; + Node frame = requireChild(diagram, ClassCompositeEditPart.VISUAL_ID, Node.class); assertThat(frame.getLayoutConstraint(), instanceOf(Size.class)); Size size = (Size) frame.getLayoutConstraint(); assertThat(size.getWidth(), is(600)); assertThat(size.getHeight(), is(400)); } + + /** + * @see <a href="http://eclip.se/496653">bug 496653</a> + */ + @Test + public void dividerBetweenNameAndStructureCompartment_bug496653() throws Exception { + simpleImport("resources/bug461980/CompositeStructureDiagram.emx"); + + openEditor(); + + // Need to open the diagram to convert the visual IDs to modern notation for assertions + Diagram diagram = openDiagram("StructureDiagram1"); + + View frame = requireChild(diagram, ClassCompositeEditPart.VISUAL_ID); + + View name = requireChild(frame, ClassCompositeNameEditPart.VISUAL_ID); + View structure = requireChild(frame, ClassCompositeCompartmentEditPart.VISUAL_ID); + + @SuppressWarnings("unchecked") + List<? extends View> children = frame.getChildren(); + assertThat(children, containsInOrder(name, structure)); + } } |