Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2018-04-24 15:57:09 +0000
committerNicolas FAUVERGUE2018-05-14 15:15:01 +0000
commit044dc1170629e1657f39305fdaf900abca5a7aa1 (patch)
treeb656954fda95873d62852e982786b15a0cb56759
parenteb963d6206eeed64210d2ac31caa880cd8489caf (diff)
downloadorg.eclipse.papyrus-044dc1170629e1657f39305fdaf900abca5a7aa1.tar.gz
org.eclipse.papyrus-044dc1170629e1657f39305fdaf900abca5a7aa1.tar.xz
org.eclipse.papyrus-044dc1170629e1657f39305fdaf900abca5a7aa1.zip
Bug 533671: [Sequence Diagram] CombinedFragment should be created on Lifeline and Interaction
Add test coverage for combined fragment creation on lifelines. Change-Id: I9657a74b412fab102422b33e6b85956bdb43f3ae Signed-off-by: Christian W. Damus <give.a.damus@gmail.com>
-rw-r--r--tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java16
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java77
2 files changed, 84 insertions, 9 deletions
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
index 932b51085ee..759cf747fb5 100644
--- a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
+++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java
@@ -23,9 +23,8 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
+import java.util.Objects;
import java.util.function.Supplier;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.eclipse.core.commands.operations.IOperationHistory;
@@ -79,7 +78,6 @@ import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
@@ -93,6 +91,7 @@ import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramEditPartsUtil;
import org.eclipse.papyrus.infra.nattable.common.editor.AbstractEMFNattableEditor;
import org.eclipse.papyrus.infra.nattable.common.modelresource.PapyrusNattableModel;
import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
@@ -136,7 +135,6 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
/**
@@ -1493,17 +1491,17 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit
public EditPart createShape(EditPart parent, IElementType type, Point location, Dimension size) {
CreateViewRequest request = CreateViewRequestFactory.getCreateShapeRequest(type, ((IGraphicalEditPart) parent).getDiagramPreferencesHint());
- // Collect existing children
- Set<EditPart> initialChildren = stream(parent.getChildren(), EditPart.class).collect(Collectors.toSet());
request.setLocation(location);
request.setSize(size);
org.eclipse.gef.commands.Command command = parent.getCommand(request);
execute(command);
// Find the new edit-part
- Set<EditPart> children = stream(parent.getChildren(), EditPart.class).collect(Collectors.toSet());
- return Sets.difference(children, initialChildren).stream()
- .filter(ep -> ep.getModel() instanceof Shape)
+ return request.getViewDescriptors().stream()
+ .map(desc -> desc.getAdapter(View.class)).map(View.class::cast)
+ .filter(Objects::nonNull)
+ .map(view -> DiagramEditPartsUtil.getEditPartFromView(view, parent))
+ .filter(Objects::nonNull)
.findAny().orElseGet(failOnAbsence("Could not find new shape edit-part"));
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java
index d6263afc498..92f61b1cbef 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.sequence.tests/src/org/eclipse/papyrus/uml/diagram/sequence/tests/bug/CombinedFragmentRegressionTest.java
@@ -15,6 +15,7 @@ package org.eclipse.papyrus.uml.diagram.sequence.tests.bug;
import static org.eclipse.papyrus.junit.matchers.MoreMatchers.greaterThan;
import static org.eclipse.papyrus.junit.matchers.MoreMatchers.isEmpty;
+import static org.eclipse.papyrus.junit.matchers.MoreMatchers.lessThan;
import static org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture.at;
import static org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture.sized;
import static org.hamcrest.CoreMatchers.hasItem;
@@ -45,6 +46,7 @@ import org.eclipse.uml2.uml.ExecutionSpecification;
import org.eclipse.uml2.uml.Interaction;
import org.eclipse.uml2.uml.InteractionFragment;
import org.eclipse.uml2.uml.InteractionOperand;
+import org.eclipse.uml2.uml.Lifeline;
import org.junit.Rule;
import org.junit.Test;
@@ -282,4 +284,79 @@ public class CombinedFragmentRegressionTest extends AbstractPapyrusTest {
assertThat("Fragments of deleted operand not retained",
interaction.getFragments(), hasItems(deleteSend, deleted));
}
+
+ /**
+ * Verify the creation of a combined fragment by just dropping the tool on a
+ * lifeline.
+ */
+ @Test
+ @PluginResource("resource/bugs/bug533673.di")
+ public void createCFragOnLifeline_533671() {
+ GraphicalEditPart lifelineEP = (GraphicalEditPart) editor.findEditPart("a", Lifeline.class);
+
+ // Null size to just drop the tool
+ GraphicalEditPart combinedFragmentEP = (GraphicalEditPart) editor.createShape(lifelineEP, UMLElementTypes.CombinedFragment_Shape, at(80, 80), null);
+
+ Consumer<GraphicalEditPart> verifyCFrag = cfragEP -> {
+ assertThat(cfragEP, DiagramMatchers.semanticThat(instanceOf(CombinedFragment.class)));
+ assertThat("Combined fragment is not a peer of the lifeline", cfragEP.getParent(), is(lifelineEP.getParent()));
+ Rectangle lifelineBounds = lifelineEP.getFigure().getBounds();
+ Rectangle cfragBounds = cfragEP.getFigure().getBounds();
+ assertThat("Combined fragment not bounded by the lifeline", lifelineBounds.contains(cfragBounds), is(true));
+ };
+ verifyCFrag.accept(combinedFragmentEP);
+
+ CombinedFragment cfrag = (CombinedFragment) combinedFragmentEP.getAdapter(EObject.class);
+
+ editor.undo();
+
+ combinedFragmentEP = (GraphicalEditPart) editor.findEditPart(cfrag);
+ assertThat("Combined fragment still present in the diagram", combinedFragmentEP, nullValue());
+
+ editor.redo();
+
+ combinedFragmentEP = (GraphicalEditPart) editor.findEditPart(cfrag);
+ verifyCFrag.accept(combinedFragmentEP);
+ }
+
+ /**
+ * Verify the creation of a combined fragment by drawing the tool out over
+ * a pair of lifelines.
+ */
+ @Test
+ @PluginResource("resource/bugs/bug533673.di")
+ public void createCFragOverLifelines_533671() {
+ GraphicalEditPart aEP = (GraphicalEditPart) editor.findEditPart("a", Lifeline.class);
+ GraphicalEditPart bEP = (GraphicalEditPart) editor.findEditPart("b", Lifeline.class);
+ GraphicalEditPart interactionCompartment = (GraphicalEditPart) aEP.getParent();
+
+ GraphicalEditPart combinedFragmentEP = (GraphicalEditPart) editor.createShape(
+ interactionCompartment, UMLElementTypes.CombinedFragment_Shape,
+ at(25, 80), sized(360, 200));
+
+ Consumer<GraphicalEditPart> verifyCFrag = cfragEP -> {
+ assertThat(cfragEP, DiagramMatchers.semanticThat(instanceOf(CombinedFragment.class)));
+ assertThat("Combined fragment not contained in interaction compartment", cfragEP.getParent(), is(interactionCompartment));
+ Rectangle aBounds = aEP.getFigure().getBounds();
+ Rectangle bBounds = bEP.getFigure().getBounds();
+ Rectangle cfragBounds = cfragEP.getFigure().getBounds();
+ assertThat("Combined fragment does not extend east of lifeline a",
+ aBounds.x(), greaterThan(cfragBounds.x()));
+ assertThat("Combined fragment does not extend west of lifeline b",
+ bBounds.right(), lessThan(cfragBounds.right()));
+ };
+ verifyCFrag.accept(combinedFragmentEP);
+
+ CombinedFragment cfrag = (CombinedFragment) combinedFragmentEP.getAdapter(EObject.class);
+
+ editor.undo();
+
+ combinedFragmentEP = (GraphicalEditPart) editor.findEditPart(cfrag);
+ assertThat("Combined fragment still present in the diagram", combinedFragmentEP, nullValue());
+
+ editor.redo();
+
+ combinedFragmentEP = (GraphicalEditPart) editor.findEditPart(cfrag);
+ verifyCFrag.accept(combinedFragmentEP);
+ }
}

Back to the top