diff options
author | Christian W. Damus | 2018-04-25 20:28:05 +0000 |
---|---|---|
committer | Nicolas FAUVERGUE | 2018-05-14 15:15:01 +0000 |
commit | 3ef042ffd8437bcc54f7b2258bcea0b6962f110c (patch) | |
tree | 2c95fb747c64ef6d66fbf61c84f315c1a74a9093 /tests/junit | |
parent | ffad788980af9a4d5dc533f283a29915cc13a786 (diff) | |
download | org.eclipse.papyrus-3ef042ffd8437bcc54f7b2258bcea0b6962f110c.tar.gz org.eclipse.papyrus-3ef042ffd8437bcc54f7b2258bcea0b6962f110c.tar.xz org.eclipse.papyrus-3ef042ffd8437bcc54f7b2258bcea0b6962f110c.zip |
Bug 533699: [Sequence Diagram] InteractionOperand Guard should not be moved
Disable moving of interaction operand guards. Resize was already
disabled. Add JUnit test coverage for both move and resize.
Change-Id: Ibbb29ff64f684b184be1efc6142f7c35df218399
Signed-off-by: Christian W. Damus <give.a.damus@gmail.com>
Diffstat (limited to 'tests/junit')
2 files changed, 87 insertions, 5 deletions
diff --git a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java index 3cd355c83b3..c8e7f58f9fc 100644 --- a/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java +++ b/tests/junit/framework/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/matchers/CommandMatchers.java @@ -17,7 +17,7 @@ import java.util.function.Predicate; import org.hamcrest.Description; import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; +import org.hamcrest.TypeSafeDiagnosingMatcher; /** * Matchers for commands of various flavours, which are defined in nested classes. @@ -34,15 +34,21 @@ public final class CommandMatchers { } static <C> Matcher<C> executable(Predicate<? super C> canExecute) { - return new TypeSafeMatcher<C>() { + return new TypeSafeDiagnosingMatcher<C>() { @Override public void describeTo(Description description) { - description.appendText("unexecutable"); + description.appendText("executable"); } @Override - protected boolean matchesSafely(C item) { - return canExecute.test(item); + protected boolean matchesSafely(C item, Description mismatch) { + boolean result = canExecute.test(item); + + if (!result) { + mismatch.appendText("unexecutable"); + } + + return result; } }; } 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 83a0afbdb6f..5cdd09f531b 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 @@ -34,12 +34,22 @@ import static org.junit.Assume.assumeThat; import java.util.Arrays; import java.util.List; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.PositionConstants; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.emf.ecore.EObject; import org.eclipse.gef.EditPart; import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.RequestConstants; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest; import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory; @@ -523,6 +533,72 @@ public class CombinedFragmentRegressionTest extends AbstractPapyrusTest { .or(instanceOf(Comment.class))))); } + /** + * Verify that the guard of an interaction operand cannot be moved. + */ + @Test + @PluginResource("resource/bugs/bug533681.di") + public void attemptToMoveOperandGuard_533699() { + operandGuardUnchangeable("move", ep -> { + Rectangle currentBounds = ep.getFigure().getBounds(); + ChangeBoundsRequest result = new ChangeBoundsRequest(RequestConstants.REQ_MOVE); + Point moveDelta = new Point(5, 5); // Just a nudge + Point newLoc = currentBounds.getLocation().getTranslated(moveDelta); + result.setLocation(newLoc); // Within the constraint shape + result.setMoveDelta(moveDelta); + result.setConstrainedMove(false); + result.setSnapToEnabled(false); + return result; + }); + } + + private void operandGuardUnchangeable(String action, Function<? super GraphicalEditPart, ? extends Request> requestFunction) { + EditPart combinedFragmentEP = editor.findEditPart("cfrag", CombinedFragment.class); + CombinedFragment cfrag = (CombinedFragment) combinedFragmentEP.getAdapter(EObject.class); + Interaction interaction = cfrag.getEnclosingInteraction(); + assumeThat("No interaction", interaction, notNullValue()); + + InteractionOperand alt1 = cfrag.getOperand("alt1"); + Constraint alt1Guard = alt1.getGuard(); + InteractionOperand alt2 = cfrag.getOperand("alt2"); + Constraint alt2Guard = alt2.getGuard(); + + List<GraphicalEditPart> guardEPs = Stream.of(alt1Guard, alt2Guard) + .map(g -> editor.requireEditPart(editor.getActiveDiagram(), g)) + .filter(GraphicalEditPart.class::isInstance).map(GraphicalEditPart.class::cast) + .collect(Collectors.toList()); + assertThat(guardEPs.size(), greaterThanOrEqual(2)); + + guardEPs.forEach(ep -> { + Request request = requestFunction.apply(ep); + + EditPart target = ep.getTargetEditPart(request); + if (target != null) { + Command command = target.getCommand(request); + assertThat("Can " + action + " guard", command, not(CommandMatchers.GEF.canExecute())); + } // null target EP is a way to disable the request + }); + } + + /** + * Verify that the guard of an interaction operand cannot be resized. + */ + @Test + @PluginResource("resource/bugs/bug533681.di") + public void attemptToResizeOperandGuard_533699() { + operandGuardUnchangeable("resize", ep -> { + Rectangle currentBounds = ep.getFigure().getBounds(); + ChangeBoundsRequest result = new ChangeBoundsRequest(RequestConstants.REQ_RESIZE); + result.setLocation(currentBounds.getBottomRight()); + result.setSizeDelta(new Dimension(5, 5)); // Just a tweak + result.setResizeDirection(PositionConstants.SOUTH_WEST); + result.setConstrainedResize(false); + result.setCenteredResize(false); + result.setSnapToEnabled(false); + return result; + }); + } + // // Test framework // |