diff options
author | Patrick Tessier | 2015-01-30 14:20:55 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2015-01-30 14:20:56 +0000 |
commit | e3f4cbee5b8ebf4d1306e2a29da118729a33b4af (patch) | |
tree | 41ab4b919cd5d050d6293fb8eb44b2c4296cc027 /tests | |
parent | d25ec775a2414d33bcd8750c6fa5a79184619ed4 (diff) | |
parent | 1be2507bd5bd0f91ea7a74a507c54aa6061bd333 (diff) | |
download | org.eclipse.papyrus-e3f4cbee5b8ebf4d1306e2a29da118729a33b4af.tar.gz org.eclipse.papyrus-e3f4cbee5b8ebf4d1306e2a29da118729a33b4af.tar.xz org.eclipse.papyrus-e3f4cbee5b8ebf4d1306e2a29da118729a33b4af.zip |
Merge changes I06cf3cfd,Ibe3678e3
* changes:
430548: [Constraints] ConstraintLink not show on diagram after drag and drop from Model Explorer https://bugs.eclipse.org/bugs/show_bug.cgi?id=430548 - Add a test on diagram with handler copy/paste
430548: [Constraints] ConstraintLink not show on diagram after drag and drop from Model Explorer https://bugs.eclipse.org/bugs/show_bug.cgi?id=430548
Diffstat (limited to 'tests')
7 files changed, 251 insertions, 2 deletions
diff --git a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java index ff6f06fa893..959005b38de 100644 --- a/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java +++ b/tests/junit/plugins/junit/org.eclipse.papyrus.junit.utils/src/org/eclipse/papyrus/junit/utils/rules/PapyrusEditorFixture.java @@ -581,6 +581,10 @@ public class PapyrusEditorFixture extends AbstractModelFixture<TransactionalEdit editPart.getViewer().getSelectionManager().appendSelection(editPart); } + public void deselect(EditPart editPart) { + editPart.getViewer().getSelectionManager().deselect(editPart); + } + public PaletteViewer getPalette() { return getPalette(getActiveDiagramEditor()); } diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/META-INF/MANIFEST.MF index d2f89a3ccef..97229dbe2e8 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/META-INF/MANIFEST.MF @@ -19,7 +19,11 @@ Require-Bundle: org.eclipse.ui, org.eclipse.emf.common.ui;bundle-version="2.9.0", org.eclipse.papyrus.infra.widgets;bundle-version="1.1.0", org.eclipse.papyrus.junit.utils;bundle-version="1.1.0", - org.eclipse.papyrus.infra.services.edit;bundle-version="1.1.0" + org.eclipse.papyrus.infra.services.edit;bundle-version="1.1.0", + org.eclipse.papyrus.infra.emf;bundle-version="1.1.0", + org.eclipse.papyrus.infra.services.openelement;bundle-version="1.1.0", + org.eclipse.core.expressions, + org.eclipse.papyrus.uml.tools.utils Export-Package: org.eclipse.papyrus.diagram.clazz.test.createFromPalette, org.eclipse.papyrus.uml.diagram.clazz.test, org.eclipse.papyrus.uml.diagram.clazz.test.canonical, diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.di b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.di new file mode 100644 index 00000000000..bf9abab340f --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.di @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"/> diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.notation b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.notation new file mode 100644 index 00000000000..c7eb0c853b6 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.notation @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<notation:Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:style="http://www.eclipse.org/papyrus/infra/viewpoints/policy/style" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_MQtE8ODIEeOARK60pOvVqQ" type="PapyrusUMLClassDiagram" name="ConstraintClassDiagram" measurementUnit="Pixel"> + <children xmi:type="notation:Shape" xmi:id="_N2U-8ODIEeOARK60pOvVqQ" type="2008"> + <children xmi:type="notation:DecorationNode" xmi:id="_N2nS0ODIEeOARK60pOvVqQ" type="5029"/> + <children xmi:type="notation:BasicCompartment" xmi:id="_N22jYODIEeOARK60pOvVqQ" type="7017"> + <styles xmi:type="notation:TitleStyle" xmi:id="_N22jYeDIEeOARK60pOvVqQ"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_N22jYuDIEeOARK60pOvVqQ"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_N22jY-DIEeOARK60pOvVqQ"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_N22jZODIEeOARK60pOvVqQ"/> + </children> + <children xmi:type="notation:BasicCompartment" xmi:id="_N22jZeDIEeOARK60pOvVqQ" type="7018"> + <styles xmi:type="notation:TitleStyle" xmi:id="_N22jZuDIEeOARK60pOvVqQ"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_N22jZ-DIEeOARK60pOvVqQ"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_N22jaODIEeOARK60pOvVqQ"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_N22jaeDIEeOARK60pOvVqQ"/> + </children> + <children xmi:type="notation:BasicCompartment" xmi:id="_N23KcODIEeOARK60pOvVqQ" type="7019"> + <styles xmi:type="notation:TitleStyle" xmi:id="_N23KceDIEeOARK60pOvVqQ"/> + <styles xmi:type="notation:SortingStyle" xmi:id="_N23KcuDIEeOARK60pOvVqQ"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_N23Kc-DIEeOARK60pOvVqQ"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_N23KdODIEeOARK60pOvVqQ"/> + </children> + <element xmi:type="uml:Class" href="ConstraintPasteStrategy.uml#_N0UMwODIEeOARK60pOvVqQ"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_N2U-8eDIEeOARK60pOvVqQ" x="391" y="110"/> + </children> + <children xmi:type="notation:Shape" xmi:id="_OQWogODIEeOARK60pOvVqQ" type="2011"> + <children xmi:type="notation:DecorationNode" xmi:id="_OQXPkODIEeOARK60pOvVqQ" type="5037"/> + <children xmi:type="notation:DecorationNode" xmi:id="_OQXPkeDIEeOARK60pOvVqQ" type="5159"/> + <element xmi:type="uml:Constraint" href="ConstraintPasteStrategy.uml#_OQJ0MODIEeOARK60pOvVqQ"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_OQWogeDIEeOARK60pOvVqQ" x="78" y="152"/> + </children> + <styles xmi:type="notation:DiagramStyle" xmi:id="_MQtE8eDIEeOARK60pOvVqQ"/> + <styles xmi:type="style:PapyrusViewStyle" xmi:id="_MQtE8uDIEeOARK60pOvVqQ"> + <owner xmi:type="uml:Model" href="ConstraintPasteStrategy.uml#_ML1zEODIEeOARK60pOvVqQ"/> + </styles> + <element xmi:type="uml:Model" href="ConstraintPasteStrategy.uml#_ML1zEODIEeOARK60pOvVqQ"/> + <edges xmi:type="notation:Connector" xmi:id="_OaMhAODIEeOARK60pOvVqQ" type="8500" source="_OQWogODIEeOARK60pOvVqQ" target="_N2U-8ODIEeOARK60pOvVqQ"> + <children xmi:type="notation:DecorationNode" xmi:id="_OaNIEODIEeOARK60pOvVqQ" type="8501"> + <layoutConstraint xmi:type="notation:Location" xmi:id="_OaNIEeDIEeOARK60pOvVqQ" y="15"/> + </children> + <styles xmi:type="notation:FontStyle" xmi:id="_OaMhAeDIEeOARK60pOvVqQ"/> + <element xsi:nil="true"/> + <bendpoints xmi:type="notation:RelativeBendpoints" xmi:id="_OaMhAuDIEeOARK60pOvVqQ" points="[0, 0, -204, 19]$[160, -14, -44, 5]$[204, -14, 0, 5]"/> + <sourceAnchor xmi:type="notation:IdentityAnchor" xmi:id="_OcQ9kODIEeOARK60pOvVqQ" id="(1.0,0.1)"/> + <targetAnchor xmi:type="notation:IdentityAnchor" xmi:id="_OcQ9keDIEeOARK60pOvVqQ" id="(0.0,0.48)"/> + </edges> +</notation:Diagram> diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.uml b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.uml new file mode 100644 index 00000000000..29eca5aff8f --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/model/copyPaste/ConstraintPasteStrategy.uml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_ML1zEODIEeOARK60pOvVqQ" name="model"> + <packagedElement xmi:type="uml:Class" xmi:id="_N0UMwODIEeOARK60pOvVqQ" name="Class1"> + <ownedRule xmi:type="uml:Constraint" xmi:id="_OQJ0MODIEeOARK60pOvVqQ" name="Constraint1"> + <specification xmi:type="uml:LiteralString" xmi:id="_OQMQcODIEeOARK60pOvVqQ" value=""/> + </ownedRule> + </packagedElement> +</uml:Model> diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/AllTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/AllTests.java index 1f21fc47972..06397911f2a 100644 --- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/AllTests.java +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/AllTests.java @@ -15,6 +15,7 @@ package org.eclipse.papyrus.uml.diagram.clazz.test; import org.eclipse.papyrus.uml.diagram.clazz.test.canonical.AllCanonicalTests; import org.eclipse.papyrus.uml.diagram.clazz.test.canonical.TestClassDiagram; +import org.eclipse.papyrus.uml.diagram.clazz.test.copyPaste.ConstraintPasteStrategyTest; import org.eclipse.papyrus.uml.diagram.clazz.test.legacy.PackageDiagramLegacyTest; import org.eclipse.papyrus.uml.diagram.clazz.test.tests.Bug382954_InstanceSpecificationLink; import org.junit.runner.RunWith; @@ -30,7 +31,8 @@ import org.junit.runners.Suite.SuiteClasses; AllCanonicalTests.class, TestClassDiagram.class, PackageDiagramLegacyTest.class, - Bug382954_InstanceSpecificationLink.class + Bug382954_InstanceSpecificationLink.class, + ConstraintPasteStrategyTest.class // load // LoadTests.class diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/copyPaste/ConstraintPasteStrategyTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/copyPaste/ConstraintPasteStrategyTest.java new file mode 100644 index 00000000000..8b2fba65fd0 --- /dev/null +++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.clazz.tests/test/org/eclipse/papyrus/uml/diagram/clazz/test/copyPaste/ConstraintPasteStrategyTest.java @@ -0,0 +1,182 @@ +/***************************************************************************** + * Copyright (c) 2014 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 + * + * Contributors: + * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net- bug430548 + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.clazz.test.copyPaste; + + + +import java.util.List; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.IHandler; +import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.Shape; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject; +import org.eclipse.papyrus.infra.services.openelement.service.OpenElementService; +import org.eclipse.papyrus.junit.framework.classification.tests.AbstractPapyrusTest; +import org.eclipse.papyrus.junit.utils.DiagramUtils; +import org.eclipse.papyrus.junit.utils.HandlerUtils; +import org.eclipse.papyrus.junit.utils.rules.PapyrusEditorFixture; +import org.eclipse.papyrus.junit.utils.rules.PluginResource; +import org.eclipse.papyrus.junit.utils.rules.ShowView; +import org.eclipse.papyrus.uml.diagram.clazz.custom.edit.part.CustomConstraintEditPart; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ModelEditPart; +import org.eclipse.ui.ISelectionService; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.services.IEvaluationService; +import org.eclipse.uml2.uml.Model; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + + +/** + * Tests for constraint paste strategy + * + * @author Benoit Maggi + * + */ +@PluginResource("model/copyPaste/ConstraintPasteStrategy.di") +@ShowView(value = "org.eclipse.papyrus.views.modelexplorer.modelexplorer") +public class ConstraintPasteStrategyTest extends AbstractPapyrusTest { + + @Rule + public final PapyrusEditorFixture editorFixture = new PapyrusEditorFixture(); + + public static final String COPY_COMMAND_ID = "org.eclipse.ui.edit.copy"; //$NON-NLS-1$ + + public static final String PASTE_COMMAND_ID = "org.eclipse.ui.edit.paste"; //$NON-NLS-1$ + + public final static String CLASS1_NAME = "Class1"; //$NON-NLS-1$ + + public final static String CONSTRAINT_NAME = "Constraint1"; //$NON-NLS-1$ + + public final static String DIAGRAM_NAME = "ConstraintClassDiagram"; //$NON-NLS-1$ + + + /** + * Test copy constraint in class diagram. + * + * @throws Exception + * the exception + */ + @Test + public void testCopyConstraintInClassDiagram() throws Exception { + + // get all semantic element that will handled + Model model = (Model) editorFixture.getModel(); + Assert.assertNotNull("RootModel is null", model); + + + org.eclipse.uml2.uml.Class class1 = (org.eclipse.uml2.uml.Class) model.getPackagedElement(CLASS1_NAME); + org.eclipse.uml2.uml.Constraint constraint = (org.eclipse.uml2.uml.Constraint) class1.getMember(CONSTRAINT_NAME); + + Assert.assertNotNull("Constraint is missing in the model", constraint); + + Diagram mainDiagram = DiagramUtils.getNotationDiagram(editorFixture.getModelSet(), DIAGRAM_NAME); + editorFixture.getPageManager().openPage(mainDiagram); + Assert.assertEquals("current opened diagram is not the expected one", mainDiagram.getName(), DIAGRAM_NAME); + + Shape constraintView = DiagramUtils.findShape(mainDiagram, CONSTRAINT_NAME); + Assert.assertNotNull("Constraint view not present", constraintView); + + Object defaultSelection = getSelectionLikeTestOnModelExplorer(); + Object defaultSelectionHandler = getSelectionLikeInAbstractGraphicalHandler(); + + editorFixture.flushDisplayEvents(); + Assert.assertNotNull("Constraint TreeElement is null", defaultSelection); //$NON-NLS-1$ + Assert.assertEquals("TreeElement is not a model", ModelEditPart.class, defaultSelection.getClass()); + Assert.assertEquals("TreeElement is not a model", ModelEditPart.class, defaultSelectionHandler.getClass()); + + EditPart constraintEP = editorFixture.findEditPart(constraint); + editorFixture.select(constraintEP); + + + IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + ISelectionService selectionService = activeWorkbenchWindow.getSelectionService(); + Object constraintSelection = ((IStructuredSelection) selectionService.getSelection()).getFirstElement(); + + // it's working on service selection + Assert.assertEquals("TreeElement is not a constraint", CustomConstraintEditPart.class, constraintSelection.getClass()); + + ISelection selection = editorFixture.getEditor().getEditorSite().getSelectionProvider().getSelection(); + Object editorSelection = ((IStructuredSelection) selection).getFirstElement(); + + // it's working on editor selection + Assert.assertEquals("TreeElement is not a constraint", CustomConstraintEditPart.class, editorSelection.getClass()); + + editorFixture.flushDisplayEvents(); + Object defaultVariableFromLinkHelperSelection = getSelectionLikeInAbstractGraphicalHandler(); + Assert.assertEquals("TreeElement is not a constraint", CustomConstraintEditPart.class, defaultVariableFromLinkHelperSelection.getClass()); + + // Test with OpenElementService + OpenElementService openElementService = ServiceUtilsForEObject.getInstance().getService(OpenElementService.class, constraint); + openElementService.openSemanticElement(constraint); + + editorFixture.flushDisplayEvents(); + Object defaultVariableFromOpenElementService = getSelectionLikeInAbstractGraphicalHandler(); + Assert.assertEquals("TreeElement is not a constraint", CustomConstraintEditPart.class, defaultVariableFromOpenElementService.getClass()); + + // Copy + IHandler copyHandler = HandlerUtils.getActiveHandlerFor(COPY_COMMAND_ID); + Assert.assertTrue("Copy not available", copyHandler.isEnabled()); //$NON-NLS-1$ + copyHandler.execute(new ExecutionEvent()); + + // Select diagram + EditPart modelEP = editorFixture.findEditPart(model); + editorFixture.deselect(constraintEP); + editorFixture.select(modelEP); + editorFixture.getPageManager().selectPage(mainDiagram); + + editorFixture.flushDisplayEvents(); + + int amountRulesBeforeCopy = class1.getOwnedRules().size(); + + // Paste + IHandler pasteHandler = HandlerUtils.getActiveHandlerFor(PASTE_COMMAND_ID); + Assert.assertTrue("Paste not available", pasteHandler.isEnabled()); //$NON-NLS-1$ + pasteHandler.execute(new ExecutionEvent()); + + editorFixture.flushDisplayEvents(); + + // Check that there is a copy of Constraint + Assert.assertEquals("The copy failed", amountRulesBeforeCopy + 1, class1.getOwnedRules().size()); //$NON-NLS-1$ + + } + + private Object getSelectionLikeInAbstractGraphicalHandler() { + IEvaluationService evaluationService = PlatformUI.getWorkbench().getService(IEvaluationService.class); + IEvaluationContext currentState = evaluationService.getCurrentState(); + Object defaultVariable = currentState.getDefaultVariable(); + if (defaultVariable instanceof List) { + List arrayList = (List) defaultVariable; + if (!arrayList.isEmpty()) { + return arrayList.get(0); + } + } + return defaultVariable; + } + + private Object getSelectionLikeTestOnModelExplorer() { + IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + ISelectionService selectionService = activeWorkbenchWindow.getSelectionService(); + return ((IStructuredSelection) selectionService.getSelection()).getFirstElement(); + } + + + +} |