Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmallet2017-08-11 16:04:10 +0000
committerLaurent Redor2017-09-01 14:11:17 +0000
commit089ecb94010986c6cdd7a5d86c90a558693ed000 (patch)
tree6de768e218df07fe9cd8468f5ccdc440208a56cb
parent6576c03bceb2fc723b55bf5b694f1f5fc71d9d9c (diff)
downloadorg.eclipse.sirius-089ecb94010986c6cdd7a5d86c90a558693ed000.tar.gz
org.eclipse.sirius-089ecb94010986c6cdd7a5d86c90a558693ed000.tar.xz
org.eclipse.sirius-089ecb94010986c6cdd7a5d86c90a558693ed000.zip
[520632] Add multiple borderNode creation test with snapToGrid.
Addition of test to check multiple BorderNode creation with snapToGrid activated, i.e. many new border node are aligned on the grid. Bug: 520632 Change-Id: I463d0687e31a3e8581649129b059a361299dc621 Signed-off-by: jmallet <jessy.mallet@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.odesign15
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java7
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationWithSnapToGridTest.java68
3 files changed, 77 insertions, 13 deletions
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.odesign b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.odesign
index 503fc5bbb2..61cfccdfe7 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.odesign
+++ b/plugins/org.eclipse.sirius.tests.swtbot/data/unit/tools/creation/borderedNode/borderedNode.odesign
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ASCII"?>
-<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:filter="http://www.eclipse.org/sirius/diagram/description/filter/1.1.0" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:tool="http://www.eclipse.org/sirius/diagram/description/tool/1.1.0" xmlns:tool_1="http://www.eclipse.org/sirius/description/tool/1.1.0" version="8.1.0">
+<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:filter="http://www.eclipse.org/sirius/diagram/description/filter/1.1.0" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:tool="http://www.eclipse.org/sirius/diagram/description/tool/1.1.0" xmlns:tool_1="http://www.eclipse.org/sirius/description/tool/1.1.0" version="12.0.0.2017041100">
<ownedViewpoints name="BorderedNode" modelFileExtension="ecore">
<ownedRepresentations xsi:type="description_1:DiagramDescription" name="BorderedNodeDiagram" label="BorderedNodeDiagram" domainClass="EPackage">
<filters xsi:type="filter:CompositeFilterDescription" name="collapse">
@@ -52,7 +52,7 @@
<color xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='dark_orange']"/>
</style>
</borderedNodeMappings>
- <style xsi:type="style:ShapeContainerStyleDescription">
+ <style xsi:type="style:ShapeContainerStyleDescription" arcWidth="1" arcHeight="1" borderSizeComputationExpression="1">
<borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
<labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/>
<backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/>
@@ -114,6 +114,17 @@
</firstModelOperations>
</initialOperation>
</ownedTools>
+ <ownedTools xsi:type="tool:NodeCreationDescription" name="Enum2" forceRefresh="true" nodeMappings="//@ownedViewpoints[name='BorderedNode']/@ownedRepresentations[name='BorderedNodeDiagram']/@defaultLayer/@containerMappings[name='Package']/@borderedNodeMappings[name='Enum']">
+ <variable name="container"/>
+ <viewVariable name="containerView"/>
+ <initialOperation>
+ <firstModelOperations xsi:type="tool_1:ChangeContext" browseExpression="var:self">
+ <subModelOperations xsi:type="tool_1:CreateInstance" typeName="EEnum" referenceName="eClassifiers">
+ <subModelOperations xsi:type="tool_1:SetValue" featureName="name" valueExpression="aql:'new Enum'+self.eContainer().eContents()->filter(ecore::EEnum)->size()"/>
+ </subModelOperations>
+ </firstModelOperations>
+ </initialOperation>
+ </ownedTools>
<ownedTools xsi:type="tool:NodeCreationDescription" name="CollapsedAttribute" forceRefresh="true" nodeMappings="//@ownedViewpoints[name='BorderedNode']/@ownedRepresentations[name='BorderedNodeDiagram']/@defaultLayer/@nodeMappings[name='Class']/@borderedNodeMappings[name='Attribute']">
<variable name="container"/>
<viewVariable name="containerView"/>
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java
index 09d9606cf0..6235269ff6 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationTest.java
@@ -69,7 +69,7 @@ public class BorderedNodeCreationTest extends AbstractSiriusSwtBotGefTestCase {
/**
* The name of the tool that create a bordered node on a package.
*/
- private static final String BORDERED_NODE_CREATION_ON_PACKAGE_TOOL_NAME = "Enum";
+ protected static final String BORDERED_NODE_CREATION_ON_PACKAGE_TOOL_NAME = "Enum";
/**
* The name of the tool that create a collapsed bordered node on a class (if
@@ -108,7 +108,8 @@ public class BorderedNodeCreationTest extends AbstractSiriusSwtBotGefTestCase {
private static final String PACKAGE_3_NAME = "P3";
- private static final String PACKAGE_4_NAME = "P4";
+ /** Name of the fourth package */
+ protected static final String PACKAGE_4_NAME = "P4";
private static final String CLASS_1_NAME = "Class1";
@@ -438,7 +439,7 @@ public class BorderedNodeCreationTest extends AbstractSiriusSwtBotGefTestCase {
* the name of the package to reveal before inserting the
* bordered node.
*/
- private void testBNC_OnContainer(ZoomLevel zoomLevel, String packageToRevealName) {
+ protected void testBNC_OnContainer(ZoomLevel zoomLevel, String packageToRevealName) {
testBNC_OnContainer(zoomLevel, packageToRevealName, null);
}
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationWithSnapToGridTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationWithSnapToGridTest.java
index 293e198d89..78eda6e89a 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationWithSnapToGridTest.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/BorderedNodeCreationWithSnapToGridTest.java
@@ -19,8 +19,10 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramBorderNodeEditPart;
+import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramContainerEditPart;
import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramNodeEditPart;
import org.eclipse.sirius.diagram.ui.internal.refresh.GMFHelper;
+import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper;
import org.eclipse.sirius.tests.swtbot.support.api.business.UIDiagramRepresentation.ZoomLevel;
import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
@@ -31,12 +33,17 @@ import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart;
*/
public class BorderedNodeCreationWithSnapToGridTest extends BorderedNodeCreationTest {
/**
- * The name of the tool that create a bordered node (that named
- * "new Attribute2" on a class.
+ * The name of the tool that create a bordered node (that named "new Attribute2" on a class.
*/
private static final String BORDERED_NODE_CREATION_ON_CLASS_2_TOOL_NAME = "Attribute2";
/**
+ * The name of the tool that create a bordered node (that named "new Enum"with number of Enum as suffix on a
+ * container.
+ */
+ private static final String BORDERED_NODE_CREATION_ON_PACKAGE_TOOL_NAME_2 = "Enum2";
+
+ /**
* The name of a new bordered node created on class with the above tool.
*/
private static final String NEW_BORDERED_NODE_ON_CLASS_2_NAME = "new Attribute2";
@@ -54,8 +61,8 @@ public class BorderedNodeCreationWithSnapToGridTest extends BorderedNodeCreation
}
/**
- * Ensures that 2 border nodes created at same location (forced with
- * snapToGrid) on a Node (zoom level : 100%) are not at same location.
+ * Ensures that 2 border nodes created at same location (forced with snapToGrid) on a Node (zoom level : 100%) are
+ * not at same location.
*/
public void testCreateTwoBorderNodesAtSameLocation() {
testBNC_OnNode(ZoomLevel.ZOOM_100, C1_NAME, false);
@@ -92,11 +99,34 @@ public class BorderedNodeCreationWithSnapToGridTest extends BorderedNodeCreation
}
/**
- * Only one of the coordinates is snap to grid. The other is constrained by
- * the parent border.
+ * Ensures that 2 border nodes created at same location (forced with snapToGrid) on a package (zoom level : 100%)
+ * are aligned on the grid. Indeed, Grid spacing is sufficient to have two border node aligned on the grid.
+ */
+ public void testCreateTwoBorderNodesAtSameLocationWithThinGridSpacing() {
+ int gridStep = 50;
+ editor.setSnapToGrid(true, gridStep, 2);
+
+ SWTBotGefEditPart packageP4 = editor.getEditPart(PACKAGE_4_NAME, AbstractDiagramContainerEditPart.class);
+ Rectangle packageAbsoluteBounds = editor.getAbsoluteBounds(packageP4);
+
+ // We compute the location according the top left package location
+ Point creationLocation = packageAbsoluteBounds.getTopLeft().translate(20, 20);
+
+ createBorderedNode(BORDERED_NODE_CREATION_ON_PACKAGE_TOOL_NAME_2, creationLocation.x, creationLocation.y);
+ createBorderedNode(BORDERED_NODE_CREATION_ON_PACKAGE_TOOL_NAME_2, creationLocation.x, creationLocation.y);
+
+ IGraphicalEditPart firstNewNode = (IGraphicalEditPart) editor.getEditPart("new Enum2", AbstractDiagramBorderNodeEditPart.class).part();
+ checkLocationAlignOnGrid(firstNewNode, "BorderNode 'new Enum2'");
+
+ IGraphicalEditPart secondNewNode = (IGraphicalEditPart) editor.getEditPart("new Enum3", AbstractDiagramBorderNodeEditPart.class).part();
+ checkLocationAlignOnGrid(secondNewNode, "BorderNode 'new Enum3'");
+ }
+
+ /**
+ * Only one of the coordinates is snap to grid. The other is constrained by the parent border.
*
- * @see org.eclipse.sirius.tests.swtbot.BorderedNodeCreationTest#assertSameLocation(String,
- * Point, Point, Point, Point, IGraphicalEditPart)
+ * @see org.eclipse.sirius.tests.swtbot.BorderedNodeCreationTest#assertSameLocation(String, Point, Point, Point,
+ * Point, IGraphicalEditPart)
*/
@Override
protected void assertSameLocation(String errorMessage, Point expectedLocation, Point nodeLocation, Point parentLocation, Point creationLocation, IGraphicalEditPart parentPart) {
@@ -146,4 +176,26 @@ public class BorderedNodeCreationWithSnapToGridTest extends BorderedNodeCreation
addParentScrollbar(figure.getParent(), location);
}
}
+
+ /**
+ * Check that a diagram element is aligned on the grid.
+ *
+ * @param editPart
+ * edit part of the diagram element to check
+ * @param elementNameToDisplay
+ * The name of the element displayed in case of error
+ */
+ private void checkLocationAlignOnGrid(IGraphicalEditPart editPart, String elementNameToDisplay) {
+ Point location = editPart.getFigure().getBounds().getTopLeft();
+ boolean locationIsOK = (location.x % GRID_SPACING) == 0 || (location.y % GRID_SPACING) == 0;
+ if (!locationIsOK) {
+ IGraphicalEditPart parentPart = (IGraphicalEditPart) editPart.getParent();
+ Rectangle parentBounds = GraphicalHelper.getAbsoluteBoundsIn100Percent(parentPart);
+ locationIsOK = (location.x == parentBounds.x || location.x == (parentBounds.x + parentBounds.width)) || (location.y == parentBounds.y || location.y == (parentBounds.y + parentBounds.height));
+ }
+ if (!locationIsOK) {
+ fail("For " + elementNameToDisplay + ", the x or y coordinate of the top left corner should be on the grid (grid spacing = " + GRID_SPACING + "), but was: " + location + ".");
+ }
+
+ }
}

Back to the top