Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBenoit Maggi2015-10-07 18:40:26 +0000
committerQuentin Le Menez2018-06-28 07:02:47 +0000
commit3ee0c59432c0d7b8b7fe3a25522b95cc881e6a34 (patch)
tree111cc38de29f8b44d679e14eb03ecadd76011302 /tests
parent00dee22840c69f6524a7b1792fbfd241d1b31125 (diff)
downloadorg.eclipse.papyrus-3ee0c59432c0d7b8b7fe3a25522b95cc881e6a34.tar.gz
org.eclipse.papyrus-3ee0c59432c0d7b8b7fe3a25522b95cc881e6a34.tar.xz
org.eclipse.papyrus-3ee0c59432c0d7b8b7fe3a25522b95cc881e6a34.zip
Bug 479122 - [Component] Should be possible to reroute connection
between component ports - allow connector re-routing - tests contribution Change-Id: I40c6948999d26e0c7382f5b406399eb213a4c278 Signed-off-by: ashatilov <shatilov@montages.com>
Diffstat (limited to 'tests')
-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.java11
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.tests/src/org/eclipse/papyrus/uml/diagram/tests/canonical/AbstractTestNode.java18
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.tests/src/org/eclipse/papyrus/uml/diagram/tests/canonical/TestDiagramConnector.java100
3 files changed, 116 insertions, 13 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 5ddc033d110..216739821db 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
@@ -22,30 +22,21 @@ import org.junit.runners.Suite.SuiteClasses;
*/
@RunWith(ClassificationSuite.class)
@SuiteClasses({
- // Top Node
TestComponentDiagramTopNode.class,
- // Child Node
TestComponentDiagramPackageChildNode.class,
- // child nodes in components
TestComponentDiagramComponentChildNode.class,
- // child nodes in interface
TestComponentDiagramChildLabel.class,
- // Link
TestComponentDiagramLink.class,
- // Link owned by source
TestComponentDiagramLinkOwnedBySource.class,
- // CommentLink
TestComponentDiagramCommentLink.class,
- // Constraint Link
TestComponentDiagramConstraintLink.class,
- // List compartment duplicates
TestListCompartmentNodeChildDuplicates.class,
- // List Compartment Illegal Elements
TestListCompartmentIllegalElements.class,
TestListCompartmentPropertiesOperationsDrop.class,
TestComponentDiagramConnector.class,
TestComponentDiagramPortLink.class,
TestPortLocation.class,
+ TestComponentDiagramConnector.class
})
public class AllCanonicalTests {
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.tests/src/org/eclipse/papyrus/uml/diagram/tests/canonical/AbstractTestNode.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.tests/src/org/eclipse/papyrus/uml/diagram/tests/canonical/AbstractTestNode.java
index 0ed56f0dc7c..12381adf82d 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.tests/src/org/eclipse/papyrus/uml/diagram/tests/canonical/AbstractTestNode.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.tests/src/org/eclipse/papyrus/uml/diagram/tests/canonical/AbstractTestNode.java
@@ -346,7 +346,7 @@ public abstract class AbstractTestNode extends org.eclipse.papyrus.uml.diagram.t
assertEquals(DROP + INITIALIZATION_TEST, expectedSemanticChildren, getRootSemanticModel().getOwnedElements().size());
}
DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
- ArrayList<Element> list = new ArrayList<Element>();
+ ArrayList<Element> list = new ArrayList<>();
for (Element element : getRootSemanticModel().getOwnedElements()) {
if (element != null && element.eClass().equals(eClass)) {
list.add(element);
@@ -444,6 +444,17 @@ public abstract class AbstractTestNode extends org.eclipse.papyrus.uml.diagram.t
* the type
*/
public void testToCreateANode(IElementType type, int expectedGraphicalChildren, int expectedSemanticChildren, int addedGraphicalChildren, int addedSemanticChildren, boolean maskmanaged, String initialName, int numberSemanticChildreen) {
+ testToCreateANode(getContainerEditPart(), type, expectedGraphicalChildren, expectedSemanticChildren, addedGraphicalChildren, addedSemanticChildren, maskmanaged, initialName, numberSemanticChildreen);
+ }
+
+ /**
+ * Test to create a node.
+ *
+ * @param type
+ * the type
+ */
+ public EditPart testToCreateANode(final IGraphicalEditPart container, IElementType type, int expectedGraphicalChildren, int expectedSemanticChildren, int addedGraphicalChildren, int addedSemanticChildren, boolean maskmanaged, String initialName,
+ int numberSemanticChildreen) {
command = null;
// CREATION
assertEquals(CREATION + INITIALIZATION_TEST, expectedGraphicalChildren, getRootView().getChildren().size());
@@ -456,7 +467,7 @@ public abstract class AbstractTestNode extends org.eclipse.papyrus.uml.diagram.t
Display.getDefault().syncExec(new Runnable() {
public void run() {
- command = getContainerEditPart().getCommand(requestcreation);
+ command = container.getCommand(requestcreation);
}
});
assertNotNull(CREATION + COMMAND_NULL, command);
@@ -485,7 +496,7 @@ public abstract class AbstractTestNode extends org.eclipse.papyrus.uml.diagram.t
assertEquals(CREATION + TEST_THE_REDO, expectedSemanticChildren + addedSemanticChildren, getRootSemanticModel().getOwnedElements().size());
}
- EditPart createdEditPart = (EditPart) getContainerEditPart().getChildren().get((getContainerEditPart().getChildren().size() - 1));
+ EditPart createdEditPart = (EditPart) container.getChildren().get((container.getChildren().size() - 1));
Assert.assertNotNull("The editpart must be created", createdEditPart); //$NON-NLS-1$
testNodeEditPart(maskmanaged, createdEditPart, initialName);
@@ -509,6 +520,7 @@ public abstract class AbstractTestNode extends org.eclipse.papyrus.uml.diagram.t
}
}
+ return createdEditPart;
}
/**
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.tests/src/org/eclipse/papyrus/uml/diagram/tests/canonical/TestDiagramConnector.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.tests/src/org/eclipse/papyrus/uml/diagram/tests/canonical/TestDiagramConnector.java
new file mode 100644
index 00000000000..f4b1af407b1
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.tests/src/org/eclipse/papyrus/uml/diagram/tests/canonical/TestDiagramConnector.java
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * Copyright (c) 2013,2018 CEA LIST.
+ *
+ *
+ * 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.tests.canonical;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
+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.ReorientRelationshipRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRequest;
+import org.eclipse.papyrus.commands.wrappers.GMFtoGEFCommandWrapper;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.uml2.uml.Connector;
+import org.eclipse.uml2.uml.Port;
+
+/**
+ *
+ * Base class for {@link org.eclipse.uml2.uml.Connector} feature testing
+ *
+ */
+public abstract class TestDiagramConnector extends TestChildNode {
+
+ protected void testToManagePortConnection(IElementType container, IElementType port, IElementType connectorType) {
+ int expectedGraphicalChildrens = 0;
+ IGraphicalEditPart sourceContainer = createContainer(container, expectedGraphicalChildrens++);
+ IGraphicalEditPart targetContainer = createContainer(container, expectedGraphicalChildrens++);
+ IGraphicalEditPart newTargetContainer = createContainer(container, expectedGraphicalChildrens++);
+ IGraphicalEditPart sourcePort = createPort(sourceContainer, port, expectedGraphicalChildrens, 0);
+ IGraphicalEditPart targetPort = createPort(targetContainer, port, expectedGraphicalChildrens, 0);
+ IGraphicalEditPart newTargetPort = createPort(newTargetContainer, port, expectedGraphicalChildrens, 1);
+ IGraphicalEditPart connector = createConnector(sourcePort, targetPort, connectorType);
+ assertTrue(connector.resolveSemanticElement() instanceof Connector);
+ assertTrue(sourcePort.resolveSemanticElement() instanceof Port);
+ assertTrue(targetPort.resolveSemanticElement() instanceof Port);
+ assertTrue(newTargetPort.resolveSemanticElement() instanceof Port);
+ testPortConnectorReorient((Connector) connector.resolveSemanticElement(), (Port) sourcePort.resolveSemanticElement(), (Port) newTargetPort.resolveSemanticElement(), ReorientRequest.REORIENT_SOURCE);
+ undoOnUIThread();
+ testPortConnectorReorient((Connector) connector.resolveSemanticElement(), (Port) targetPort.resolveSemanticElement(), (Port) newTargetPort.resolveSemanticElement(), ReorientRequest.REORIENT_TARGET);
+ }
+
+ private void testPortConnectorReorient(Connector connector, Port oldEnd, Port newEnd, int direction) {
+ ReorientRelationshipRequest req = new ReorientRelationshipRequest(getEditingDomain(), connector, newEnd, oldEnd, direction);
+ IElementEditService service = ElementEditServiceUtils.getCommandProvider(connector);
+ ICommand cmd = service.getEditCommand(req);
+ assertNotNull(cmd);
+ assertTrue(cmd.canExecute());
+ executeOnUIThread(GMFtoGEFCommandWrapper.wrap(cmd));
+ }
+
+ private IGraphicalEditPart createPort(IGraphicalEditPart container, IElementType port, int expectedGraphicalChildrens, int numberSemanticChildren) {
+ return (IGraphicalEditPart) testToCreateANode(container, port, expectedGraphicalChildrens, 0, 0, 1, false, null, numberSemanticChildren);
+ }
+
+ private IGraphicalEditPart createContainer(IElementType container, int expectedGraphicalChildrens) {
+ testToCreateANode(container, expectedGraphicalChildrens, 0, 1, 1, false, null, 0);
+ return (IGraphicalEditPart) getContainerEditPart().getChildren().get(expectedGraphicalChildrens);
+ }
+
+ protected IGraphicalEditPart createConnector(IGraphicalEditPart source, IGraphicalEditPart target, IElementType connector) {
+ Command command = target.getCommand(createConnectionViewRequest(connector, source, target));
+ assertNotNull(CREATION + COMMAND_NULL, command);
+ assertTrue(CONTAINER_CREATION + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute());
+ diagramEditor.getDiagramEditDomain().getDiagramCommandStack().execute(command);
+ assertEquals(1, source.getSourceConnections().size());
+ assertEquals(1, target.getTargetConnections().size());
+ IGraphicalEditPart sourceConnector = (IGraphicalEditPart) source.getSourceConnections().get(0);
+ IGraphicalEditPart targetConnector = (IGraphicalEditPart) target.getTargetConnections().get(0);
+ assertEquals(sourceConnector, targetConnector);
+ return sourceConnector;
+ }
+
+ protected CreateConnectionViewRequest createConnectionViewRequest(IElementType type, EditPart source, EditPart target) {
+ CreateConnectionViewRequest connectionRequest = CreateViewRequestFactory.getCreateConnectionRequest(type, getDiagramEditPart().getDiagramPreferencesHint());
+ connectionRequest.setSourceEditPart(null);
+ connectionRequest.setTargetEditPart(source);
+ connectionRequest.setType(RequestConstants.REQ_CONNECTION_START);
+ source.getCommand(connectionRequest);
+ connectionRequest.setSourceEditPart(source);
+ connectionRequest.setTargetEditPart(target);
+ connectionRequest.setType(RequestConstants.REQ_CONNECTION_END);
+ return connectionRequest;
+ }
+}

Back to the top