Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratischenko2015-09-18 08:23:12 +0000
committerGerrit Code Review @ Eclipse.org2015-09-18 12:56:38 +0000
commit795b4df0bea78c2461043b347998f2e6619507ef (patch)
tree8e1b0cc6d413a0441764f01e505574c52c2a6fa1 /tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus
parentec47d735753d534dc495fa38e1c0514640263606 (diff)
downloadorg.eclipse.papyrus-795b4df0bea78c2461043b347998f2e6619507ef.tar.gz
org.eclipse.papyrus-795b4df0bea78c2461043b347998f2e6619507ef.tar.xz
org.eclipse.papyrus-795b4df0bea78c2461043b347998f2e6619507ef.zip
Bug 475371 - Copy paste Class do not copy all ownedElements
Change-Id: I635e2b3bdd76ac22fe197f039db72b11b6e77c6d Signed-off-by: atischenko <tischenko@montages.com>
Diffstat (limited to 'tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus')
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/AllTests.java4
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/tests/copyPaste/ConstraintCopyPasteTest.java177
2 files changed, 180 insertions, 1 deletions
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/AllTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/AllTests.java
index 73d53b6636e..7dee471098c 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/AllTests.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/test/AllTests.java
@@ -18,6 +18,7 @@ import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite;
import org.eclipse.papyrus.junit.framework.classification.ClassificationSuite.DynamicClasses;
import org.eclipse.papyrus.uml.diagram.composite.test.canonical.AllCanonicalTests;
import org.eclipse.papyrus.uml.diagram.composite.test.model.AllModelTests;
+import org.eclipse.papyrus.uml.diagram.composite.tests.copyPaste.ConstraintCopyPasteTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite.SuiteClasses;
@@ -29,7 +30,8 @@ import org.junit.runners.Suite.SuiteClasses;
// canonical
AllCanonicalTests.class,
RoundedCompartmentTest.class,
- AllModelTests.class
+ AllModelTests.class,
+ ConstraintCopyPasteTest.class
})
@DynamicClasses("org.eclipse.papyrus.uml.diagram.composite.test.AllGenTests")
public class AllTests {
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/tests/copyPaste/ConstraintCopyPasteTest.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/tests/copyPaste/ConstraintCopyPasteTest.java
new file mode 100644
index 00000000000..56e3c77eac7
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite.tests/test/org/eclipse/papyrus/uml/diagram/composite/tests/copyPaste/ConstraintCopyPasteTest.java
@@ -0,0 +1,177 @@
+/*****************************************************************************
+ * Copyright (c) 2015 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.composite.tests.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.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Shape;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+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.composite.custom.edit.parts.CustomConstraintEditPartCN;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeCompartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.CompositeStructureDiagramEditPart;
+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;
+
+
+@PluginResource("model/copyPaste/ConstraintPasteStrategy.di")
+@ShowView(value = "org.eclipse.papyrus.views.modelexplorer.modelexplorer")
+public class ConstraintCopyPasteTest {
+
+ @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 CLASS2_NAME = "Class2"; //$NON-NLS-1$
+
+ public final static String CONSTRAINT_NAME = "Constraint1"; //$NON-NLS-1$
+
+ public final static String DIAGRAM_NAME = "ConstraintCompositeStructureDiagram"; //$NON-NLS-1$
+
+ @Test
+ public void testCopyConstraintFromClassToClass() 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.Class class2 = (org.eclipse.uml2.uml.Class) model.getPackagedElement(CLASS2_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);
+
+ View class1View = DiagramUtils.findShape(mainDiagram, CLASS1_NAME);
+ View class1CompartmentView = findChildView(class1View, ClassCompositeCompartmentEditPart.VISUAL_ID);
+ Shape constraintView = DiagramUtils.findShape(class1CompartmentView, 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", CompositeStructureDiagramEditPart.class, defaultSelection.getClass());
+ Assert.assertEquals("TreeElement is not a model", CompositeStructureDiagramEditPart.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()).toList().get(0);
+
+ // it's working on service selection
+ Assert.assertEquals("TreeElement is not a constraint", CustomConstraintEditPartCN.class, constraintSelection.getClass());
+
+ ISelection selection = editorFixture.getEditor().getEditorSite().getSelectionProvider().getSelection();
+ Object editorConstraintSelection = ((IStructuredSelection) selection).toList().get(0);
+
+ // it's working on editor selection
+ Assert.assertEquals("TreeElement is not a constraint", CustomConstraintEditPartCN.class, editorConstraintSelection.getClass());
+
+ editorFixture.flushDisplayEvents();
+ Object defaultConstraintFromLinkHelperSelection = getSelectionLikeInAbstractGraphicalHandler(0);
+ Assert.assertEquals("TreeElement is not a constraint", CustomConstraintEditPartCN.class, defaultConstraintFromLinkHelperSelection.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 class2EP = editorFixture.findEditPart(class2);
+ IGraphicalEditPart classCompartmentEditPart = ((IGraphicalEditPart)class2EP).getChildBySemanticHint(Integer.toString(ClassCompositeCompartmentEditPart.VISUAL_ID));
+ editorFixture.deselect(constraintEP);
+ editorFixture.select(classCompartmentEditPart);
+ editorFixture.getPageManager().selectPage(mainDiagram);
+
+ editorFixture.flushDisplayEvents();
+
+ int class1AmountRulesBeforeCopy = class1.getOwnedRules().size();
+ int class2AmountRulesBeforeCopy = class2.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", class1AmountRulesBeforeCopy, class1.getOwnedRules().size()); //$NON-NLS-1$
+ Assert.assertEquals("The copy failed", class2AmountRulesBeforeCopy + 1, class2.getOwnedRules().size());
+ }
+
+ private Object getSelectionLikeInAbstractGraphicalHandler() {
+ return getSelectionLikeInAbstractGraphicalHandler(0);
+ }
+
+ private Object getSelectionLikeInAbstractGraphicalHandler(int numberOfSelectedEl) {
+ 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(numberOfSelectedEl);
+ }
+ }
+ return defaultVariable;
+ }
+
+ private Object getSelectionLikeTestOnModelExplorer() {
+ IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ISelectionService selectionService = activeWorkbenchWindow.getSelectionService();
+ return ((IStructuredSelection) selectionService.getSelection()).getFirstElement();
+ }
+
+ private View findChildView(View baseView, int compartmentID) {
+ String type = Integer.toString(compartmentID);
+ for (Object childObject: baseView.getChildren()) {
+ View child = (View)childObject;
+ if (child.getType().equals(type)) {
+ return child;
+ }
+ }
+ return null;
+ }
+}

Back to the top