Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorashatilov2015-05-21 14:56:24 +0000
committerCamille Letavernier2015-05-26 09:02:07 +0000
commit0cca5e68f4bfe49e9b2327d21f053c5b32f2f85b (patch)
treed6326a54ba8334c02f2b77e33764173b281afdeb
parent2c9c0be82ea09f7d7b99c1fda3a5b45bd5ebc19a (diff)
downloadorg.eclipse.papyrus-0cca5e68f4bfe49e9b2327d21f053c5b32f2f85b.tar.gz
org.eclipse.papyrus-0cca5e68f4bfe49e9b2327d21f053c5b32f2f85b.tar.xz
org.eclipse.papyrus-0cca5e68f4bfe49e9b2327d21f053c5b32f2f85b.zip
Bug 315314 - [Profile diagram] Consistency between model and diagram can
be broken - test implementation Change-Id: I8cbd9f295c0d60e0c071bf8427c56d745e8b066a Signed-off-by: ashatilov <shatilov@montages.com> Reviewed-on: https://git.eclipse.org/r/48383 Tested-by: Hudson CI Reviewed-by: Michael Golubev <golubev@montages.com> Reviewed-by: Camille Letavernier <camille.letavernier@cea.fr>
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/tests/canonical/AllCanonicalTests.java2
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/tests/canonical/TestProfileDiagramExtension.java164
2 files changed, 165 insertions, 1 deletions
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/tests/canonical/AllCanonicalTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/tests/canonical/AllCanonicalTests.java
index 184df3d2791..82cf7cd87cf 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/tests/canonical/AllCanonicalTests.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/tests/canonical/AllCanonicalTests.java
@@ -16,6 +16,6 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
-@Suite.SuiteClasses({ TestProfileDiagramTopNode.class, TestProfileDiagramChildNode.class, TestProfileDiagramLink.class, TestImportMetaClass.class })
+@Suite.SuiteClasses({ TestProfileDiagramTopNode.class, TestProfileDiagramChildNode.class, TestProfileDiagramLink.class, TestImportMetaClass.class, TestProfileDiagramExtension.class })
public class AllCanonicalTests {
}
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/tests/canonical/TestProfileDiagramExtension.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/tests/canonical/TestProfileDiagramExtension.java
new file mode 100644
index 00000000000..2d76ac0bcd1
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.profile.tests/src/org/eclipse/papyrus/uml/diagram/profile/tests/canonical/TestProfileDiagramExtension.java
@@ -0,0 +1,164 @@
+package org.eclipse.papyrus.uml.diagram.profile.tests.canonical;
+
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+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.CreateViewRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
+import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
+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.View;
+import org.eclipse.papyrus.commands.ICreationCommand;
+import org.eclipse.papyrus.uml.diagram.common.commands.ShowHideElementsRequest;
+import org.eclipse.papyrus.uml.diagram.profile.CreateProfileDiagramCommand;
+import org.eclipse.papyrus.uml.diagram.profile.custom.edit.parts.CustomUMLDiagramUpdater;
+import org.eclipse.papyrus.uml.diagram.profile.custom.helper.MetaclassHelper;
+import org.eclipse.papyrus.uml.diagram.profile.edit.parts.StereotypeAttributeCompartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.profile.providers.UMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.tests.canonical.AbstractPapyrusTestCase;
+import org.eclipse.papyrus.uml.tools.providers.UMLMetaclassContentProvider;
+import org.eclipse.uml2.uml.Profile;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestProfileDiagramExtension extends AbstractPapyrusTestCase {
+
+ @Override
+ protected ICreationCommand getDiagramCommandCreation() {
+ return new CreateProfileDiagramCommand();
+ }
+
+ @Override
+ protected String getProjectName() {
+ return "ProfileDiagramTestProject";
+ }
+
+ @Override
+ protected String getFileName() {
+ return "ProfileDiagramTest.profile.di";
+ }
+
+ @Test
+ public void testDestroyExtensionProperty() {
+ // create Stereotype
+ GraphicalEditPart stereotypeEditPart = createNodeOnDiagram(UMLElementTypes.Stereotype_1026, new Point(100, 100), 1);
+ EObject stereotypeObject = ((View) stereotypeEditPart.getModel()).getElement();
+ Assert.assertTrue("Expected StereotypeImpl.", stereotypeObject instanceof Stereotype);
+ Stereotype stereotypeElement = (Stereotype) stereotypeObject;
+ Assert.assertTrue("Stereotype owned attr list should be empty at this step.", stereotypeElement.getOwnedAttributes().isEmpty());
+ IGraphicalEditPart propertyCompartment = findChildBySemanticHint(stereotypeEditPart, StereotypeAttributeCompartmentEditPart.VISUAL_ID);
+ GraphicalEditPart metaClassEditPart = createMetaclassOnDiagram(new Point(100, 300), 2);
+ // expected CSSConnectorImpl@6a2d9ede (type: StereotypeCommentLink) after the MetaclassEditPart creating
+ int linksAtStart = 1;
+ checkLinksCount(linksAtStart);
+ // create a extension link between stereotype and metaclass
+ createLink(UMLElementTypes.Extension_1013, stereotypeEditPart, metaClassEditPart);
+ checkLinksCount(linksAtStart + 1);
+ Assert.assertEquals("Expected just one stereotype owned attr.", 1, stereotypeElement.getOwnedAttributes().size());
+ Property extensionProperty = stereotypeElement.getOwnedAttributes().get(0);
+ showStereotypePropertyView(stereotypeEditPart, propertyCompartment.getNotationView(), extensionProperty);
+ Assert.assertEquals("Expected just one stereotype property attr.", 1, propertyCompartment.getChildren().size());
+ IGraphicalEditPart stereotypePropertyEP = (IGraphicalEditPart) propertyCompartment.getChildren().get(0);
+ Assert.assertTrue("stereotype property attr should be Property", ((View) stereotypePropertyEP.getModel()).getElement() instanceof Property);
+ destroyEditPart(stereotypePropertyEP);
+ Assert.assertTrue("We had removed stereotype property so owned attributes list should be empty.", stereotypeElement.getOwnedAttributes().isEmpty());
+ checkLinksCount(linksAtStart);
+ }
+
+ private void checkLinksCount(int expected) {
+ Assert.assertEquals("Diagram updater must detect that no link has been created", expected, CustomUMLDiagramUpdater.INSTANCE.getContainedLinks(getRootView()).size()); //$NON-NLS-1$
+ Assert.assertEquals(CREATION + INITIALIZATION_TEST, expected, ((Diagram) getRootView()).getEdges().size());
+ }
+
+ private void showStereotypePropertyView(EditPart parentEP, View compartmentView, Property property) {
+ ShowHideElementsRequest req = new ShowHideElementsRequest(compartmentView, property);
+ Command cmd = parentEP.getCommand(req);
+ assertNotNull(CREATION + COMMAND_NULL, cmd);
+ assertTrue(CREATION + TEST_IF_THE_COMMAND_IS_CREATED, cmd != UnexecutableCommand.INSTANCE);
+ assertTrue("CREATION: " + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, cmd.canExecute()); //$NON-NLS-1$
+ diagramEditor.getDiagramEditDomain().getDiagramCommandStack().execute(cmd);
+ }
+
+ private IGraphicalEditPart findChildBySemanticHint(IGraphicalEditPart parent, int vid) {
+ return findChildBySemanticHint(parent, Integer.toString(vid));
+ }
+
+ private IGraphicalEditPart findChildBySemanticHint(IGraphicalEditPart parent, String vid) {
+ IGraphicalEditPart childEP = parent.getChildBySemanticHint(vid);
+ assertNotNull("Parent " + parent + ", type " + parent.getNotationView() + " looking for: " + vid, childEP);
+ return childEP;
+ }
+
+ private void destroyEditPart(EditPart currentEditPart) {
+ Request deleteViewRequest = new EditCommandRequestWrapper(new DestroyElementRequest(false));
+ Command command = currentEditPart.getCommand(deleteViewRequest);
+ assertNotNull(DESTROY_DELETION + COMMAND_NULL, command);
+ assertTrue(DESTROY_DELETION + TEST_IF_THE_COMMAND_IS_CREATED, command != UnexecutableCommand.INSTANCE);
+ assertTrue(DESTROY_DELETION + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute());
+ executeOnUIThread(command);
+ }
+
+ private GraphicalEditPart createMetaclassOnDiagram(Point loc, int childrensCount) {
+ CreateViewRequest requestcreation = CreateViewRequestFactory.getCreateShapeRequest(UMLElementTypes.Class_1031, getDiagramEditPart().getDiagramPreferencesHint());
+ Profile parentProfile = MetaclassHelper.getParentProfile(getDiagramEditPart());
+ List<Object> importedElements = Arrays.asList(new UMLMetaclassContentProvider(parentProfile).getElements());
+ List<Object> forDialogSetup = new ArrayList<Object>();
+ forDialogSetup.add(importedElements.get(0));
+ MetaclassHelper.setupSuppressDialogRequest(requestcreation, forDialogSetup);
+ assertTrue("Metaclass selection dialog should be supressed.", MetaclassHelper.shouldSuppressDialog(requestcreation));
+ return createNodeOnDiagram(requestcreation, loc, childrensCount);
+ }
+
+ private GraphicalEditPart createNodeOnDiagram(IElementType nodeType, Point loc, int childrensCount) {
+ CreateViewRequest requestcreation = CreateViewRequestFactory.getCreateShapeRequest(nodeType, getDiagramEditPart().getDiagramPreferencesHint());
+ return createNodeOnDiagram(requestcreation, loc, childrensCount);
+ }
+
+ private GraphicalEditPart createNodeOnDiagram(CreateViewRequest request, Point loc, int childrensCount) {
+ request.setLocation(loc);
+ Command command = getDiagramEditPart().getCommand(request);
+ assertNotNull(CREATION + COMMAND_NULL, command);
+ assertTrue(CREATION + TEST_IF_THE_COMMAND_IS_CREATED, command != UnexecutableCommand.INSTANCE);
+ assertTrue("CREATION: " + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute()); //$NON-NLS-1$
+ diagramEditor.getDiagramEditDomain().getDiagramCommandStack().execute(command);
+ return (GraphicalEditPart) getDiagramEditPart().getChildren().get(childrensCount - 1);
+ }
+
+ private void createLink(IElementType linkType, GraphicalEditPart source, GraphicalEditPart target) {
+ Command command = target.getCommand(createConnectionViewRequest(linkType, source, target));
+ Assert.assertNotNull(CREATION + COMMAND_NULL, command);
+ Assert.assertTrue(CONTAINER_CREATION + TEST_IF_THE_COMMAND_CAN_BE_EXECUTED, command.canExecute());
+ diagramEditor.getDiagramEditDomain().getDiagramCommandStack().execute(command);
+ }
+
+ private CreateConnectionViewRequest createConnectionViewRequest(IElementType type, EditPart source, EditPart target) {
+ CreateConnectionViewRequest connectionRequest = CreateViewRequestFactory.getCreateConnectionRequest(type, ((IGraphicalEditPart) 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