Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2018-01-12 14:01:41 +0000
committervincent lorenzo2018-01-13 18:11:23 +0000
commit01c51a363a937b8fc64b0b37a8434517a34d6dd5 (patch)
treef80722b2a52602738a70fbca8a283d4f61d833bd /tests/junit
parente21394efd4533fbff89fe60f21d60bc7ebc760bb (diff)
downloadorg.eclipse.papyrus-01c51a363a937b8fc64b0b37a8434517a34d6dd5.tar.gz
org.eclipse.papyrus-01c51a363a937b8fc64b0b37a8434517a34d6dd5.tar.xz
org.eclipse.papyrus-01c51a363a937b8fc64b0b37a8434517a34d6dd5.zip
Bug 450921 - Additional graphics no longer available
- add tests Change-Id: I495a152b8f41d54689dfc39ca8ac28044c0f509a Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'tests/junit')
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/canonical/AllCanonicalTests.java6
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/canonical/TestGeoshapes.java159
2 files changed, 163 insertions, 2 deletions
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/canonical/AllCanonicalTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/canonical/AllCanonicalTests.java
index e526930ed27..defed4f6306 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/canonical/AllCanonicalTests.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/canonical/AllCanonicalTests.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * Copyright (c) 2013, 2018 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* Nizar GUEDIDI (CEA LIST) - Initial API and implementation
+ * Vincent LORENZO (CEA LIST) vincent.lorenzo@cea.fr - bug 450921
/*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.component.test.canonical;
@@ -44,7 +45,8 @@ import org.junit.runners.Suite.SuiteClasses;
TestListCompartmentPropertiesOperationsDrop.class,
TestComponentDiagramConnector.class,
TestComponentDiagramPortLink.class,
- TestPortLocation.class
+ TestPortLocation.class,
+ TestGeoshapes.class
// End
})
public class AllCanonicalTests {
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/canonical/TestGeoshapes.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/canonical/TestGeoshapes.java
new file mode 100644
index 00000000000..06400d80a8c
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component.tests/src/org/eclipse/papyrus/uml/diagram/component/test/canonical/TestGeoshapes.java
@@ -0,0 +1,159 @@
+/*****************************************************************************
+ * Copyright (c) 2015, 2018 CEA LIST 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.component.test.canonical;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.Bounds;
+import org.eclipse.gmf.runtime.notation.LayoutConstraint;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.junit.Test;
+
+/**
+ * Check ability to create geoshapes
+ */
+@SuppressWarnings("nls")
+public class TestGeoshapes extends AbstractPapyrusTestCase {
+
+ @Test
+ public void testCreationNote() {
+ IGraphicalEditPart diagram = getDiagramEditPart();
+ Point p = selectEditpart(diagram);
+ List<String> menuChain = Arrays.asList(new String[]{"Add", "&Note"});
+ selectMenu(diagram, p, menuChain);
+ }
+
+ @Test
+ public void testCreationTriangle() {
+ IGraphicalEditPart diagram = getDiagramEditPart();
+ Point p = selectEditpart(diagram);
+ List<String> menuChain = Arrays.asList(new String[]{"Add", "Tri&angle"});
+ selectMenu(diagram, p, menuChain);
+ }
+
+ protected void selectMenu(IGraphicalEditPart dc, Point p, List<String> chain) {
+ Control control = getDiagramEditPart().getViewer().getControl();
+ Menu menu = control.getMenu();
+ Event event = createEvent();
+ event.widget = control;
+ event.x = p.x;
+ event.y = p.y;
+ MenuItem item = findItem(menu, chain.iterator(), event);
+ StringBuilder menuChain = new StringBuilder();
+ for (int i = 0 ; i < chain.size(); i++) {
+ if (i != 0) {
+ menuChain.append("->");
+ }
+ menuChain.append(chain.get(i));
+ }
+ assertNotNull("Menu item was not found:" + menuChain.toString(),item);
+ assertTrue("Menu was not enabled", item.getEnabled());
+ }
+
+ private MenuItem findItem(Menu menu, Iterator<String> chain, Event event) {
+ menu.notifyListeners(SWT.Show, event);
+ menu.setVisible(true);
+ String text = chain.next();
+ for (MenuItem item: menu.getItems()) {
+ if (item.getText().contains(text)) {
+ return chain.hasNext() ? findItem(item.getMenu(), chain, event) : item;
+ }
+ }
+ return null;
+ }
+
+ protected Event createMouseEvent(int x, int y, int button, int stateMask, int count) {
+ Event event = new Event();
+ event.time = (int) System.currentTimeMillis();
+ event.widget = null;
+ event.display = Display.getDefault();
+ event.x = x;
+ event.y = y;
+ event.button = button;
+ event.stateMask = stateMask;
+ event.count = count;
+ return event;
+ }
+
+ protected Event createEvent() {
+ Event event = new Event();
+ event.time = (int) System.currentTimeMillis();
+ event.widget = null;
+ event.display = Display.getDefault();
+ return event;
+ }
+
+ protected Event createSelectionEvent(int stateMask) {
+ Event event = createEvent();
+ event.stateMask = stateMask;
+ return event;
+ }
+
+ private Point selectEditpart(IGraphicalEditPart dc) {
+ // select edit part
+ Control control = dc.getViewer().getControl();
+ Point p = getAbsoluteBounds(dc).getCenter();
+ Event event = createMouseEvent(p.x, p.y, 1, SWT.NONE, 1);
+ event.type = SWT.MouseDown;
+ event.widget = control;
+ control.notifyListeners(SWT.MouseDown, event);
+ event.type = SWT.MouseUp;
+ control.notifyListeners(SWT.MouseUp, event);
+ return p;
+ }
+
+ public static Rectangle getAbsoluteBounds(IGraphicalEditPart part) {
+ // take bounds from figure
+ Rectangle bounds = part.getFigure().getBounds().getCopy();
+
+ if(part.getNotationView() instanceof Node) {
+ // rather update with up to date model bounds
+ Node node = (Node)part.getNotationView();
+ LayoutConstraint cst = node.getLayoutConstraint();
+ if(cst instanceof Bounds) {
+ Bounds b = (Bounds)cst;
+ Point parentLoc = part.getFigure().getParent().getBounds().getLocation();
+ if(b.getX() > 0) {
+ bounds.x = b.getX() + parentLoc.x;
+ }
+ if(b.getY() > 0) {
+ bounds.y = b.getY() + parentLoc.y;
+ }
+ if(b.getHeight() != -1) {
+ bounds.height = b.getHeight();
+ }
+ if(b.getWidth() != -1) {
+ bounds.width = b.getWidth();
+ }
+ }
+ }
+
+ part.getFigure().getParent().translateToAbsolute(bounds);
+ return bounds;
+ }
+}

Back to the top