diff options
author | Remi Schnekenburger | 2014-07-16 13:41:17 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2014-07-16 13:41:17 +0000 |
commit | 57da219981c90089ab8012949379ddf685b9d6c4 (patch) | |
tree | 6b5a5d79344d4ae2c34bf2ea8e9c892b202a8433 | |
parent | 6c26644683ca16d9ef3c592782ddfccc6b4c6d69 (diff) | |
parent | 6e7528070bc772d82a7249ed6560db04bcc5f594 (diff) | |
download | org.eclipse.papyrus-57da219981c90089ab8012949379ddf685b9d6c4.tar.gz org.eclipse.papyrus-57da219981c90089ab8012949379ddf685b9d6c4.tar.xz org.eclipse.papyrus-57da219981c90089ab8012949379ddf685b9d6c4.zip |
Merge "Bug 436385 - [Copy/paste] generates NPE when applied to a property of a SysML Block - patch the NPE - add a test case"
4 files changed, 85 insertions, 3 deletions
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 a675c445517..394d622da62 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 @@ -17,6 +17,7 @@ Export-Package: org.eclipse.papyrus.gmf.diagram.common.commands, org.eclipse.papyrus.sysml.diagram.common.messages, org.eclipse.papyrus.sysml.diagram.common.parser, org.eclipse.papyrus.sysml.diagram.common.preferences, + org.eclipse.papyrus.sysml.diagram.common.strategy.paste, org.eclipse.papyrus.sysml.diagram.common.utils, org.eclipse.papyrus.uml.diagram.common.dnd.helper, org.eclipse.papyrus.uml.diagram.common.edit.part, 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 index d58723a50da..4b140657d28 100644 --- 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 @@ -248,7 +248,10 @@ public class PartPasteStrategy implements IPasteStrategy { 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()); + Association association = propertySource.getAssociation(); + if (association != null){ + clipboardAdditionalData = new PartAdditionalData(association); + } } else if(elementSource instanceof Classifier && UMLUtil.getStereotypeApplication(elementSource, Block.class) != null) {// is Block Classifier block = (Classifier)elementSource; clipboardAdditionalData = new PartBlockAdditionalData(block); diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/META-INF/MANIFEST.MF b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/META-INF/MANIFEST.MF index c50d00f3382..6c5ecb28a25 100644 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/META-INF/MANIFEST.MF +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/META-INF/MANIFEST.MF @@ -16,7 +16,9 @@ Require-Bundle: org.eclipse.ui, org.eclipse.papyrus.uml.tools.utils;bundle-version="1.0.0", org.eclipse.papyrus.views.modelexplorer;bundle-version="1.0.0", org.eclipse.papyrus.sysml.modelexplorer;bundle-version="1.0.0", - org.eclipse.papyrus.sysml.service.types;bundle-version="1.0.0" + org.eclipse.papyrus.sysml.service.types;bundle-version="1.0.0", + org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0", + org.eclipse.papyrus.sysml.diagram.common;bundle-version="1.0.0" Bundle-Vendor: %providerName Bundle-ActivationPolicy: lazy Bundle-Version: 1.0.0.qualifier diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteInModelExplorer.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteInModelExplorer.java index 5d90492dab9..c8530425fbd 100644 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteInModelExplorer.java +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteInModelExplorer.java @@ -19,14 +19,18 @@ import java.util.List; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.IHandler; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.papyrus.infra.gmfdiag.common.strategy.IStrategy; +import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.PasteStrategyManager; import org.eclipse.papyrus.junit.utils.HandlerUtils; import org.eclipse.papyrus.junit.utils.tests.AbstractEditorTest; +import org.eclipse.papyrus.sysml.diagram.common.strategy.paste.PartPasteStrategy; import org.eclipse.papyrus.sysml.modelexplorer.tests.Activator; import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil; import org.eclipse.ui.ISelectionService; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.uml2.uml.Model; +import org.eclipse.uml2.uml.Property; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -50,6 +54,8 @@ public class CopyPasteInModelExplorer extends AbstractEditorTest { public final static String BLOCK_NAME = "Block"; //$NON-NLS-1$ + public final static String PORT_NAME = "port"; //$NON-NLS-1$ + @Before public void initModelForCutTest() { try { @@ -64,7 +70,15 @@ public class CopyPasteInModelExplorer extends AbstractEditorTest { return RESOURCES_PATH; } - + private PartPasteStrategy getPartPasteStrategy() { + List<IStrategy> allStrategies = PasteStrategyManager.getInstance().getAllActiveStrategies(); + for(IStrategy iStrategy : allStrategies) { + if (iStrategy instanceof PartPasteStrategy){ + return ( PartPasteStrategy) iStrategy; + } + } + return null; + } /** @@ -73,6 +87,11 @@ public class CopyPasteInModelExplorer extends AbstractEditorTest { */ @Test public void copyPasteofBlockWithPropertyAndNoAssociationTest() throws Exception { + + PartPasteStrategy partPasteStrategy = getPartPasteStrategy(); + Assert.assertNotNull("PartPasteStrategy not present", partPasteStrategy); + Assert.assertTrue("PartPasteStrategy not active", PasteStrategyManager.getInstance().isActive(partPasteStrategy)); + //get the rootModel Assert.assertNotNull("RootModel is null", getRootUMLModel()); //$NON-NLS-1$ //get all semantic elment that will handled @@ -113,4 +132,61 @@ public class CopyPasteInModelExplorer extends AbstractEditorTest { Assert.assertNotNull("The copy is missing", copyOfBlock); //$NON-NLS-1$ } + + /** + * Test for Bug 436385 + * @throws Exception + */ + @Test + public void copyPasteofPropertyWithoutAssociationTest() throws Exception { + + PartPasteStrategy partPasteStrategy = getPartPasteStrategy(); + Assert.assertNotNull("PartPasteStrategy not present", partPasteStrategy); + Assert.assertTrue("PartPasteStrategy not active", PasteStrategyManager.getInstance().isActive(partPasteStrategy)); + + //get the rootModel + Assert.assertNotNull("RootModel is null", getRootUMLModel()); //$NON-NLS-1$ + //get all semantic elment that will handled + Model model = (Model)getRootUMLModel(); + + IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + ISelectionService selectionService = activeWorkbenchWindow.getSelectionService(); + modelExplorerView = getModelExplorerView(); + modelExplorerView.setFocus(); + List<Object> elements = new ArrayList<Object>(); + elements.add(getRootUMLModel()); + modelExplorerView.revealSemanticElement(elements); + + org.eclipse.uml2.uml.Class block = (org.eclipse.uml2.uml.Class)model.getPackagedElement(BLOCK_NAME); + Property port = block.getAttribute(PORT_NAME, null); + Assert.assertNotNull("There is no port", port); //$NON-NLS-1$ + + elements.clear(); + elements.add(port); + modelExplorerView.revealSemanticElement(elements); + Object blockTreeObject = ((IStructuredSelection)selectionService.getSelection()).getFirstElement(); + Assert.assertNotNull("Class1 TreeElement is null", blockTreeObject); //$NON-NLS-1$ + + IHandler copyHandler = HandlerUtils.getActiveHandlerFor(COPY_COMMAND_ID); + Assert.assertTrue("Copy not available", copyHandler.isEnabled()); //$NON-NLS-1$ + copyHandler.execute(new ExecutionEvent()); + + // select the block + elements.clear(); + elements.add(block); + modelExplorerView.revealSemanticElement(elements); + + // paste + IHandler pasteHandler = HandlerUtils.getActiveHandlerFor(PASTE_COMMAND_ID); + Assert.assertTrue("Paste not available", pasteHandler.isEnabled()); //$NON-NLS-1$ + pasteHandler.execute(new ExecutionEvent()); + + // check that there is a Block + Property copyOfPort = block.getAttribute(NamedElementUtil.COPY_OF + "_" + PORT_NAME + "_1",null); + Assert.assertNotNull("The copy is missing", copyOfPort); //$NON-NLS-1$ + } + + + + } |