summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-06-04 11:18:26 (EDT)
committerBenoit Maggi2014-06-04 11:18:26 (EDT)
commit6e7528070bc772d82a7249ed6560db04bcc5f594 (patch)
treebdb82d088007cebe6eca4930d062c3be33bf3deb
parent29f4b97cd04eb76073eecdd7772294bd6f7b1716 (diff)
downloadorg.eclipse.papyrus-6e7528070bc772d82a7249ed6560db04bcc5f594.zip
org.eclipse.papyrus-6e7528070bc772d82a7249ed6560db04bcc5f594.tar.gz
org.eclipse.papyrus-6e7528070bc772d82a7249ed6560db04bcc5f594.tar.bz2
Bug 436385 - [Copy/paste] generates NPE when applied to a property of arefs/changes/54/27954/1
SysML Block - patch the NPE - add a test case Change-Id: I3810f22fd89d0f7ac3d7fa2e8d15d4194645a911 Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/META-INF/MANIFEST.MF1
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/strategy/paste/PartPasteStrategy.java5
-rw-r--r--tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/META-INF/MANIFEST.MF4
-rw-r--r--tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/CopyPasteInModelExplorer.java78
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 a675c44..394d622 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 d58723a..4b14065 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 c50d00f..6c5ecb2 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 5d90492..c853042 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$
+ }
+
+
+
+
}