From 6ca0730998ef904252b73645a6d57288fd2d38e1 Mon Sep 17 00:00:00 2001 From: Benoit Maggi Date: Tue, 8 Apr 2014 14:35:57 +0200 Subject: Patch sysml.modelexplorer.tests for copy-paste Change-Id: I4dc10a381a32b3c385c1d2b6ec1c1a2329682cf0 Signed-off-by: Benoit Maggi --- .../.classpath | 2 +- .../.settings/org.eclipse.jdt.core.prefs | 7 +- .../META-INF/MANIFEST.MF | 5 +- .../plugin.xml | 6 + .../common/strategy/paste/PartPasteStrategy.java | 347 ++++++++++++++ .../META-INF/MANIFEST.MF | 1 + .../.classpath | 15 +- .../tests/common/AbstractModelExplorerTest.java | 525 --------------------- .../copypaste/AbstractCopyPasteBlockTest.java | 61 --- .../tests/copypaste/AbstractCopyPastePartTest.java | 59 --- .../copypaste/AbstractCopyPasteReferenceTest.java | 60 --- .../tests/copypaste/AbstractCopyPasteTest.java | 158 ------- .../tests/copypaste/CopyPasteSimpleBlock2Test.java | 114 ----- .../tests/copypaste/CopyPasteSimpleBlockTest.java | 125 ----- .../tests/copypaste/CopyPasteSimplePartTest.java | 136 ------ .../copypaste/CopyPasteSimpleReferenceTest.java | 150 ------ .../tests/suites/AllCopyPasteTests.java | 41 -- .../tests/common/AbstractModelExplorerTest.java | 525 +++++++++++++++++++++ .../copypaste/AbstractCopyPasteBlockTest.java | 61 +++ .../tests/copypaste/AbstractCopyPastePartTest.java | 66 +++ .../copypaste/AbstractCopyPasteReferenceTest.java | 60 +++ .../tests/copypaste/AbstractCopyPasteTest.java | 158 +++++++ .../tests/copypaste/CopyPasteSimpleBlock2Test.java | 114 +++++ .../tests/copypaste/CopyPasteSimpleBlockTest.java | 125 +++++ .../tests/copypaste/CopyPasteSimplePartTest.java | 136 ++++++ .../copypaste/CopyPasteSimpleReferenceTest.java | 150 ++++++ .../tests/suites/AllCopyPasteTests.java | 41 ++ 27 files changed, 1803 insertions(+), 1445 deletions(-) create mode 100644 plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/strategy/paste/PartPasteStrategy.java delete mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/common/AbstractModelExplorerTest.java delete mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteBlockTest.java delete mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPastePartTest.java delete mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteReferenceTest.java delete mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteTest.java delete mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlock2Test.java delete mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlockTest.java delete mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimplePartTest.java delete mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleReferenceTest.java delete mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/suites/AllCopyPasteTests.java create mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/common/AbstractModelExplorerTest.java create mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteBlockTest.java create mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPastePartTest.java create mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteReferenceTest.java create mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteTest.java create mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlock2Test.java create mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlockTest.java create mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimplePartTest.java create mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleReferenceTest.java create mode 100644 tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/suites/AllCopyPasteTests.java diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/.classpath b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/.classpath index a93010f69d7..beb405d35fd 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/.classpath +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/.classpath @@ -1,6 +1,6 @@ - + diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/.settings/org.eclipse.jdt.core.prefs b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/.settings/org.eclipse.jdt.core.prefs index 980d46758d6..8000cd6ca61 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/.settings/org.eclipse.jdt.core.prefs +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/.settings/org.eclipse.jdt.core.prefs @@ -1,12 +1,11 @@ -#Thu Apr 21 15:05:56 CEST 2011 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/META-INF/MANIFEST.MF b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/META-INF/MANIFEST.MF index 58301b5bea6..a675c445517 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/META-INF/MANIFEST.MF +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/META-INF/MANIFEST.MF @@ -69,7 +69,6 @@ Bundle-Localization: plugin Bundle-Name: %pluginName Bundle-Activator: org.eclipse.papyrus.sysml.diagram.common.Activator Bundle-ManifestVersion: 2 -Bundle-SymbolicName: org.eclipse.papyrus.sysml.diagram.common;singleto - n:=true -Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-SymbolicName: org.eclipse.papyrus.sysml.diagram.common;singleton:=true +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/plugin.xml b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/plugin.xml index d04bf6abd85..f2a731c5d31 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/plugin.xml +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/plugin.xml @@ -43,6 +43,12 @@ + + + + diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/strategy/paste/PartPasteStrategy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/strategy/paste/PartPasteStrategy.java new file mode 100644 index 00000000000..d512c0619ee --- /dev/null +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/strategy/paste/PartPasteStrategy.java @@ -0,0 +1,347 @@ +/***************************************************************************** + * 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 + *****************************************************************************/ +package org.eclipse.papyrus.sysml.diagram.common.strategy.paste; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.gef.commands.Command; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.commands.wrappers.EMFtoGEFCommandWrapper; +import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper; +import org.eclipse.papyrus.infra.core.clipboard.IClipboardAdditionalData; +import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard; +import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy; +import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils; +import org.eclipse.papyrus.infra.services.edit.service.IElementEditService; +import org.eclipse.papyrus.sysml.blocks.Block; +import org.eclipse.papyrus.uml.diagram.common.Activator; +import org.eclipse.papyrus.uml.diagram.common.strategy.paste.DefaultPasteStrategy; +import org.eclipse.swt.graphics.Image; +import org.eclipse.uml2.uml.Association; +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Package; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.util.UMLUtil; + +/** + * Offer a strategy for copying stereotypes. + */ +public class PartPasteStrategy implements IPasteStrategy { + + /** The instance. */ + private static IPasteStrategy instance = new PartPasteStrategy(); + + /** + * Gets the single instance of StereotypePasteStrategy. + * + * @return single instance of StereotypePasteStrategy + */ + public static IPasteStrategy getInstance() { + return instance; + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getLabel() + */ + public String getLabel() { + return "partPasteStrategy"; //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getID() + */ + public String getID() { + return Activator.ID + ".partPasteStrategy"; //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getDescription() + */ + public String getDescription() { + return "Paste part elements with association"; //$NON-NLS-1$ + } + + /** + * Gets the category id. + * + * @return the category id + */ + public String getCategoryID() { + return "org.eclipse.papyrus.strategy.paste"; //$NON-NLS-1$ + } + + /** + * Gets the category label. + * + * @return the category label + */ + public String getCategoryLabel() { + return "Paste all copied elements"; //$NON-NLS-1$ + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getImage() + */ + @Deprecated + public Image getImage() { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getPriority() + */ + @Deprecated + public int getPriority() { + return 1; + } + + /** + * Sets the options. + * + * @param options + * the options + */ + public void setOptions(Map options) { + //Nothing + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getSemanticCommand(org.eclipse.emf.edit.domain.EditingDomain, + * org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard) + */ + @Override + public org.eclipse.emf.common.command.Command getSemanticCommand(EditingDomain domain, EObject targetOwner, PapyrusClipboard papyrusClipboard) { + if(targetOwner instanceof Classifier || targetOwner instanceof Package) { // test if block or package + // get affiliate AdditionnalData + Map additionalDataMap = papyrusClipboard.getAdditionalDataForStrategy(getID()); + if(additionalDataMap != null) { + CompoundCommand compoundCommand = new CompoundCommand("Copy associations for parts"); //$NON-NLS-1$ + for(Iterator iterator = papyrusClipboard.iterator(); iterator.hasNext();) { + Object object = iterator.next(); + EObject target = papyrusClipboard.getTragetCopyFromInternalClipboardCopy(object); + Object additionnalData = additionalDataMap.get(object); + EList listDuplicatedAssociation = new BasicEList(); + EObject associationContainer = null; + if(target != null && target instanceof Property && targetOwner instanceof Classifier && additionnalData instanceof PartAdditionalData) { // test if it is a part + Classifier block = (Classifier)targetOwner; + Property property = (Property)target; + PartAdditionalData partAdditionalData = (PartAdditionalData)additionnalData; + Association newAssociation = partAdditionalData.getDuplicatedAssociation(); + restoreAssociationPartContext(block, property, newAssociation); + listDuplicatedAssociation.add(newAssociation); + associationContainer = block.eContainer(); + } else if(target != null && target instanceof Classifier && targetOwner instanceof Package && additionnalData instanceof PartBlockAdditionalData) { // test if it is a block + Classifier classifier = (Classifier)target; + EList allAttributes = classifier.getAllAttributes(); + PartBlockAdditionalData partBlockAdditionalData = (PartBlockAdditionalData)additionnalData; + for(Property property : allAttributes) { + Association duplicatedAssociation = partBlockAdditionalData.getDuplicatedAssociationByPropertyName(property.getName()); + restoreAssociationPartContext(classifier, property, duplicatedAssociation); + listDuplicatedAssociation.add(duplicatedAssociation); + } + associationContainer = targetOwner; + } + if(associationContainer != null && !listDuplicatedAssociation.isEmpty()) { + // add associations to the nearest container + MoveRequest moveRequest = new MoveRequest(associationContainer, listDuplicatedAssociation); + IElementEditService provider = ElementEditServiceUtils.getCommandProvider(targetOwner); + if(provider != null) { + ICommand editCommand = provider.getEditCommand(moveRequest); + GMFtoEMFCommandWrapper gmFtoEMFCommandWrapper = new GMFtoEMFCommandWrapper(editCommand); + compoundCommand.append(gmFtoEMFCommandWrapper); + } + } + } + // An empty command can't be executed + if(compoundCommand.getCommandList().isEmpty()) { + return null; + } + return compoundCommand; + } + } + return null; + } + + + + + + /* + * (non-Javadoc) + * + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#getGraphicalCommand(org.eclipse.emf.edit.domain.EditingDomain, + * org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart, org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard) + */ + @Override + public Command getGraphicalCommand(EditingDomain domain, org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart targetEditPart, PapyrusClipboard papyrusClipboard) { + View targetView = (View)targetEditPart.getModel(); + EObject targetOwner = (EObject)targetView.getElement(); + org.eclipse.emf.common.command.Command semanticCommand = getSemanticCommand(domain, targetOwner, papyrusClipboard); + if(semanticCommand != null) { + org.eclipse.gef.commands.CompoundCommand compoundCommand = new org.eclipse.gef.commands.CompoundCommand("Association Part Semantic And Graphical paste"); //$NON-NLS-1$ + EMFtoGEFCommandWrapper emFtoGEFCommandWrapper = new EMFtoGEFCommandWrapper(semanticCommand); + compoundCommand.add(emFtoGEFCommandWrapper); + return compoundCommand; + } + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#dependsOn() + */ + @Override + public IPasteStrategy dependsOn() { + return DefaultPasteStrategy.getInstance(); + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy#prepare(org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard) + */ + @Override + public void prepare(PapyrusClipboard papyrusClipboard) { + Map mapCopyPartData = new HashMap(); + for(Iterator iterator = papyrusClipboard.iterateOnSource(); iterator.hasNext();) { + EObject eObjectSource = iterator.next(); + if(eObjectSource instanceof Element) { + Element elementSource = (Element)eObjectSource; + IClipboardAdditionalData clipboardAdditionalData = null; + if(elementSource instanceof Property && UMLUtil.getStereotypeApplication(elementSource.getOwner(), Block.class) != null) { // is part + Property propertySource = (Property)elementSource; + clipboardAdditionalData = new PartAdditionalData(propertySource.getAssociation()); + } else if(elementSource instanceof Classifier && UMLUtil.getStereotypeApplication(elementSource, Block.class) != null) {// is Block + Classifier block = (Classifier)elementSource; + clipboardAdditionalData = new PartBlockAdditionalData(block); + } + if(clipboardAdditionalData != null) { + Object copy = papyrusClipboard.getCopyFromSource(eObjectSource); + mapCopyPartData.put(copy, clipboardAdditionalData); + } + } + + } + papyrusClipboard.pushAdditionalData(getID(), mapCopyPartData); + } + + + /** + * Duplicate the association + * @param association + * @return + */ + protected Association duplicateAssociation(Association association) { + EcoreUtil.Copier copier = new EcoreUtil.Copier(); + copier.copy(association); + EObject eObject = copier.get(association); + return (Association)eObject; + } + + /** + * Init the association in the new context + * @param classifier + * @param property + * @param association + */ + protected void restoreAssociationPartContext(Classifier classifier, Property property, Association association) { + EList memberEnds = association.getMemberEnds(); // should have only one element + if (memberEnds != null && !memberEnds.isEmpty()){ + Property blockProperty = memberEnds.get(0); + blockProperty.setType(classifier); + } + memberEnds.add(property); + } + + + /** + * The Class PartAdditionalData. + */ + protected class PartAdditionalData implements IClipboardAdditionalData { + + /** The association. */ + protected Association asssociation; + + /** + * @param association + */ + public PartAdditionalData(Association asssociation) { + this.asssociation = duplicateAssociation(asssociation); + } + + /** + * @return a copy of the association + */ + public Association getDuplicatedAssociation() { + return duplicateAssociation(asssociation); + } + + } + + /** + * The Class PartBlockAdditionalData. + */ + protected class PartBlockAdditionalData implements IClipboardAdditionalData { + + /** The associations by property name. */ + protected Map mapPropertyNameToAssociation; + + /** + * @param block + */ + public PartBlockAdditionalData(Classifier block) { + this.mapPropertyNameToAssociation = new HashMap(); + EList allAttributes = block.getAllAttributes(); + for(Property property : allAttributes) { + Association association = property.getAssociation(); + Association newAssociation = duplicateAssociation(association); + mapPropertyNameToAssociation.put(property.getName(), newAssociation); + } + + } + + /** + * @param propertyName + * @return a copy of the association + */ + public Association getDuplicatedAssociationByPropertyName(String propertyName) { + Association association = mapPropertyNameToAssociation.get(propertyName); + return duplicateAssociation(association); + } + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF index 1c01988f0fe..12a7a67418e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF @@ -35,6 +35,7 @@ Export-Package: org.eclipse.papyrus.uml.diagram.common, org.eclipse.papyrus.uml.diagram.common.service, org.eclipse.papyrus.uml.diagram.common.service.palette, org.eclipse.papyrus.uml.diagram.common.sheet, + org.eclipse.papyrus.uml.diagram.common.strategy.paste, org.eclipse.papyrus.uml.diagram.common.ui.dialogs, org.eclipse.papyrus.uml.diagram.common.ui.helper, org.eclipse.papyrus.uml.diagram.common.util, diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/.classpath b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/.classpath index 23f23cf2994..969b4034060 100644 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/.classpath +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/.classpath @@ -1,8 +1,7 @@ - - - - - - - - + + + + + + + diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/common/AbstractModelExplorerTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/common/AbstractModelExplorerTest.java deleted file mode 100644 index 165a3329338..00000000000 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/common/AbstractModelExplorerTest.java +++ /dev/null @@ -1,525 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2011 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: - * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation - * - * @Generated from Model - * - *****************************************************************************/ -package org.eclipse.papyrus.sysml.modelexplorer.tests.common; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import junit.framework.Assert; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; -import org.eclipse.gmf.runtime.notation.Diagram; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.custom.Customization; -import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EObjectTreeElement; -import org.eclipse.papyrus.infra.core.resource.ModelSet; -import org.eclipse.papyrus.infra.core.resource.additional.AdditionalResourcesModel; -import org.eclipse.papyrus.sysml.modelexplorer.Activator; -import org.eclipse.papyrus.sysml.modelexplorer.tests.utils.EditorUtils; -import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView; -import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView; -import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils; -import org.eclipse.papyrus.views.modelexplorer.matching.IMatchingItem; -import org.eclipse.papyrus.views.modelexplorer.matching.LinkItemMatchingItem; -import org.eclipse.papyrus.views.modelexplorer.matching.ModelElementItemMatchingItem; -import org.eclipse.papyrus.views.modelexplorer.matching.ReferencableMatchingItem; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.navigator.CommonViewer; -import org.eclipse.ui.part.FileEditorInput; -import org.eclipse.uml2.uml.Model; -import org.eclipse.uml2.uml.NamedElement; -import org.junit.AfterClass; -import org.junit.BeforeClass; - - - -/** - * Abstract class for Copy/paste - */ -public abstract class AbstractModelExplorerTest { - - /** boolean to indicate if the test is initialized or not */ - private static boolean isInitialized; - - /** main papyrus editor */ - public static IEditorPart editor = null; - - /** id of the papyrus editor */ - public static String editorID = "org.eclipse.papyrus.infra.core.papyrusEditor"; - - /** view part: the model explorer */ - protected static IViewPart modelExplorerPart; - - /** generated selectable objects */ - protected static org.eclipse.uml2.uml.Model model_EObject; - - protected static org.eclipse.uml2.uml.Class b1_EObject; - - protected static org.eclipse.uml2.uml.Property pB1P1_B1_EObject; - - protected static org.eclipse.uml2.uml.Property rB2_B1_EObject; - - protected static org.eclipse.uml2.uml.Property pB2_B1_EObject; - - protected static org.eclipse.uml2.uml.Class b2_EObject; - - protected static org.eclipse.uml2.uml.Package p1_EObject; - - protected static org.eclipse.uml2.uml.Class b2P1_P1_EObject; - - protected static org.eclipse.uml2.uml.Class b1P1_P1_EObject; - - protected static org.eclipse.uml2.uml.Property pB1_B1P1_P1_EObject; - - protected static org.eclipse.uml2.uml.Property pB2P1_B1P1_P1_EObject; - - protected static Diagram iBD_B1_Diagram; - - protected static Diagram bDD_Main_Diagram; - - /** end of generated selectable objects */ - - /** - * Initialization of the test - * - * @throws Exception - * thrown when initialization has problem - */ - @BeforeClass - public static void openPapyrusWithAnEmptyProject() throws Exception { - // Prepare new project for tests - IProject testProject = ResourcesPlugin.getWorkspace().getRoot().getProject("TestCopyPasteProject"); - if(!testProject.exists()) { - testProject.create(new NullProgressMonitor()); - } - - if(!testProject.isOpen()) { - testProject.open(new NullProgressMonitor()); - } - - // Copy EmptyModel from bundle to the test project - final IFile emptyModel_di = testProject.getFile("ModelWithBDD.di"); - IFile emptyModel_no = testProject.getFile("ModelWithBDD.notation"); - IFile emptyModel_uml = testProject.getFile("ModelWithBDD.uml"); - - // isInitialized = isInitialized || emptyModel_di.exists(); - - if(!isInitialized) { - isInitialized = true; - emptyModel_di.create(Activator.getDefault().getBundle().getResource("/model/ModelWithBDD.di").openStream(), true, new NullProgressMonitor()); - emptyModel_no.create(Activator.getDefault().getBundle().getResource("/model/ModelWithBDD.notation").openStream(), true, new NullProgressMonitor()); - emptyModel_uml.create(Activator.getDefault().getBundle().getResource("/model/ModelWithBDD.uml").openStream(), true, new NullProgressMonitor()); - } - - // Open the EmptyModel.di file with Papyrus (assumed to be the default editor for "di" files here). - Display.getDefault().syncExec(new Runnable() { - - public void run() { - try { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - editor = page.openEditor(new FileEditorInput(emptyModel_di), editorID); - - modelExplorerPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ModelExplorerPageBookView.VIEW_ID); - modelExplorerPart.setFocus(); - } catch (Exception ex) { - ex.printStackTrace(System.out); - } - } - }); - - Assert.assertNotNull("Model explorer is null", modelExplorerPart); - - prepareTest(); - } - - /** - * Prepare the diagram before testing - * - * @throws Exception - * exception thrown in case of problem - */ - public static void prepareTest() throws Exception { - DiagramEditPart diagramEditPart = EditorUtils.getDiagramEditPart(); - EObject root = diagramEditPart.getDiagramView().getElement(); - - Assert.assertTrue("Impossible to find main model", root instanceof Model); - - /** generated selectable objects */ - model_EObject = (org.eclipse.uml2.uml.Model)root; - b1_EObject = (org.eclipse.uml2.uml.Class)model_EObject.getPackagedElement("B1"); - Assert.assertNotNull("Impossible to find Class B1", b1_EObject); - pB1P1_B1_EObject = b1_EObject.getAttribute("pB1P1", null); - Assert.assertNotNull("Impossible to find Property pB1P1", pB1P1_B1_EObject); - rB2_B1_EObject = b1_EObject.getAttribute("rB2", null); - Assert.assertNotNull("Impossible to find Property rB2", rB2_B1_EObject); - pB2_B1_EObject = b1_EObject.getAttribute("pB2", null); - Assert.assertNotNull("Impossible to find Property pB2", pB2_B1_EObject); - - b2_EObject = (org.eclipse.uml2.uml.Class)model_EObject.getPackagedElement("B2"); - Assert.assertNotNull("Impossible to find Class B2", b2_EObject); - - p1_EObject = (org.eclipse.uml2.uml.Package)model_EObject.getPackagedElement("P1"); - Assert.assertNotNull("Impossible to find Package P1", p1_EObject); - b2P1_P1_EObject = (org.eclipse.uml2.uml.Class)p1_EObject.getPackagedElement("B2P1"); - Assert.assertNotNull("Impossible to find Class B2P1", b2P1_P1_EObject); - - b1P1_P1_EObject = (org.eclipse.uml2.uml.Class)p1_EObject.getPackagedElement("B1P1"); - Assert.assertNotNull("Impossible to find Class B1P1", b1P1_P1_EObject); - pB1_B1P1_P1_EObject = b1P1_P1_EObject.getAttribute("pB1", null); - Assert.assertNotNull("Impossible to find Property pB1", pB1_B1P1_P1_EObject); - pB2P1_B1P1_P1_EObject = b1P1_P1_EObject.getAttribute("pB2P1", null); - Assert.assertNotNull("Impossible to find Property pB2P1", pB2P1_B1P1_P1_EObject); - - - - - - iBD_B1_Diagram = getDiagram("IBD_B1"); - Assert.assertNotNull("Impossible to find IBD_B1", iBD_B1_Diagram); - bDD_Main_Diagram = getDiagram("BDD_Main"); - Assert.assertNotNull("Impossible to find BDD_Main", bDD_Main_Diagram); - List appliedCustomizations=org.eclipse.papyrus.views.modelexplorer.Activator.getDefault().getCustomizationManager().getManagedCustomizations(); - Customization SimpleUML=null; - Iteratoriter=appliedCustomizations.iterator(); - while(iter.hasNext()) { - Customization custo = (Customization)iter.next(); - if( custo.getName().equals("SimpleUML")){ - SimpleUML=custo; - } - } - org.junit.Assert.assertNotNull("Custom SimpleUML not found", SimpleUML); - org.eclipse.papyrus.views.modelexplorer.Activator.getDefault().getCustomizationManager().getManagedCustomizations().add(0, SimpleUML); - - - - org.junit.Assert.assertEquals("bad order of applied Custom", "SimpleUML", appliedCustomizations.get(0).getName()); - - /** end of generated selectable objects */ - } - - /** - * Close editor - * - * @throws Exception - * exception thrown in case of problem - */ - @AfterClass - public static void closePapyrusAndCleanProject() throws Exception { - // Close the editor without saving content created during tests - Display.getDefault().syncExec(new Runnable() { - - public void run() { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - page.closeEditor(editor, false); - } - }); - - editor = null; - modelExplorerPart = null; - } - - - /** - * Selects and reveal the specified element - * - * @param object - * the object to select - * @throws Exception - * exception thrown in case element could not be selected - */ - public static void selectAndReveal(final EObject object) throws Exception { - Display.getDefault().syncExec(new Runnable() { - - public void run() { - try { - selectAndReveal(Arrays.asList(object)); - } catch (Exception ex) { - ex.printStackTrace(System.out); - } - } - }); - } - - /** - * Selects and reveal the specified list of elements - * - * @param newElements - * the list of objects to select - * @throws Exception - * exception thrown in case element could not be selected - */ - public static void selectAndReveal(List newElements) throws Exception { - // Retrieve model explorer - ModelExplorerView modelExplorerView = null; - - ModelExplorerPageBookView bookViewPart = (ModelExplorerPageBookView)NavigatorUtils.findViewPart(ModelExplorerPageBookView.VIEW_ID); - if(bookViewPart != null) { - modelExplorerView = (ModelExplorerView)bookViewPart.getActiveView(); - } - - // Set selection on new element in the model explorer - if((modelExplorerView != null) && (newElements != null)) { - List semanticElementList = new ArrayList(); - semanticElementList.addAll(newElements); - modelExplorerView.revealSemanticElement(semanticElementList); - } else { - throw new Exception("Impossible to find the model explorer required to select: " + newElements); - } - } - - /** - * Returns the current editing domain - * - * @return - * the current editing domain - */ - protected TransactionalEditingDomain getEditingDomain() throws Exception { - return (TransactionalEditingDomain)editor.getAdapter(TransactionalEditingDomain.class); - } - - /** - * Returns true if the current Active editor is dirty. - * - * @return true if the current Active editor is dirty - * @throws Exception - * exception thrown in case of problem (NPE, etc.) - */ - protected boolean isEditorDirty() throws Exception { - RunnableWithResult runnable; - Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl() { - - public void run() { - setResult(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().isDirty()); - } - }); - - return runnable.getResult(); - } - - /** - * Selects and reveal the specified element - * - * @param object - * the object to select - * @throws Exception - * exception thrown in case element could not be selected - */ - public static void selectAndRevealDiagram(final Diagram object) throws Exception { - Display.getDefault().syncExec(new Runnable() { - - public void run() { - try { - selectAndRevealDiagram(Arrays.asList(object)); - } catch (Exception ex) { - ex.printStackTrace(System.out); - } - } - }); - } - - /** - * Selects and reveal the specified list of diagrams - * - * @param newElements - * the list of diagrams to select - * @throws Exception - * exception thrown in case diagram could not be selected - */ - public static void selectAndRevealDiagram(List newDiagrams) throws Exception { - // Retrieve model explorer - ModelExplorerView modelExplorerView = null; - ModelExplorerPageBookView bookViewPart = (ModelExplorerPageBookView)NavigatorUtils.findViewPart(ModelExplorerPageBookView.VIEW_ID); - if(bookViewPart != null) { - modelExplorerView = (ModelExplorerView)bookViewPart.getActiveView(); - } - modelExplorerView.getCommonViewer().expandAll(); - // Set selection on new element in the model explorer - if((modelExplorerView != null) && (newDiagrams != null)) { - List semanticElementList = new ArrayList(); - semanticElementList.addAll(newDiagrams); - // reveal 'container' of the diagram - - modelExplorerView.revealSemanticElement(semanticElementList); - //reveal(semanticElementList, modelExplorerView.getCommonViewer()); - } else { - throw new Exception("Impossible to find the model explorer required to select: " + newDiagrams); - } - } - - /** - * Expands the given CommonViewer to reveal the given elements - * - * @param elementList - * The elements to reveal - * @param commonViewer - * The CommonViewer they are to be revealed in - */ - public static void reveal(final Iterable elementList, final CommonViewer commonViewer) { - ArrayList matchingItemsToSelect = new ArrayList(); - // filter out non EMF objects - for(Diagram currentEObject : elementList) { - matchingItemsToSelect.add(new ModelElementItemMatchingItem(currentEObject)); - // the content provider exist? - if(commonViewer.getContentProvider() != null) { - // retrieve the ancestors to reveal them - // and allow the selection of the object - ArrayList parents = new ArrayList(); - // retrieve context - EObject tmp = currentEObject.getElement(); - while(tmp != null) { - parents.add(tmp); - tmp = tmp.eContainer(); - } - List reverseParents = new ArrayList(parents); - Collections.reverse(reverseParents); - // reveal the resource if necessary - Resource r = null; - if(!parents.isEmpty()) { - r = parents.get(parents.size() - 1).eResource(); - } else { - r = currentEObject.eResource(); - } - if(r != null) { - ResourceSet rs = r.getResourceSet(); - if(rs instanceof ModelSet && AdditionalResourcesModel.isAdditionalResource((ModelSet)rs, r.getURI())) { - commonViewer.expandToLevel(new ReferencableMatchingItem(rs), 1); - commonViewer.expandToLevel(new ReferencableMatchingItem(r), 1); - } - } - /* - * reveal the ancestors tree using expandToLevel on each of them - * in the good order. This is a lot faster than going through the whole tree - * using getChildren of the ContentProvider since our Viewer uses a Hashtable - * to keep track of the revealed elements. - * - * However we need to use a dedicated MatchingItem to do the matching, - * and a specific comparer in our viewer so than the equals of MatchingItem is - * used in priority. - * - * Please refer to MatchingItem for more infos. - */ - EObject previousParent = null; - for(EObject parent : reverseParents) { - if(parent.eContainingFeature() != null && previousParent != null) { - commonViewer.expandToLevel(new LinkItemMatchingItem(previousParent, parent.eContainmentFeature()), 1); - } - commonViewer.expandToLevel(new ModelElementItemMatchingItem(parent), 1); - previousParent = parent; - } - commonViewer.expandToLevel(new LinkItemMatchingItem(currentEObject.eContainer(), currentEObject.eContainmentFeature()), 1); - } - } - commonViewer.setSelection(new StructuredSelection(matchingItemsToSelect), true); - } - - /** - * Returns the diagram with the given name - * - * @param name - * the name of the diagram to find - * @return the diagram with the given name. - * @exception Exception - * exception thrown in case of issue, e.g. diagram was not found - */ - protected static Diagram getDiagram(String name) throws Exception { - Iterator it = EditorUtils.getDiagramEditPart().getDiagramView().eResource().getContents().iterator(); - while(it.hasNext()) { - EObject next = it.next(); - if(next instanceof Diagram) { - if(name.equals(((Diagram)next).getName())) { - return (Diagram)next; - } - } - } - return null; - } - - /** - * Retrieves the Model Element Item for the given EObject - * - * @param objectToFind - * object represented by the searched item - * @return the {@link ModelElementItem} that corresponds to the diagram - * @throws Exception - * exception thrown in case of issue - */ - protected EObjectTreeElement findSemanticModelElementItem(EObject objectToFind) throws Exception { - selectAndReveal(objectToFind); - IStructuredSelection selection = (IStructuredSelection)modelExplorerPart.getSite().getSelectionProvider().getSelection(); - Assert.assertEquals("one and only one object should be selected", 1, selection.size()); - Object selectedElement = selection.getFirstElement(); - Assert.assertTrue("selection should be a model item element", selectedElement instanceof EObjectTreeElement); - Assert.assertTrue("selection should be linked to a EObject", ((EObjectTreeElement)selectedElement).getEObject() instanceof EObject); - Assert.assertTrue("selection should be linked to the Object: " + objectToFind, ((EObjectTreeElement)selectedElement).getEObject().equals(objectToFind)); - return (EObjectTreeElement)selectedElement; - } - - /** - * Retrieves the Model Element Item for the given Diagram - * - * @param diagramToFind - * diagram represented by the searched item - * @return the {@link ModelElementItem} that corresponds to the diagram - * @throws Exception - * exception thrown in case of issue - */ - protected EObjectTreeElement findSemanticModelElementItem(Diagram diagramToFind) throws Exception { - - selectAndRevealDiagram(diagramToFind); - IStructuredSelection selection = (IStructuredSelection)modelExplorerPart.getSite().getSelectionProvider().getSelection(); - Assert.assertEquals("one and only one diagram should be selected", 1, selection.size()); - Object selectedElement = selection.getFirstElement(); - Assert.assertTrue("selection should be a model item element", selectedElement instanceof EObjectTreeElement); - Assert.assertTrue("selection should be linked to a Diagram", ((EObjectTreeElement)selectedElement).getEObject() instanceof Diagram); - Assert.assertTrue("selection should be linked to the Object: " + diagramToFind, ((EObjectTreeElement)selectedElement).getEObject().equals(diagramToFind)); - return (EObjectTreeElement)selectedElement; - } - - protected String printElement(EObject object) { - if(object instanceof Diagram) { - return printElement((Diagram)object); - } else if(object instanceof NamedElement) { - return printElement((NamedElement)object); - } - return EcoreUtil.getID(object); - } - - protected String printElement(NamedElement element) { - return element.getName() + " <" + element.eClass().getName() + ">"; - } - - protected String printElement(Diagram diagram) { - return diagram.getName() + " <" + diagram.getType() + ">"; - } - -} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteBlockTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteBlockTest.java deleted file mode 100644 index e927a51dbca..00000000000 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteBlockTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2011 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: - * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation - * - * @Generated from Block - Model - * - *****************************************************************************/ -package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.papyrus.infra.core.utils.FilteredCollectionView; -import org.eclipse.papyrus.infra.core.utils.IFilter; -import org.eclipse.uml2.uml.Property; -import org.junit.Assert; - - -/** - * Test for Copy / Paste of a Part - */ -public abstract class AbstractCopyPasteBlockTest extends AbstractCopyPasteTest { - - /** - * {@inheritDoc} - * - * @generated - */ - @Override - protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { - super.initializeTest(additionalChecks, targetContainer, copiedEObject); - - /* pre-copy initialization */ - List originalParts = new ArrayList(); for(Property p : ((org.eclipse.uml2.uml.Class)copiedEObject).getAllAttributes()) { if(new org.eclipse.papyrus.sysml.service.types.matcher.PartPropertyMatcher().matches(p)) {originalParts.add(p);}} additionalChecks.put("originalParts", originalParts); - /* END OF pre-copy initialization */ - } - - /** - * {@inheritDoc} - * - * @generated - */ - @Override - protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { - super.postCopyAdditionalChecks(originalModel, newValues, delta); - - /* post copy checks */ - FilteredCollectionView newClasses = new FilteredCollectionView(delta, new IFilter() { /** * {@inheritDoc} */ public boolean isAllowed(Object object) { return object instanceof org.eclipse.uml2.uml.Class && !(object instanceof org.eclipse.uml2.uml.Association); } }); Assert.assertEquals("New values should contain a Class", 1, newClasses.size()); org.eclipse.uml2.uml.Class newBlock = newClasses.toArray(new org.eclipse.uml2.uml.Class[]{})[0]; Assert.assertNotNull("Block stereotype should be applied", ((org.eclipse.uml2.uml.Class) newBlock) .getAppliedStereotype("SysML::Blocks::Block")); List originalParts = (List) originalModel .get("originalParts"); List newParts = new ArrayList(); for (Property p : ((org.eclipse.uml2.uml.Class) newBlock) .getAllAttributes()) { if (new org.eclipse.papyrus.sysml.service.types.matcher.PartPropertyMatcher().matches(p)) { newParts.add(p); Assert.assertNotNull( "Part should have an associated association.", p.getAssociation()); } } Assert.assertEquals( "Both original and new list of attributes should be quivalent for the blocks", originalParts.size(), newParts.size()); - /* END OF post copy checks */ - } - -} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPastePartTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPastePartTest.java deleted file mode 100644 index b22fd5ed6f2..00000000000 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPastePartTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2011 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: - * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation - * - * @Generated from Part - Model - * - *****************************************************************************/ -package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; - -import java.util.List; -import java.util.Map; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.uml2.uml.Association; -import org.eclipse.uml2.uml.Property; -import org.junit.Assert; - - -/** - * Test for Copy / Paste of a Part - */ -public abstract class AbstractCopyPastePartTest extends AbstractCopyPasteTest { - - /** - * {@inheritDoc} - * @generated - */ - @Override - protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { - super.initializeTest(additionalChecks, targetContainer, copiedEObject); - - /* pre-copy initialization */ - - /* END OF pre-copy initialization */ - } - - /** - * {@inheritDoc} - * @generated - */ - @Override - protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { - super.postCopyAdditionalChecks(originalModel, newValues, delta); - - /* post copy checks */ - Association newAssociation = ((Property)newValues.get(0)).getAssociation(); Assert.assertNotNull("New Part should have an association", newAssociation); - /* END OF post copy checks */ - } - -} - - diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteReferenceTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteReferenceTest.java deleted file mode 100644 index 86132c3435c..00000000000 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteReferenceTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2011 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: - * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation - * - * @Generated from Reference - Model - * - *****************************************************************************/ -package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; - -import java.util.List; -import java.util.Map; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.uml2.uml.Association; -import org.eclipse.uml2.uml.Property; -import org.junit.Assert; - - - -/** - * Test for Copy / Paste of a Part - */ -public abstract class AbstractCopyPasteReferenceTest extends AbstractCopyPasteTest { - - /** - * {@inheritDoc} - * @generated - */ - @Override - protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { - super.initializeTest(additionalChecks, targetContainer, copiedEObject); - - /* pre-copy initialization */ - - /* END OF pre-copy initialization */ - } - - /** - * {@inheritDoc} - * @generated - */ - @Override - protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { - super.postCopyAdditionalChecks(originalModel, newValues, delta); - - /* post copy checks */ - Association newAssociation = ((Property)newValues.get(0)).getAssociation(); Assert.assertNotNull("New Reference should have an association", newAssociation); - /* END OF post copy checks */ - } - -} - - diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteTest.java deleted file mode 100644 index ce272d6528a..00000000000 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2011 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: - * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation - * - * @Generated from Model - * - *****************************************************************************/ -package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import junit.framework.Assert; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.papyrus.sysml.modelexplorer.tests.common.AbstractModelExplorerTest; -import org.eclipse.ui.IWorkbenchCommandConstants; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.commands.ICommandService; - - -/** - * Abstract class for Copy/paste - */ -public abstract class AbstractCopyPasteTest extends AbstractModelExplorerTest { - - /** - * Generic implementation of the test - * - * @throws Exception - * exception thrown when the test has problems - */ - protected void testExecutableCopyPaste(EObject targetContainer, EObject copiedEObject, String featureName, int expectedNumberOfAddedElements) throws Exception { - testExecutableCopyPaste(targetContainer, copiedEObject, targetContainer.eClass().getEStructuralFeature(featureName), expectedNumberOfAddedElements); - } - - /** - * Generic implementation of the test - * - * @throws Exception - * exception thrown when the test has problems - */ - protected void testExecutableCopyPaste(EObject targetContainer, EObject copiedEObject, EStructuralFeature feature, int expectedNumberOfAddedElements) throws Exception { - // retrieve elements in the model explorer - selectAndReveal(targetContainer); - - List originalValues = new ArrayList((List)targetContainer.eGet(feature)); - - Map originalModel = new HashMap(); - initializeTest(originalModel, targetContainer, copiedEObject); - - // try to paste in several places - // copy Paste b1EObject - ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class); - commandService.refreshElements(IWorkbenchCommandConstants.EDIT_PASTE, null); - org.eclipse.core.commands.Command pasteCommand = commandService.getCommand(IWorkbenchCommandConstants.EDIT_PASTE); - Assert.assertNotNull("Impossible to find paste command", pasteCommand); - Assert.assertTrue("command in not enabled", pasteCommand.isEnabled()); - Assert.assertTrue("command in not defined", pasteCommand.isDefined()); - - pasteCommand.executeWithChecks(new ExecutionEvent()); - - // check editor state (should be non dirty) - Assert.assertTrue("Editor should be dirty after paste command execution", isEditorDirty()); - - - // should retrieve a new Part AND a new association - List newValues = (List)targetContainer.eGet(feature); - // compute delta - List delta = new ArrayList(); - for(EObject o : newValues) { - if(!originalValues.contains(o)) { - delta.add(o); - } - } - - // size = original size +1 - Assert.assertEquals("Wrong number of attributes after paste", expectedNumberOfAddedElements, delta.size()); - - // part should be linked to an association - postCopyAdditionalChecks(originalModel, newValues, delta); - - // undo - if(getEditingDomain().getCommandStack().canUndo()) { - getEditingDomain().getCommandStack().undo(); - } else { - throw new Exception("Impossible to undo the paste command: " + pasteCommand); - } - // check editor state (should be non dirty) - Assert.assertFalse("Editor should not be dirty after undo", isEditorDirty()); - // check old values equals the actual values - newValues = (List)targetContainer.eGet(feature); - Assert.assertEquals("Initial and current list feature list should be equivalent", newValues, originalValues); - - // redo - if(getEditingDomain().getCommandStack().canRedo()) { - getEditingDomain().getCommandStack().redo(); - } else { - throw new Exception("Impossible to redo the paste command: " + pasteCommand); - } - // check editor state (should be non dirty) - Assert.assertTrue("Editor should not dirty after redo", isEditorDirty()); - - // check as it was the result of the paste command - newValues = (List)targetContainer.eGet(feature); - delta = new ArrayList(); - for(EObject o : newValues) { - if(!originalValues.contains(o)) { - delta.add(o); - } - } - - // size = original size + delta - Assert.assertEquals("Wrong number of attributes after paste", expectedNumberOfAddedElements, delta.size()); - - // part should be linked to an association - postCopyAdditionalChecks(originalModel, newValues, delta); - - // undo again, to restore state - if(getEditingDomain().getCommandStack().canUndo()) { - getEditingDomain().getCommandStack().undo(); - } else { - throw new Exception("Impossible to re-undo the paste command: " + pasteCommand); - } - // check editor state (should be non dirty) - Assert.assertFalse("Editor should not be dirty after undo", isEditorDirty()); - - } - - /** - * executes additional checks on the new value - * - * @param originalModel - * the map containing all values stored before launching the test - * @param newValue - * the new value, result of the copy - * @param delta - * differences between original list and the new one - */ - protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { - // use the values contained in the map to do additional checks - } - - protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { - // nothing to do here - } -} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlock2Test.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlock2Test.java deleted file mode 100644 index f1fc8a85487..00000000000 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlock2Test.java +++ /dev/null @@ -1,114 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2011 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: - * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation - * - * @Generated from SimpleBlock2 - Model - * - *****************************************************************************/ -package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; - -import java.util.List; -import java.util.Map; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkbenchCommandConstants; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.commands.ICommandService; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - - -/** - * Test for Copy / Paste of a Part - */ -public class CopyPasteSimpleBlock2Test extends AbstractCopyPasteBlockTest { - - /** - * prepare the copy - * - * @throws Exception - * exception thrown in case of problems - */ - @Before - public void testPrepare() throws Exception { - // check editor state (should be non dirty) - //FIXME: In Papyrus, the editor may be dirty at initialization. This should not be tested here. We simply save the editor as soon as it is opened. - Display.getDefault().syncExec(new Runnable() { - - public void run() { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor()); - } - }); - // retrieve elements in the model explorer - selectAndReveal(b1P1_P1_EObject); - - // copy Paste - ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class); - commandService.refreshElements(IWorkbenchCommandConstants.EDIT_COPY, null); - org.eclipse.core.commands.Command copyCommand = commandService.getCommand(IWorkbenchCommandConstants.EDIT_COPY); - Assert.assertNotNull("Impossible to find copy command", copyCommand); - Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); - Assert.assertTrue("command in not defined", copyCommand.isDefined()); - copyCommand.executeWithChecks(new ExecutionEvent()); - - // check editor state (should be non dirty) - Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); - } - - @Override - protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { - super.initializeTest(additionalChecks, targetContainer, copiedEObject); - - /* pre-copy initialization */ - - /* END OF pre-copy initialization */ - } - - /** - * {@inheritDoc} - */ - @Override - protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { - super.postCopyAdditionalChecks(originalModel, newValues, delta); - - /* post copy checks */ - - /* END OF post copy checks */ - } - - - /** - * Test the copy /paste on P1 - * - * @throws Exception - * exception thrown in case of problems - */ - @Test - public void testCopyPasteInP1() throws Exception { - testExecutableCopyPaste(p1_EObject, b1P1_P1_EObject, "ownedElement", 3); - } - - /** - * Test the copy /paste on model - * - * @throws Exception - * exception thrown in case of problems - */ - @Test - public void testCopyPasteInmodel() throws Exception { - testExecutableCopyPaste(model_EObject, b1P1_P1_EObject, "ownedElement", 3); - } - - -} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlockTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlockTest.java deleted file mode 100644 index 689dc65f0e5..00000000000 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlockTest.java +++ /dev/null @@ -1,125 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2011 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: - * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation - * - * @Generated from SimpleBlock - Model - * - *****************************************************************************/ -package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; - -import java.util.List; -import java.util.Map; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RunnableWithResult; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkbenchCommandConstants; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.commands.ICommandService; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - - -/** - * Test for Copy / Paste of a Part - */ -public class CopyPasteSimpleBlockTest extends AbstractCopyPasteBlockTest { - - /** - * prepare the copy - * - * @throws Exception - * exception thrown in case of problems - */ - @Before - public void testPrepare() throws Exception { - // check editor state (should be non dirty) - //FIXME: In Papyrus, the editor may be dirty at initialization. This should not be tested here. We simply save the editor as soon as it is opened. - Display.getDefault().syncExec(new Runnable() { - - public void run() { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor()); - } - }); - // retrieve elements in the model explorer - selectAndReveal(b1_EObject); - - // copy Paste - RunnableWithResult runnable; - Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl() { - - public void run() { - ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(ICommandService.class); - setResult(commandService); - } - }); - - ICommandService commandService = runnable.getResult(); - - commandService.refreshElements(IWorkbenchCommandConstants.EDIT_COPY, null); - org.eclipse.core.commands.Command copyCommand = commandService.getCommand(IWorkbenchCommandConstants.EDIT_COPY); - Assert.assertNotNull("Impossible to find copy command", copyCommand); - Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); - Assert.assertTrue("command in not defined", copyCommand.isDefined()); - copyCommand.executeWithChecks(new ExecutionEvent()); - - // check editor state (should be non dirty) - Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); - } - - @Override - protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { - super.initializeTest(additionalChecks, targetContainer, copiedEObject); - - /* pre-copy initialization */ - - /* END OF pre-copy initialization */ - } - - /** - * {@inheritDoc} - */ - @Override - protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { - super.postCopyAdditionalChecks(originalModel, newValues, delta); - - /* post copy checks */ - - /* END OF post copy checks */ - } - - - /** - * Test the copy /paste on P1 - * - * @throws Exception - * exception thrown in case of problems - */ - @Test - public void testCopyPasteInP1() throws Exception { - testExecutableCopyPaste(p1_EObject, b1_EObject, "ownedElement", 4); - } - - /** - * Test the copy /paste on model - * - * @throws Exception - * exception thrown in case of problems - */ - @Test - public void testCopyPasteInmodel() throws Exception { - testExecutableCopyPaste(model_EObject, b1_EObject, "ownedElement", 4); - } - - -} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimplePartTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimplePartTest.java deleted file mode 100644 index c0cde11a21a..00000000000 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimplePartTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2011 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: - * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation - * - * @Generated from SimplePart - Model - * - *****************************************************************************/ -package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; - -import java.util.List; -import java.util.Map; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkbenchCommandConstants; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.commands.ICommandService; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - - -/** - * Test for Copy / Paste of a Part - */ -public class CopyPasteSimplePartTest extends AbstractCopyPastePartTest { - - /** - * prepare the copy - * - * @throws Exception - * exception thrown in case of problems - */ - @Before - public void testPrepare() throws Exception { - // check editor state (should be non dirty) - //FIXME: In Papyrus, the editor may be dirty at initialization. This should not be tested here. We simply save the editor as soon as it is opened. - Display.getDefault().syncExec(new Runnable() { - - public void run() { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor()); - } - }); - // retrieve elements in the model explorer - selectAndReveal(pB2_B1_EObject); - - // copy Paste - ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class); - commandService.refreshElements(IWorkbenchCommandConstants.EDIT_COPY, null); - org.eclipse.core.commands.Command copyCommand = commandService.getCommand(IWorkbenchCommandConstants.EDIT_COPY); - Assert.assertNotNull("Impossible to find copy command", copyCommand); - Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); - Assert.assertTrue("command in not defined", copyCommand.isDefined()); - copyCommand.executeWithChecks(new ExecutionEvent()); - - // check editor state (should be non dirty) - Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); - } - - @Override - protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { - super.initializeTest(additionalChecks, targetContainer, copiedEObject); - - /* pre-copy initialization */ - - /* END OF pre-copy initialization */ - } - - /** - * {@inheritDoc} - */ - @Override - protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { - super.postCopyAdditionalChecks(originalModel, newValues, delta); - - /* post copy checks */ - - /* END OF post copy checks */ - } - - - /** - * Test the copy /paste on B1 - * - * @throws Exception - * exception thrown in case of problems - */ - @Test - public void testCopyPasteInB1() throws Exception { - testExecutableCopyPaste(b1_EObject, pB2_B1_EObject, "attribute", 1); - } - - /** - * Test the copy /paste on B2 - * - * @throws Exception - * exception thrown in case of problems - */ - @Test - public void testCopyPasteInB2() throws Exception { - testExecutableCopyPaste(b2_EObject, pB2_B1_EObject, "attribute", 1); - } - - /** - * Test the copy /paste on B1P1 - * - * @throws Exception - * exception thrown in case of problems - */ - @Test - public void testCopyPasteInB1P1() throws Exception { - testExecutableCopyPaste(b1P1_P1_EObject, pB2_B1_EObject, "attribute", 1); - } - - /** - * Test the copy /paste on B2P1 - * - * @throws Exception - * exception thrown in case of problems - */ - @Test - public void testCopyPasteInB2P1() throws Exception { - testExecutableCopyPaste(b2P1_P1_EObject, pB2_B1_EObject, "attribute", 1); - } - - -} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleReferenceTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleReferenceTest.java deleted file mode 100644 index 982bf214bf1..00000000000 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleReferenceTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2011 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: - * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation - * - * @Generated from SimpleReference - Model - * - *****************************************************************************/ -package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; - -import java.util.List; -import java.util.Map; - -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkbenchCommandConstants; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.commands.ICommandService; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - - -/** - * Test for Copy / Paste of a Part - */ -public class CopyPasteSimpleReferenceTest extends AbstractCopyPasteReferenceTest { - - /** - * prepare the copy - * - * @throws Exception - * exception thrown in case of problems - */ - @Before - public void testPrepare() throws Exception { - // check editor state (should be non dirty) - //FIXME: In Papyrus, the editor may be dirty at initialization. This should not be tested here. We simply save the editor as soon as it is opened. - Display.getDefault().syncExec(new Runnable() { - - public void run() { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor()); - } - }); - - Assert.assertFalse("Editor should not be dirty at initialization", isEditorDirty()); - // retrieve elements in the model explorer - selectAndReveal(rB2_B1_EObject); - - // copy Paste - ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class); - commandService.refreshElements(IWorkbenchCommandConstants.EDIT_COPY, null); - org.eclipse.core.commands.Command copyCommand = commandService.getCommand(IWorkbenchCommandConstants.EDIT_COPY); - Assert.assertNotNull("Impossible to find copy command", copyCommand); - Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); - Assert.assertTrue("command in not defined", copyCommand.isDefined()); - copyCommand.executeWithChecks(new ExecutionEvent()); - - // check editor state (should be non dirty) - // Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); - - // NOTE: save editor. The copy command should not dirty the model, the implementation of the copy command or the editor should be modified - Assert.assertFalse("Copy command is dirtying the model, whereas it should not. This assert is here to remember that the test code should be modified: Isdirty = false after copy...", isEditorDirty()); - Display.getDefault().syncExec(new Runnable() { - - public void run() { - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor()); - } - }); - - Assert.assertFalse("Save command is non-dirtying the model, whereas it should. ", isEditorDirty()); - // END NOTE - } - - @Override - protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { - super.initializeTest(additionalChecks, targetContainer, copiedEObject); - - /* pre-copy initialization */ - - /* END OF pre-copy initialization */ - } - - /** - * {@inheritDoc} - */ - @Override - protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { - super.postCopyAdditionalChecks(originalModel, newValues, delta); - - /* post copy checks */ - - /* END OF post copy checks */ - } - - - /** - * Test the copy /paste on B1 - * - * @throws Exception - * exception thrown in case of problems - */ - @Test - public void testCopyPasteInB1() throws Exception { - testExecutableCopyPaste(b1_EObject, rB2_B1_EObject, "attribute", 1); - } - - /** - * Test the copy /paste on B2 - * - * @throws Exception - * exception thrown in case of problems - */ - @Test - public void testCopyPasteInB2() throws Exception { - testExecutableCopyPaste(b2_EObject, rB2_B1_EObject, "attribute", 1); - } - - /** - * Test the copy /paste on B1P1 - * - * @throws Exception - * exception thrown in case of problems - */ - @Test - public void testCopyPasteInB1P1() throws Exception { - testExecutableCopyPaste(b1P1_P1_EObject, rB2_B1_EObject, "attribute", 1); - } - - /** - * Test the copy /paste on B2P1 - * - * @throws Exception - * exception thrown in case of problems - */ - @Test - public void testCopyPasteInB2P1() throws Exception { - testExecutableCopyPaste(b2P1_P1_EObject, rB2_B1_EObject, "attribute", 1); - } - - -} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/suites/AllCopyPasteTests.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/suites/AllCopyPasteTests.java deleted file mode 100644 index ae8eb63df81..00000000000 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test-gen/org/eclipse/papyrus/sysml/modelexplorer/tests/suites/AllCopyPasteTests.java +++ /dev/null @@ -1,41 +0,0 @@ - /***************************************************************************** - * Copyright (c) 2011 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: - * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation - * @generated - *****************************************************************************/ -package org.eclipse.papyrus.sysml.modelexplorer.tests.suites; - -import org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste.CopyPasteSimpleBlock2Test; -import org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste.CopyPasteSimpleBlockTest; -import org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste.CopyPasteSimplePartTest; -import org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste.CopyPasteSimpleReferenceTest; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.junit.runners.Suite.SuiteClasses; - - -/** - * Tests suite for Copy/Paste - * @generated - */ -@RunWith(Suite.class) -@SuiteClasses({ -// Reference -CopyPasteSimpleReferenceTest.class, -// Block -CopyPasteSimpleBlockTest.class, -CopyPasteSimpleBlock2Test.class, -// Part -CopyPasteSimplePartTest.class, - -}) -public class AllCopyPasteTests { - -} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/common/AbstractModelExplorerTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/common/AbstractModelExplorerTest.java new file mode 100644 index 00000000000..1c386641ccf --- /dev/null +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/common/AbstractModelExplorerTest.java @@ -0,0 +1,525 @@ +/***************************************************************************** + * Copyright (c) 2011 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: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + * + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.modelexplorer.tests.common; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.junit.Assert; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.custom.Customization; +import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EObjectTreeElement; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.core.resource.additional.AdditionalResourcesModel; +import org.eclipse.papyrus.sysml.modelexplorer.Activator; +import org.eclipse.papyrus.sysml.modelexplorer.tests.utils.EditorUtils; +import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView; +import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView; +import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils; +import org.eclipse.papyrus.views.modelexplorer.matching.IMatchingItem; +import org.eclipse.papyrus.views.modelexplorer.matching.LinkItemMatchingItem; +import org.eclipse.papyrus.views.modelexplorer.matching.ModelElementItemMatchingItem; +import org.eclipse.papyrus.views.modelexplorer.matching.ReferencableMatchingItem; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.navigator.CommonViewer; +import org.eclipse.ui.part.FileEditorInput; +import org.eclipse.uml2.uml.Model; +import org.eclipse.uml2.uml.NamedElement; +import org.junit.AfterClass; +import org.junit.BeforeClass; + + + +/** + * Abstract class for Copy/paste + */ +public abstract class AbstractModelExplorerTest { + + /** boolean to indicate if the test is initialized or not */ + private static boolean isInitialized; + + /** main papyrus editor */ + public static IEditorPart editor = null; + + /** id of the papyrus editor */ + public static String editorID = "org.eclipse.papyrus.infra.core.papyrusEditor"; + + /** view part: the model explorer */ + protected static IViewPart modelExplorerPart; + + /** generated selectable objects */ + protected static org.eclipse.uml2.uml.Model model_EObject; + + protected static org.eclipse.uml2.uml.Class b1_EObject; + + protected static org.eclipse.uml2.uml.Property pB1P1_B1_EObject; + + protected static org.eclipse.uml2.uml.Property rB2_B1_EObject; + + protected static org.eclipse.uml2.uml.Property pB2_B1_EObject; + + protected static org.eclipse.uml2.uml.Class b2_EObject; + + protected static org.eclipse.uml2.uml.Package p1_EObject; + + protected static org.eclipse.uml2.uml.Class b2P1_P1_EObject; + + protected static org.eclipse.uml2.uml.Class b1P1_P1_EObject; + + protected static org.eclipse.uml2.uml.Property pB1_B1P1_P1_EObject; + + protected static org.eclipse.uml2.uml.Property pB2P1_B1P1_P1_EObject; + + protected static Diagram iBD_B1_Diagram; + + protected static Diagram bDD_Main_Diagram; + + /** end of generated selectable objects */ + + /** + * Initialization of the test + * + * @throws Exception + * thrown when initialization has problem + */ + @BeforeClass + public static void openPapyrusWithAnEmptyProject() throws Exception { + // Prepare new project for tests + IProject testProject = ResourcesPlugin.getWorkspace().getRoot().getProject("TestCopyPasteProject"); + if(!testProject.exists()) { + testProject.create(new NullProgressMonitor()); + } + + if(!testProject.isOpen()) { + testProject.open(new NullProgressMonitor()); + } + + // Copy EmptyModel from bundle to the test project + final IFile emptyModel_di = testProject.getFile("ModelWithBDD.di"); + IFile emptyModel_no = testProject.getFile("ModelWithBDD.notation"); + IFile emptyModel_uml = testProject.getFile("ModelWithBDD.uml"); + + // isInitialized = isInitialized || emptyModel_di.exists(); + + if(!isInitialized) { + isInitialized = true; + emptyModel_di.create(Activator.getDefault().getBundle().getResource("/model/ModelWithBDD.di").openStream(), true, new NullProgressMonitor()); + emptyModel_no.create(Activator.getDefault().getBundle().getResource("/model/ModelWithBDD.notation").openStream(), true, new NullProgressMonitor()); + emptyModel_uml.create(Activator.getDefault().getBundle().getResource("/model/ModelWithBDD.uml").openStream(), true, new NullProgressMonitor()); + } + + // Open the EmptyModel.di file with Papyrus (assumed to be the default editor for "di" files here). + Display.getDefault().syncExec(new Runnable() { + + public void run() { + try { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + editor = page.openEditor(new FileEditorInput(emptyModel_di), editorID); + + modelExplorerPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ModelExplorerPageBookView.VIEW_ID); + modelExplorerPart.setFocus(); + } catch (Exception ex) { + ex.printStackTrace(System.out); + } + } + }); + + Assert.assertNotNull("Model explorer is null", modelExplorerPart); + + prepareTest(); + } + + /** + * Prepare the diagram before testing + * + * @throws Exception + * exception thrown in case of problem + */ + public static void prepareTest() throws Exception { + DiagramEditPart diagramEditPart = EditorUtils.getDiagramEditPart(); + EObject root = diagramEditPart.getDiagramView().getElement(); + + Assert.assertTrue("Impossible to find main model", root instanceof Model); + + /** generated selectable objects */ + model_EObject = (org.eclipse.uml2.uml.Model)root; + b1_EObject = (org.eclipse.uml2.uml.Class)model_EObject.getPackagedElement("B1"); + Assert.assertNotNull("Impossible to find Class B1", b1_EObject); + pB1P1_B1_EObject = b1_EObject.getAttribute("pB1P1", null); + Assert.assertNotNull("Impossible to find Property pB1P1", pB1P1_B1_EObject); + rB2_B1_EObject = b1_EObject.getAttribute("rB2", null); + Assert.assertNotNull("Impossible to find Property rB2", rB2_B1_EObject); + pB2_B1_EObject = b1_EObject.getAttribute("pB2", null); + Assert.assertNotNull("Impossible to find Property pB2", pB2_B1_EObject); + + b2_EObject = (org.eclipse.uml2.uml.Class)model_EObject.getPackagedElement("B2"); + Assert.assertNotNull("Impossible to find Class B2", b2_EObject); + + p1_EObject = (org.eclipse.uml2.uml.Package)model_EObject.getPackagedElement("P1"); + Assert.assertNotNull("Impossible to find Package P1", p1_EObject); + b2P1_P1_EObject = (org.eclipse.uml2.uml.Class)p1_EObject.getPackagedElement("B2P1"); + Assert.assertNotNull("Impossible to find Class B2P1", b2P1_P1_EObject); + + b1P1_P1_EObject = (org.eclipse.uml2.uml.Class)p1_EObject.getPackagedElement("B1P1"); + Assert.assertNotNull("Impossible to find Class B1P1", b1P1_P1_EObject); + pB1_B1P1_P1_EObject = b1P1_P1_EObject.getAttribute("pB1", null); + Assert.assertNotNull("Impossible to find Property pB1", pB1_B1P1_P1_EObject); + pB2P1_B1P1_P1_EObject = b1P1_P1_EObject.getAttribute("pB2P1", null); + Assert.assertNotNull("Impossible to find Property pB2P1", pB2P1_B1P1_P1_EObject); + + + + + + iBD_B1_Diagram = getDiagram("IBD_B1"); + Assert.assertNotNull("Impossible to find IBD_B1", iBD_B1_Diagram); + bDD_Main_Diagram = getDiagram("BDD_Main"); + Assert.assertNotNull("Impossible to find BDD_Main", bDD_Main_Diagram); + List appliedCustomizations=org.eclipse.papyrus.views.modelexplorer.Activator.getDefault().getCustomizationManager().getManagedCustomizations(); + Customization SimpleUML=null; + Iteratoriter=appliedCustomizations.iterator(); + while(iter.hasNext()) { + Customization custo = (Customization)iter.next(); + if( custo.getName().equals("SimpleUML")){ + SimpleUML=custo; + } + } + org.junit.Assert.assertNotNull("Custom SimpleUML not found", SimpleUML); + org.eclipse.papyrus.views.modelexplorer.Activator.getDefault().getCustomizationManager().getManagedCustomizations().add(0, SimpleUML); + + + + org.junit.Assert.assertEquals("bad order of applied Custom", "SimpleUML", appliedCustomizations.get(0).getName()); + + /** end of generated selectable objects */ + } + + /** + * Close editor + * + * @throws Exception + * exception thrown in case of problem + */ + @AfterClass + public static void closePapyrusAndCleanProject() throws Exception { + // Close the editor without saving content created during tests + Display.getDefault().syncExec(new Runnable() { + + public void run() { + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + page.closeEditor(editor, false); + } + }); + + editor = null; + modelExplorerPart = null; + } + + + /** + * Selects and reveal the specified element + * + * @param object + * the object to select + * @throws Exception + * exception thrown in case element could not be selected + */ + public static void selectAndReveal(final EObject object) throws Exception { + Display.getDefault().syncExec(new Runnable() { + + public void run() { + try { + selectAndReveal(Arrays.asList(object)); + } catch (Exception ex) { + ex.printStackTrace(System.out); + } + } + }); + } + + /** + * Selects and reveal the specified list of elements + * + * @param newElements + * the list of objects to select + * @throws Exception + * exception thrown in case element could not be selected + */ + public static void selectAndReveal(List newElements) throws Exception { + // Retrieve model explorer + ModelExplorerView modelExplorerView = null; + + ModelExplorerPageBookView bookViewPart = (ModelExplorerPageBookView)NavigatorUtils.findViewPart(ModelExplorerPageBookView.VIEW_ID); + if(bookViewPart != null) { + modelExplorerView = (ModelExplorerView)bookViewPart.getActiveView(); + } + + // Set selection on new element in the model explorer + if((modelExplorerView != null) && (newElements != null)) { + List semanticElementList = new ArrayList(); + semanticElementList.addAll(newElements); + modelExplorerView.revealSemanticElement(semanticElementList); + } else { + throw new Exception("Impossible to find the model explorer required to select: " + newElements); + } + } + + /** + * Returns the current editing domain + * + * @return + * the current editing domain + */ + protected TransactionalEditingDomain getEditingDomain() throws Exception { + return (TransactionalEditingDomain)editor.getAdapter(TransactionalEditingDomain.class); + } + + /** + * Returns true if the current Active editor is dirty. + * + * @return true if the current Active editor is dirty + * @throws Exception + * exception thrown in case of problem (NPE, etc.) + */ + protected boolean isEditorDirty() throws Exception { + RunnableWithResult runnable; + Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl() { + + public void run() { + setResult(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().isDirty()); + } + }); + + return runnable.getResult(); + } + + /** + * Selects and reveal the specified element + * + * @param object + * the object to select + * @throws Exception + * exception thrown in case element could not be selected + */ + public static void selectAndRevealDiagram(final Diagram object) throws Exception { + Display.getDefault().syncExec(new Runnable() { + + public void run() { + try { + selectAndRevealDiagram(Arrays.asList(object)); + } catch (Exception ex) { + ex.printStackTrace(System.out); + } + } + }); + } + + /** + * Selects and reveal the specified list of diagrams + * + * @param newElements + * the list of diagrams to select + * @throws Exception + * exception thrown in case diagram could not be selected + */ + public static void selectAndRevealDiagram(List newDiagrams) throws Exception { + // Retrieve model explorer + ModelExplorerView modelExplorerView = null; + ModelExplorerPageBookView bookViewPart = (ModelExplorerPageBookView)NavigatorUtils.findViewPart(ModelExplorerPageBookView.VIEW_ID); + if(bookViewPart != null) { + modelExplorerView = (ModelExplorerView)bookViewPart.getActiveView(); + } + modelExplorerView.getCommonViewer().expandAll(); + // Set selection on new element in the model explorer + if((modelExplorerView != null) && (newDiagrams != null)) { + List semanticElementList = new ArrayList(); + semanticElementList.addAll(newDiagrams); + // reveal 'container' of the diagram + + modelExplorerView.revealSemanticElement(semanticElementList); + //reveal(semanticElementList, modelExplorerView.getCommonViewer()); + } else { + throw new Exception("Impossible to find the model explorer required to select: " + newDiagrams); + } + } + + /** + * Expands the given CommonViewer to reveal the given elements + * + * @param elementList + * The elements to reveal + * @param commonViewer + * The CommonViewer they are to be revealed in + */ + public static void reveal(final Iterable elementList, final CommonViewer commonViewer) { + ArrayList matchingItemsToSelect = new ArrayList(); + // filter out non EMF objects + for(Diagram currentEObject : elementList) { + matchingItemsToSelect.add(new ModelElementItemMatchingItem(currentEObject)); + // the content provider exist? + if(commonViewer.getContentProvider() != null) { + // retrieve the ancestors to reveal them + // and allow the selection of the object + ArrayList parents = new ArrayList(); + // retrieve context + EObject tmp = currentEObject.getElement(); + while(tmp != null) { + parents.add(tmp); + tmp = tmp.eContainer(); + } + List reverseParents = new ArrayList(parents); + Collections.reverse(reverseParents); + // reveal the resource if necessary + Resource r = null; + if(!parents.isEmpty()) { + r = parents.get(parents.size() - 1).eResource(); + } else { + r = currentEObject.eResource(); + } + if(r != null) { + ResourceSet rs = r.getResourceSet(); + if(rs instanceof ModelSet && AdditionalResourcesModel.isAdditionalResource((ModelSet)rs, r.getURI())) { + commonViewer.expandToLevel(new ReferencableMatchingItem(rs), 1); + commonViewer.expandToLevel(new ReferencableMatchingItem(r), 1); + } + } + /* + * reveal the ancestors tree using expandToLevel on each of them + * in the good order. This is a lot faster than going through the whole tree + * using getChildren of the ContentProvider since our Viewer uses a Hashtable + * to keep track of the revealed elements. + * + * However we need to use a dedicated MatchingItem to do the matching, + * and a specific comparer in our viewer so than the equals of MatchingItem is + * used in priority. + * + * Please refer to MatchingItem for more infos. + */ + EObject previousParent = null; + for(EObject parent : reverseParents) { + if(parent.eContainingFeature() != null && previousParent != null) { + commonViewer.expandToLevel(new LinkItemMatchingItem(previousParent, parent.eContainmentFeature()), 1); + } + commonViewer.expandToLevel(new ModelElementItemMatchingItem(parent), 1); + previousParent = parent; + } + commonViewer.expandToLevel(new LinkItemMatchingItem(currentEObject.eContainer(), currentEObject.eContainmentFeature()), 1); + } + } + commonViewer.setSelection(new StructuredSelection(matchingItemsToSelect), true); + } + + /** + * Returns the diagram with the given name + * + * @param name + * the name of the diagram to find + * @return the diagram with the given name. + * @exception Exception + * exception thrown in case of issue, e.g. diagram was not found + */ + protected static Diagram getDiagram(String name) throws Exception { + Iterator it = EditorUtils.getDiagramEditPart().getDiagramView().eResource().getContents().iterator(); + while(it.hasNext()) { + EObject next = it.next(); + if(next instanceof Diagram) { + if(name.equals(((Diagram)next).getName())) { + return (Diagram)next; + } + } + } + return null; + } + + /** + * Retrieves the Model Element Item for the given EObject + * + * @param objectToFind + * object represented by the searched item + * @return the {@link ModelElementItem} that corresponds to the diagram + * @throws Exception + * exception thrown in case of issue + */ + protected EObjectTreeElement findSemanticModelElementItem(EObject objectToFind) throws Exception { + selectAndReveal(objectToFind); + IStructuredSelection selection = (IStructuredSelection)modelExplorerPart.getSite().getSelectionProvider().getSelection(); + Assert.assertEquals("one and only one object should be selected", 1, selection.size()); + Object selectedElement = selection.getFirstElement(); + Assert.assertTrue("selection should be a model item element", selectedElement instanceof EObjectTreeElement); + Assert.assertTrue("selection should be linked to a EObject", ((EObjectTreeElement)selectedElement).getEObject() instanceof EObject); + Assert.assertTrue("selection should be linked to the Object: " + objectToFind, ((EObjectTreeElement)selectedElement).getEObject().equals(objectToFind)); + return (EObjectTreeElement)selectedElement; + } + + /** + * Retrieves the Model Element Item for the given Diagram + * + * @param diagramToFind + * diagram represented by the searched item + * @return the {@link ModelElementItem} that corresponds to the diagram + * @throws Exception + * exception thrown in case of issue + */ + protected EObjectTreeElement findSemanticModelElementItem(Diagram diagramToFind) throws Exception { + + selectAndRevealDiagram(diagramToFind); + IStructuredSelection selection = (IStructuredSelection)modelExplorerPart.getSite().getSelectionProvider().getSelection(); + Assert.assertEquals("one and only one diagram should be selected", 1, selection.size()); + Object selectedElement = selection.getFirstElement(); + Assert.assertTrue("selection should be a model item element", selectedElement instanceof EObjectTreeElement); + Assert.assertTrue("selection should be linked to a Diagram", ((EObjectTreeElement)selectedElement).getEObject() instanceof Diagram); + Assert.assertTrue("selection should be linked to the Object: " + diagramToFind, ((EObjectTreeElement)selectedElement).getEObject().equals(diagramToFind)); + return (EObjectTreeElement)selectedElement; + } + + protected String printElement(EObject object) { + if(object instanceof Diagram) { + return printElement((Diagram)object); + } else if(object instanceof NamedElement) { + return printElement((NamedElement)object); + } + return EcoreUtil.getID(object); + } + + protected String printElement(NamedElement element) { + return element.getName() + " <" + element.eClass().getName() + ">"; + } + + protected String printElement(Diagram diagram) { + return diagram.getName() + " <" + diagram.getType() + ">"; + } + +} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteBlockTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteBlockTest.java new file mode 100644 index 00000000000..4b28cca05c6 --- /dev/null +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteBlockTest.java @@ -0,0 +1,61 @@ +/***************************************************************************** + * Copyright (c) 2011 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: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + * + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.papyrus.infra.core.utils.FilteredCollectionView; +import org.eclipse.papyrus.infra.core.utils.IFilter; +import org.eclipse.uml2.uml.Property; +import org.junit.Assert; + + +/** + * Test for Copy / Paste of a Part + */ +public abstract class AbstractCopyPasteBlockTest extends AbstractCopyPasteTest { + + /** + * {@inheritDoc} + * + * + */ + @Override + protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { + super.initializeTest(additionalChecks, targetContainer, copiedEObject); + + /* pre-copy initialization */ + List originalParts = new ArrayList(); for(Property p : ((org.eclipse.uml2.uml.Class)copiedEObject).getAllAttributes()) { if(new org.eclipse.papyrus.sysml.service.types.matcher.PartPropertyMatcher().matches(p)) {originalParts.add(p);}} additionalChecks.put("originalParts", originalParts); + /* END OF pre-copy initialization */ + } + + /** + * {@inheritDoc} + * + * + */ + @Override + protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { + super.postCopyAdditionalChecks(originalModel, newValues, delta); + + /* post copy checks */ + FilteredCollectionView newClasses = new FilteredCollectionView(delta, new IFilter() { /** * {@inheritDoc} */ public boolean isAllowed(Object object) { return object instanceof org.eclipse.uml2.uml.Class && !(object instanceof org.eclipse.uml2.uml.Association); } }); Assert.assertEquals("New values should contain a Class", 1, newClasses.size()); org.eclipse.uml2.uml.Class newBlock = newClasses.toArray(new org.eclipse.uml2.uml.Class[]{})[0]; Assert.assertNotNull("Block stereotype should be applied", ((org.eclipse.uml2.uml.Class) newBlock) .getAppliedStereotype("SysML::Blocks::Block")); List originalParts = (List) originalModel .get("originalParts"); List newParts = new ArrayList(); for (Property p : ((org.eclipse.uml2.uml.Class) newBlock) .getAllAttributes()) { if (new org.eclipse.papyrus.sysml.service.types.matcher.PartPropertyMatcher().matches(p)) { newParts.add(p); Assert.assertNotNull( "Part should have an associated association.", p.getAssociation()); } } Assert.assertEquals( "Both original and new list of attributes should be quivalent for the blocks", originalParts.size(), newParts.size()); + /* END OF post copy checks */ + } + +} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPastePartTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPastePartTest.java new file mode 100644 index 00000000000..6d185d8323d --- /dev/null +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPastePartTest.java @@ -0,0 +1,66 @@ +/***************************************************************************** + * Copyright (c) 2011 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: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + * from Part - Model + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; + +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.uml2.uml.Association; +import org.eclipse.uml2.uml.Property; +import org.junit.Assert; + + +/** + * Test for Copy / Paste of a Part + */ +public abstract class AbstractCopyPastePartTest extends AbstractCopyPasteTest { + + /** + * {@inheritDoc} + * + */ + @Override + protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { + super.initializeTest(additionalChecks, targetContainer, copiedEObject); + + /* pre-copy initialization */ + + /* END OF pre-copy initialization */ + } + + /** + * {@inheritDoc} + * + */ + @Override + protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { + super.postCopyAdditionalChecks(originalModel, newValues, delta); + + /* post copy checks */ + + for(EObject newObject : newValues) { + if (newObject instanceof Property){ + Property property = (Property) newObject; + Association newAssociation = property.getAssociation(); + Assert.assertNotNull("New Part should have an association", newAssociation); //$NON-NLS-1$ + } + } + /* END OF post copy checks */ + } + +} + + diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteReferenceTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteReferenceTest.java new file mode 100644 index 00000000000..1ea66a8dec2 --- /dev/null +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteReferenceTest.java @@ -0,0 +1,60 @@ +/***************************************************************************** + * Copyright (c) 2011 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: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + * from Reference - Model + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; + +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.uml2.uml.Association; +import org.eclipse.uml2.uml.Property; +import org.junit.Assert; + + + +/** + * Test for Copy / Paste of a Part + */ +public abstract class AbstractCopyPasteReferenceTest extends AbstractCopyPasteTest { + + /** + * {@inheritDoc} + * + */ + @Override + protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { + super.initializeTest(additionalChecks, targetContainer, copiedEObject); + + /* pre-copy initialization */ + + /* END OF pre-copy initialization */ + } + + /** + * {@inheritDoc} + * + */ + @Override + protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { + super.postCopyAdditionalChecks(originalModel, newValues, delta); + + /* post copy checks */ + Association newAssociation = ((Property)newValues.get(0)).getAssociation(); Assert.assertNotNull("New Reference should have an association", newAssociation); + /* END OF post copy checks */ + } + +} + + diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteTest.java new file mode 100644 index 00000000000..cef2d877c86 --- /dev/null +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteTest.java @@ -0,0 +1,158 @@ +/***************************************************************************** + * Copyright (c) 2011 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: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + * from Model + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Assert; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.papyrus.sysml.modelexplorer.tests.common.AbstractModelExplorerTest; +import org.eclipse.ui.IWorkbenchCommandConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; + + +/** + * Abstract class for Copy/paste + */ +public abstract class AbstractCopyPasteTest extends AbstractModelExplorerTest { + + /** + * Generic implementation of the test + * + * @throws Exception + * exception thrown when the test has problems + */ + protected void testExecutableCopyPaste(EObject targetContainer, EObject copiedEObject, String featureName, int expectedNumberOfAddedElements) throws Exception { + testExecutableCopyPaste(targetContainer, copiedEObject, targetContainer.eClass().getEStructuralFeature(featureName), expectedNumberOfAddedElements); + } + + /** + * Generic implementation of the test + * + * @throws Exception + * exception thrown when the test has problems + */ + protected void testExecutableCopyPaste(EObject targetContainer, EObject copiedEObject, EStructuralFeature feature, int expectedNumberOfAddedElements) throws Exception { + // retrieve elements in the model explorer + selectAndReveal(targetContainer); + + List originalValues = new ArrayList((List)targetContainer.eGet(feature)); + + Map originalModel = new HashMap(); + initializeTest(originalModel, targetContainer, copiedEObject); + + // try to paste in several places + // copy Paste b1EObject + ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class); + commandService.refreshElements(IWorkbenchCommandConstants.EDIT_PASTE, null); + org.eclipse.core.commands.Command pasteCommand = commandService.getCommand(IWorkbenchCommandConstants.EDIT_PASTE); + Assert.assertNotNull("Impossible to find paste command", pasteCommand); + Assert.assertTrue("command in not enabled", pasteCommand.isEnabled()); + Assert.assertTrue("command in not defined", pasteCommand.isDefined()); + + pasteCommand.executeWithChecks(new ExecutionEvent()); + + // check editor state (should be non dirty) + Assert.assertTrue("Editor should be dirty after paste command execution", isEditorDirty()); + + + // should retrieve a new Part AND a new association + List newValues = (List)targetContainer.eGet(feature); + // compute delta + List delta = new ArrayList(); + for(EObject o : newValues) { + if(!originalValues.contains(o)) { + delta.add(o); + } + } + + // size = original size +1 + Assert.assertEquals("Wrong number of attributes after paste", expectedNumberOfAddedElements, delta.size()); + + // part should be linked to an association + postCopyAdditionalChecks(originalModel, newValues, delta); + + // undo + if(getEditingDomain().getCommandStack().canUndo()) { + getEditingDomain().getCommandStack().undo(); + } else { + throw new Exception("Impossible to undo the paste command: " + pasteCommand); + } + // check editor state (should be non dirty) + Assert.assertFalse("Editor should not be dirty after undo", isEditorDirty()); + // check old values equals the actual values + newValues = (List)targetContainer.eGet(feature); + Assert.assertEquals("Initial and current list feature list should be equivalent", newValues, originalValues); + + // redo + if(getEditingDomain().getCommandStack().canRedo()) { + getEditingDomain().getCommandStack().redo(); + } else { + throw new Exception("Impossible to redo the paste command: " + pasteCommand); + } + // check editor state (should be non dirty) + Assert.assertTrue("Editor should not dirty after redo", isEditorDirty()); + + // check as it was the result of the paste command + newValues = (List)targetContainer.eGet(feature); + delta = new ArrayList(); + for(EObject o : newValues) { + if(!originalValues.contains(o)) { + delta.add(o); + } + } + + // size = original size + delta + Assert.assertEquals("Wrong number of attributes after paste", expectedNumberOfAddedElements, delta.size()); + + // part should be linked to an association + postCopyAdditionalChecks(originalModel, newValues, delta); + + // undo again, to restore state + if(getEditingDomain().getCommandStack().canUndo()) { + getEditingDomain().getCommandStack().undo(); + } else { + throw new Exception("Impossible to re-undo the paste command: " + pasteCommand); + } + // check editor state (should be non dirty) + Assert.assertFalse("Editor should not be dirty after undo", isEditorDirty()); + + } + + /** + * executes additional checks on the new value + * + * @param originalModel + * the map containing all values stored before launching the test + * @param newValue + * the new value, result of the copy + * @param delta + * differences between original list and the new one + */ + protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { + // use the values contained in the map to do additional checks + } + + protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { + // nothing to do here + } +} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlock2Test.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlock2Test.java new file mode 100644 index 00000000000..ec838f4f9f9 --- /dev/null +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlock2Test.java @@ -0,0 +1,114 @@ +/***************************************************************************** + * Copyright (c) 2011 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: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + * from SimpleBlock2 - Model + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; + +import java.util.List; +import java.util.Map; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchCommandConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +/** + * Test for Copy / Paste of a Part + */ +public class CopyPasteSimpleBlock2Test extends AbstractCopyPasteBlockTest { + + /** + * prepare the copy + * + * @throws Exception + * exception thrown in case of problems + */ + @Before + public void testPrepare() throws Exception { + // check editor state (should be non dirty) + //FIXME: In Papyrus, the editor may be dirty at initialization. This should not be tested here. We simply save the editor as soon as it is opened. + Display.getDefault().syncExec(new Runnable() { + + public void run() { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor()); + } + }); + // retrieve elements in the model explorer + selectAndReveal(b1P1_P1_EObject); + + // copy Paste + ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class); + commandService.refreshElements(IWorkbenchCommandConstants.EDIT_COPY, null); + org.eclipse.core.commands.Command copyCommand = commandService.getCommand(IWorkbenchCommandConstants.EDIT_COPY); + Assert.assertNotNull("Impossible to find copy command", copyCommand); + Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); + Assert.assertTrue("command in not defined", copyCommand.isDefined()); + copyCommand.executeWithChecks(new ExecutionEvent()); + + // check editor state (should be non dirty) + Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); + } + + @Override + protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { + super.initializeTest(additionalChecks, targetContainer, copiedEObject); + + /* pre-copy initialization */ + + /* END OF pre-copy initialization */ + } + + /** + * {@inheritDoc} + */ + @Override + protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { + super.postCopyAdditionalChecks(originalModel, newValues, delta); + + /* post copy checks */ + + /* END OF post copy checks */ + } + + + /** + * Test the copy /paste on P1 + * + * @throws Exception + * exception thrown in case of problems + */ + @Test + public void testCopyPasteInP1() throws Exception { + testExecutableCopyPaste(p1_EObject, b1P1_P1_EObject, "ownedElement", 3); + } + + /** + * Test the copy /paste on model + * + * @throws Exception + * exception thrown in case of problems + */ + @Test + public void testCopyPasteInmodel() throws Exception { + testExecutableCopyPaste(model_EObject, b1P1_P1_EObject, "ownedElement", 3); + } + + +} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlockTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlockTest.java new file mode 100644 index 00000000000..e9d9582cd55 --- /dev/null +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleBlockTest.java @@ -0,0 +1,125 @@ +/***************************************************************************** + * Copyright (c) 2011 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: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + * from SimpleBlock - Model + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; + +import java.util.List; +import java.util.Map; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchCommandConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +/** + * Test for Copy / Paste of a Part + */ +public class CopyPasteSimpleBlockTest extends AbstractCopyPasteBlockTest { + + /** + * prepare the copy + * + * @throws Exception + * exception thrown in case of problems + */ + @Before + public void testPrepare() throws Exception { + // check editor state (should be non dirty) + //FIXME: In Papyrus, the editor may be dirty at initialization. This should not be tested here. We simply save the editor as soon as it is opened. + Display.getDefault().syncExec(new Runnable() { + + public void run() { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor()); + } + }); + // retrieve elements in the model explorer + selectAndReveal(b1_EObject); + + // copy Paste + RunnableWithResult runnable; + Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl() { + + public void run() { + ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(ICommandService.class); + setResult(commandService); + } + }); + + ICommandService commandService = runnable.getResult(); + + commandService.refreshElements(IWorkbenchCommandConstants.EDIT_COPY, null); + org.eclipse.core.commands.Command copyCommand = commandService.getCommand(IWorkbenchCommandConstants.EDIT_COPY); + Assert.assertNotNull("Impossible to find copy command", copyCommand); + Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); + Assert.assertTrue("command in not defined", copyCommand.isDefined()); + copyCommand.executeWithChecks(new ExecutionEvent()); + + // check editor state (should be non dirty) + Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); + } + + @Override + protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { + super.initializeTest(additionalChecks, targetContainer, copiedEObject); + + /* pre-copy initialization */ + + /* END OF pre-copy initialization */ + } + + /** + * {@inheritDoc} + */ + @Override + protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { + super.postCopyAdditionalChecks(originalModel, newValues, delta); + + /* post copy checks */ + + /* END OF post copy checks */ + } + + + /** + * Test the copy /paste on P1 + * + * @throws Exception + * exception thrown in case of problems + */ + @Test + public void testCopyPasteInP1() throws Exception { + testExecutableCopyPaste(p1_EObject, b1_EObject, "ownedElement", 4); + } + + /** + * Test the copy /paste on model + * + * @throws Exception + * exception thrown in case of problems + */ + @Test + public void testCopyPasteInmodel() throws Exception { + testExecutableCopyPaste(model_EObject, b1_EObject, "ownedElement", 4); + } + + +} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimplePartTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimplePartTest.java new file mode 100644 index 00000000000..d3c63e210e1 --- /dev/null +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimplePartTest.java @@ -0,0 +1,136 @@ +/***************************************************************************** + * Copyright (c) 2011 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: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + * from SimplePart - Model + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; + +import java.util.List; +import java.util.Map; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchCommandConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +/** + * Test for Copy / Paste of a Part + */ +public class CopyPasteSimplePartTest extends AbstractCopyPastePartTest { + + /** + * prepare the copy + * + * @throws Exception + * exception thrown in case of problems + */ + @Before + public void testPrepare() throws Exception { + // check editor state (should be non dirty) + //FIXME: In Papyrus, the editor may be dirty at initialization. This should not be tested here. We simply save the editor as soon as it is opened. + Display.getDefault().syncExec(new Runnable() { + + public void run() { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor()); + } + }); + // retrieve elements in the model explorer + selectAndReveal(pB2_B1_EObject); + + // copy Paste + ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class); + commandService.refreshElements(IWorkbenchCommandConstants.EDIT_COPY, null); + org.eclipse.core.commands.Command copyCommand = commandService.getCommand(IWorkbenchCommandConstants.EDIT_COPY); + Assert.assertNotNull("Impossible to find copy command", copyCommand); + Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); + Assert.assertTrue("command in not defined", copyCommand.isDefined()); + copyCommand.executeWithChecks(new ExecutionEvent()); + + // check editor state (should be non dirty) + Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); + } + + @Override + protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { + super.initializeTest(additionalChecks, targetContainer, copiedEObject); + + /* pre-copy initialization */ + + /* END OF pre-copy initialization */ + } + + /** + * {@inheritDoc} + */ + @Override + protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { + super.postCopyAdditionalChecks(originalModel, newValues, delta); + + /* post copy checks */ + + /* END OF post copy checks */ + } + + + /** + * Test the copy /paste on B1 + * + * @throws Exception + * exception thrown in case of problems + */ + @Test + public void testCopyPasteInB1() throws Exception { + testExecutableCopyPaste(b1_EObject, pB2_B1_EObject, "attribute", 1); + } + + /** + * Test the copy /paste on B2 + * + * @throws Exception + * exception thrown in case of problems + */ + @Test + public void testCopyPasteInB2() throws Exception { + testExecutableCopyPaste(b2_EObject, pB2_B1_EObject, "attribute", 1); + } + + /** + * Test the copy /paste on B1P1 + * + * @throws Exception + * exception thrown in case of problems + */ + @Test + public void testCopyPasteInB1P1() throws Exception { + testExecutableCopyPaste(b1P1_P1_EObject, pB2_B1_EObject, "attribute", 1); + } + + /** + * Test the copy /paste on B2P1 + * + * @throws Exception + * exception thrown in case of problems + */ + @Test + public void testCopyPasteInB2P1() throws Exception { + testExecutableCopyPaste(b2P1_P1_EObject, pB2_B1_EObject, "attribute", 1); + } + + +} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleReferenceTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleReferenceTest.java new file mode 100644 index 00000000000..ebf2450d313 --- /dev/null +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteSimpleReferenceTest.java @@ -0,0 +1,150 @@ +/***************************************************************************** + * Copyright (c) 2011 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: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + * from SimpleReference - Model + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste; + +import java.util.List; +import java.util.Map; + +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchCommandConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.commands.ICommandService; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + + +/** + * Test for Copy / Paste of a Part + */ +public class CopyPasteSimpleReferenceTest extends AbstractCopyPasteReferenceTest { + + /** + * prepare the copy + * + * @throws Exception + * exception thrown in case of problems + */ + @Before + public void testPrepare() throws Exception { + // check editor state (should be non dirty) + //FIXME: In Papyrus, the editor may be dirty at initialization. This should not be tested here. We simply save the editor as soon as it is opened. + Display.getDefault().syncExec(new Runnable() { + + public void run() { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor()); + } + }); + + Assert.assertFalse("Editor should not be dirty at initialization", isEditorDirty()); + // retrieve elements in the model explorer + selectAndReveal(rB2_B1_EObject); + + // copy Paste + ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class); + commandService.refreshElements(IWorkbenchCommandConstants.EDIT_COPY, null); + org.eclipse.core.commands.Command copyCommand = commandService.getCommand(IWorkbenchCommandConstants.EDIT_COPY); + Assert.assertNotNull("Impossible to find copy command", copyCommand); + Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); + Assert.assertTrue("command in not defined", copyCommand.isDefined()); + copyCommand.executeWithChecks(new ExecutionEvent()); + + // check editor state (should be non dirty) + // Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); + + // NOTE: save editor. The copy command should not dirty the model, the implementation of the copy command or the editor should be modified + Assert.assertFalse("Copy command is dirtying the model, whereas it should not. This assert is here to remember that the test code should be modified: Isdirty = false after copy...", isEditorDirty()); + Display.getDefault().syncExec(new Runnable() { + + public void run() { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().doSave(new NullProgressMonitor()); + } + }); + + Assert.assertFalse("Save command is non-dirtying the model, whereas it should. ", isEditorDirty()); + // END NOTE + } + + @Override + protected void initializeTest(Map additionalChecks, EObject targetContainer, EObject copiedEObject) { + super.initializeTest(additionalChecks, targetContainer, copiedEObject); + + /* pre-copy initialization */ + + /* END OF pre-copy initialization */ + } + + /** + * {@inheritDoc} + */ + @Override + protected void postCopyAdditionalChecks(Map originalModel, List newValues, List delta) throws Exception { + super.postCopyAdditionalChecks(originalModel, newValues, delta); + + /* post copy checks */ + + /* END OF post copy checks */ + } + + + /** + * Test the copy /paste on B1 + * + * @throws Exception + * exception thrown in case of problems + */ + @Test + public void testCopyPasteInB1() throws Exception { + testExecutableCopyPaste(b1_EObject, rB2_B1_EObject, "attribute", 1); + } + + /** + * Test the copy /paste on B2 + * + * @throws Exception + * exception thrown in case of problems + */ + @Test + public void testCopyPasteInB2() throws Exception { + testExecutableCopyPaste(b2_EObject, rB2_B1_EObject, "attribute", 1); + } + + /** + * Test the copy /paste on B1P1 + * + * @throws Exception + * exception thrown in case of problems + */ + @Test + public void testCopyPasteInB1P1() throws Exception { + testExecutableCopyPaste(b1P1_P1_EObject, rB2_B1_EObject, "attribute", 1); + } + + /** + * Test the copy /paste on B2P1 + * + * @throws Exception + * exception thrown in case of problems + */ + @Test + public void testCopyPasteInB2P1() throws Exception { + testExecutableCopyPaste(b2P1_P1_EObject, rB2_B1_EObject, "attribute", 1); + } + + +} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/suites/AllCopyPasteTests.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/suites/AllCopyPasteTests.java new file mode 100644 index 00000000000..e8a9f2f427e --- /dev/null +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/suites/AllCopyPasteTests.java @@ -0,0 +1,41 @@ + /***************************************************************************** + * Copyright (c) 2011 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: + * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.modelexplorer.tests.suites; + +import org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste.CopyPasteSimpleBlock2Test; +import org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste.CopyPasteSimpleBlockTest; +import org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste.CopyPasteSimplePartTest; +import org.eclipse.papyrus.sysml.modelexplorer.tests.copypaste.CopyPasteSimpleReferenceTest; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + + +/** + * Tests suite for Copy/Paste + * + */ +@RunWith(Suite.class) +@SuiteClasses({ +// Reference +CopyPasteSimpleReferenceTest.class, +// Block +CopyPasteSimpleBlockTest.class, +CopyPasteSimpleBlock2Test.class, +// Part +CopyPasteSimplePartTest.class, + +}) +public class AllCopyPasteTests { + +} -- cgit v1.2.3