diff options
Diffstat (limited to 'tests/junit/plugins/sysml')
10 files changed, 311 insertions, 304 deletions
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 index 1c386641ccf..dd9d9861e10 100644 --- 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 @@ -75,7 +75,7 @@ public abstract class AbstractModelExplorerTest { public static IEditorPart editor = null; /** id of the papyrus editor */ - public static String editorID = "org.eclipse.papyrus.infra.core.papyrusEditor"; + public static String editorID = "org.eclipse.papyrus.infra.core.papyrusEditor"; /** view part: the model explorer */ protected static IViewPart modelExplorerPart; @@ -172,42 +172,42 @@ public abstract class AbstractModelExplorerTest { DiagramEditPart diagramEditPart = EditorUtils.getDiagramEditPart(); EObject root = diagramEditPart.getDiagramView().getElement(); - Assert.assertTrue("Impossible to find main model", root instanceof Model); + Assert.assertTrue("Impossible to find main model", root instanceof Model); //$NON-NLS-1$ /** 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); + Assert.assertNotNull("Impossible to find Class B1", b1_EObject); //$NON-NLS-1$ pB1P1_B1_EObject = b1_EObject.getAttribute("pB1P1", null); - Assert.assertNotNull("Impossible to find Property pB1P1", pB1P1_B1_EObject); + Assert.assertNotNull("Impossible to find Property pB1P1", pB1P1_B1_EObject); //$NON-NLS-1$ rB2_B1_EObject = b1_EObject.getAttribute("rB2", null); - Assert.assertNotNull("Impossible to find Property rB2", rB2_B1_EObject); + Assert.assertNotNull("Impossible to find Property rB2", rB2_B1_EObject); //$NON-NLS-1$ pB2_B1_EObject = b1_EObject.getAttribute("pB2", null); - Assert.assertNotNull("Impossible to find Property pB2", pB2_B1_EObject); + Assert.assertNotNull("Impossible to find Property pB2", pB2_B1_EObject); //$NON-NLS-1$ b2_EObject = (org.eclipse.uml2.uml.Class)model_EObject.getPackagedElement("B2"); - Assert.assertNotNull("Impossible to find Class B2", b2_EObject); + Assert.assertNotNull("Impossible to find Class B2", b2_EObject); //$NON-NLS-1$ p1_EObject = (org.eclipse.uml2.uml.Package)model_EObject.getPackagedElement("P1"); - Assert.assertNotNull("Impossible to find Package P1", p1_EObject); + Assert.assertNotNull("Impossible to find Package P1", p1_EObject); //$NON-NLS-1$ b2P1_P1_EObject = (org.eclipse.uml2.uml.Class)p1_EObject.getPackagedElement("B2P1"); - Assert.assertNotNull("Impossible to find Class B2P1", b2P1_P1_EObject); + Assert.assertNotNull("Impossible to find Class B2P1", b2P1_P1_EObject); //$NON-NLS-1$ b1P1_P1_EObject = (org.eclipse.uml2.uml.Class)p1_EObject.getPackagedElement("B1P1"); - Assert.assertNotNull("Impossible to find Class B1P1", b1P1_P1_EObject); + Assert.assertNotNull("Impossible to find Class B1P1", b1P1_P1_EObject); //$NON-NLS-1$ pB1_B1P1_P1_EObject = b1P1_P1_EObject.getAttribute("pB1", null); - Assert.assertNotNull("Impossible to find Property pB1", pB1_B1P1_P1_EObject); + Assert.assertNotNull("Impossible to find Property pB1", pB1_B1P1_P1_EObject); //$NON-NLS-1$ pB2P1_B1P1_P1_EObject = b1P1_P1_EObject.getAttribute("pB2P1", null); - Assert.assertNotNull("Impossible to find Property pB2P1", pB2P1_B1P1_P1_EObject); + Assert.assertNotNull("Impossible to find Property pB2P1", pB2P1_B1P1_P1_EObject); //$NON-NLS-1$ iBD_B1_Diagram = getDiagram("IBD_B1"); - Assert.assertNotNull("Impossible to find IBD_B1", iBD_B1_Diagram); + Assert.assertNotNull("Impossible to find IBD_B1", iBD_B1_Diagram); //$NON-NLS-1$ bDD_Main_Diagram = getDiagram("BDD_Main"); - Assert.assertNotNull("Impossible to find BDD_Main", bDD_Main_Diagram); + Assert.assertNotNull("Impossible to find BDD_Main", bDD_Main_Diagram); //$NON-NLS-1$ List<Customization> appliedCustomizations=org.eclipse.papyrus.views.modelexplorer.Activator.getDefault().getCustomizationManager().getManagedCustomizations(); Customization SimpleUML=null; Iterator<?>iter=appliedCustomizations.iterator(); @@ -217,12 +217,12 @@ public abstract class AbstractModelExplorerTest { SimpleUML=custo; } } - org.junit.Assert.assertNotNull("Custom SimpleUML not found", SimpleUML); + Assert.assertNotNull("Custom SimpleUML not found", SimpleUML); //$NON-NLS-1$ 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()); + Assert.assertEquals("bad order of applied Custom", "SimpleUML", appliedCustomizations.get(0).getName()); //$NON-NLS-1$ /** end of generated selectable objects */ } @@ -293,7 +293,7 @@ public abstract class AbstractModelExplorerTest { semanticElementList.addAll(newElements); modelExplorerView.revealSemanticElement(semanticElementList); } else { - throw new Exception("Impossible to find the model explorer required to select: " + newElements); + throw new Exception("Impossible to find the model explorer required to select: " + newElements); //$NON-NLS-1$ } } @@ -372,7 +372,7 @@ public abstract class AbstractModelExplorerTest { modelExplorerView.revealSemanticElement(semanticElementList); //reveal(semanticElementList, modelExplorerView.getCommonViewer()); } else { - throw new Exception("Impossible to find the model explorer required to select: " + newDiagrams); + throw new Exception("Impossible to find the model explorer required to select: " + newDiagrams); //$NON-NLS-1$ } } @@ -476,11 +476,11 @@ public abstract class AbstractModelExplorerTest { 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()); + Assert.assertEquals("one and only one object should be selected", 1, selection.size()); //$NON-NLS-1$ 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)); + Assert.assertTrue("selection should be a model item element", selectedElement instanceof EObjectTreeElement); //$NON-NLS-1$ + Assert.assertTrue("selection should be linked to a EObject", ((EObjectTreeElement)selectedElement).getEObject() instanceof EObject); //$NON-NLS-1$ + Assert.assertTrue("selection should be linked to the Object: " + objectToFind, ((EObjectTreeElement)selectedElement).getEObject().equals(objectToFind)); //$NON-NLS-1$ return (EObjectTreeElement)selectedElement; } @@ -497,11 +497,11 @@ public abstract class AbstractModelExplorerTest { selectAndRevealDiagram(diagramToFind); IStructuredSelection selection = (IStructuredSelection)modelExplorerPart.getSite().getSelectionProvider().getSelection(); - Assert.assertEquals("one and only one diagram should be selected", 1, selection.size()); + Assert.assertEquals("one and only one diagram should be selected", 1, selection.size()); //$NON-NLS-1$ 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)); + Assert.assertTrue("selection should be a model item element", selectedElement instanceof EObjectTreeElement); //$NON-NLS-1$ + Assert.assertTrue("selection should be linked to a Diagram", ((EObjectTreeElement)selectedElement).getEObject() instanceof Diagram); //$NON-NLS-1$ + Assert.assertTrue("selection should be linked to the Object: " + diagramToFind, ((EObjectTreeElement)selectedElement).getEObject().equals(diagramToFind)); //$NON-NLS-1$ return (EObjectTreeElement)selectedElement; } 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 index 4b28cca05c6..e936af4ae53 100644 --- 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 @@ -40,7 +40,8 @@ public abstract class AbstractCopyPasteBlockTest extends AbstractCopyPasteTest { super.initializeTest(additionalChecks, targetContainer, copiedEObject); /* pre-copy initialization */ - List<Property> originalParts = new ArrayList<Property>(); 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); + List<Property> originalParts = new ArrayList<Property>(); + 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 */ } @@ -54,7 +55,12 @@ public abstract class AbstractCopyPasteBlockTest extends AbstractCopyPasteTest { super.postCopyAdditionalChecks(originalModel, newValues, delta); /* post copy checks */ - FilteredCollectionView<EObject> newClasses = new FilteredCollectionView<EObject>(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<Property> originalParts = (List<Property>) originalModel .get("originalParts"); List<Property> newParts = new ArrayList<Property>(); 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()); + FilteredCollectionView<EObject> newClasses = new FilteredCollectionView<EObject>(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()); //$NON-NLS-1$ + 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")); //$NON-NLS-1$ + List<Property> originalParts = (List<Property>) originalModel .get("originalParts"); List<Property> newParts = new ArrayList<Property>(); 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()); //$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 index 1ea66a8dec2..17b6ec3f5e1 100644 --- 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 @@ -51,7 +51,8 @@ public abstract class AbstractCopyPasteReferenceTest extends AbstractCopyPasteTe super.postCopyAdditionalChecks(originalModel, newValues, delta); /* post copy checks */ - Association newAssociation = ((Property)newValues.get(0)).getAssociation(); Assert.assertNotNull("New Reference should have an association", newAssociation); + Association newAssociation = ((Property)newValues.get(0)).getAssociation(); + Assert.assertNotNull("New Reference 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/AbstractCopyPasteTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/copypaste/AbstractCopyPasteTest.java index cef2d877c86..775705e82d9 100644 --- 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 @@ -65,14 +65,14 @@ public abstract class AbstractCopyPasteTest extends AbstractModelExplorerTest { 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()); + Assert.assertNotNull("Impossible to find paste command", pasteCommand); //$NON-NLS-1$ + Assert.assertTrue("command in not enabled", pasteCommand.isEnabled()); //$NON-NLS-1$ + Assert.assertTrue("command in not defined", pasteCommand.isDefined()); //$NON-NLS-1$ pasteCommand.executeWithChecks(new ExecutionEvent()); // check editor state (should be non dirty) - Assert.assertTrue("Editor should be dirty after paste command execution", isEditorDirty()); + Assert.assertTrue("Editor should be dirty after paste command execution", isEditorDirty()); //$NON-NLS-1$ // should retrieve a new Part AND a new association @@ -86,7 +86,7 @@ public abstract class AbstractCopyPasteTest extends AbstractModelExplorerTest { } // size = original size +1 - Assert.assertEquals("Wrong number of attributes after paste", expectedNumberOfAddedElements, delta.size()); + Assert.assertEquals("Wrong number of attributes after paste", expectedNumberOfAddedElements, delta.size()); //$NON-NLS-1$ // part should be linked to an association postCopyAdditionalChecks(originalModel, newValues, delta); @@ -95,22 +95,22 @@ public abstract class AbstractCopyPasteTest extends AbstractModelExplorerTest { if(getEditingDomain().getCommandStack().canUndo()) { getEditingDomain().getCommandStack().undo(); } else { - throw new Exception("Impossible to undo the paste command: " + pasteCommand); + throw new Exception("Impossible to undo the paste command: " + pasteCommand); //$NON-NLS-1$ } // check editor state (should be non dirty) - Assert.assertFalse("Editor should not be dirty after undo", isEditorDirty()); + Assert.assertFalse("Editor should not be dirty after undo", isEditorDirty()); //$NON-NLS-1$ // check old values equals the actual values newValues = (List<EObject>)targetContainer.eGet(feature); - Assert.assertEquals("Initial and current list feature list should be equivalent", newValues, originalValues); + Assert.assertEquals("Initial and current list feature list should be equivalent", newValues, originalValues); //$NON-NLS-1$ // redo if(getEditingDomain().getCommandStack().canRedo()) { getEditingDomain().getCommandStack().redo(); } else { - throw new Exception("Impossible to redo the paste command: " + pasteCommand); + throw new Exception("Impossible to redo the paste command: " + pasteCommand); //$NON-NLS-1$ } // check editor state (should be non dirty) - Assert.assertTrue("Editor should not dirty after redo", isEditorDirty()); + Assert.assertTrue("Editor should not dirty after redo", isEditorDirty()); //$NON-NLS-1$ // check as it was the result of the paste command newValues = (List<EObject>)targetContainer.eGet(feature); @@ -122,7 +122,7 @@ public abstract class AbstractCopyPasteTest extends AbstractModelExplorerTest { } // size = original size + delta - Assert.assertEquals("Wrong number of attributes after paste", expectedNumberOfAddedElements, delta.size()); + Assert.assertEquals("Wrong number of attributes after paste", expectedNumberOfAddedElements, delta.size()); //$NON-NLS-1$ // part should be linked to an association postCopyAdditionalChecks(originalModel, newValues, delta); @@ -131,10 +131,10 @@ public abstract class AbstractCopyPasteTest extends AbstractModelExplorerTest { if(getEditingDomain().getCommandStack().canUndo()) { getEditingDomain().getCommandStack().undo(); } else { - throw new Exception("Impossible to re-undo the paste command: " + pasteCommand); + throw new Exception("Impossible to re-undo the paste command: " + pasteCommand); //$NON-NLS-1$ } // check editor state (should be non dirty) - Assert.assertFalse("Editor should not be dirty after undo", isEditorDirty()); + Assert.assertFalse("Editor should not be dirty after undo", isEditorDirty()); //$NON-NLS-1$ } 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 index ec838f4f9f9..a3cb4d822bd 100644 --- 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 @@ -57,13 +57,13 @@ public class CopyPasteSimpleBlock2Test extends AbstractCopyPasteBlockTest { 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()); + Assert.assertNotNull("Impossible to find copy command", copyCommand); //$NON-NLS-1$ + Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); //$NON-NLS-1$ + Assert.assertTrue("command in not defined", copyCommand.isDefined()); //$NON-NLS-1$ copyCommand.executeWithChecks(new ExecutionEvent()); // check editor state (should be non dirty) - Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); + Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); //$NON-NLS-1$ } @Override 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 index e9d9582cd55..36e8f1414bf 100644 --- 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 @@ -68,13 +68,13 @@ public class CopyPasteSimpleBlockTest extends AbstractCopyPasteBlockTest { 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()); + Assert.assertNotNull("Impossible to find copy command", copyCommand); //$NON-NLS-1$ + Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); //$NON-NLS-1$ + Assert.assertTrue("command in not defined", copyCommand.isDefined()); //$NON-NLS-1$ copyCommand.executeWithChecks(new ExecutionEvent()); // check editor state (should be non dirty) - Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); + Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); //$NON-NLS-1$ } @Override 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 index d3c63e210e1..7a1dbc69a03 100644 --- 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 @@ -57,13 +57,13 @@ public class CopyPasteSimplePartTest extends AbstractCopyPastePartTest { 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()); + Assert.assertNotNull("Impossible to find copy command", copyCommand); //$NON-NLS-1$ + Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); //$NON-NLS-1$ + Assert.assertTrue("command in not defined", copyCommand.isDefined()); //$NON-NLS-1$ + copyCommand.executeWithChecks(new ExecutionEvent()); // check editor state (should be non dirty) - Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); + Assert.assertFalse("Editor should not be dirty after copy", isEditorDirty()); //$NON-NLS-1$ } @Override 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 index ebf2450d313..7f2d76c61a3 100644 --- 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 @@ -51,7 +51,7 @@ public class CopyPasteSimpleReferenceTest extends AbstractCopyPasteReferenceTest } }); - Assert.assertFalse("Editor should not be dirty at initialization", isEditorDirty()); + Assert.assertFalse("Editor should not be dirty at initialization", isEditorDirty()); //$NON-NLS-1$ // retrieve elements in the model explorer selectAndReveal(rB2_B1_EObject); @@ -59,16 +59,16 @@ public class CopyPasteSimpleReferenceTest extends AbstractCopyPasteReferenceTest 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()); + Assert.assertNotNull("Impossible to find copy command", copyCommand); //$NON-NLS-1$ + Assert.assertTrue("command in not enabled", copyCommand.isEnabled()); //$NON-NLS-1$ + Assert.assertTrue("command in not defined", copyCommand.isDefined()); //$NON-NLS-1$ 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()); + 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()); //$NON-NLS-1$ Display.getDefault().syncExec(new Runnable() { public void run() { @@ -76,7 +76,7 @@ public class CopyPasteSimpleReferenceTest extends AbstractCopyPasteReferenceTest } }); - Assert.assertFalse("Save command is non-dirtying the model, whereas it should. ", isEditorDirty()); + Assert.assertFalse("Save command is non-dirtying the model, whereas it should. ", isEditorDirty()); //$NON-NLS-1$ // END NOTE } @@ -110,7 +110,7 @@ public class CopyPasteSimpleReferenceTest extends AbstractCopyPasteReferenceTest */ @Test public void testCopyPasteInB1() throws Exception { - testExecutableCopyPaste(b1_EObject, rB2_B1_EObject, "attribute", 1); + testExecutableCopyPaste(b1_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/dragdrop/AbstractDragDropTest.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/dragdrop/AbstractDragDropTest.java index 82e15f263d6..8bf37088ae6 100644 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/dragdrop/AbstractDragDropTest.java +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/dragdrop/AbstractDragDropTest.java @@ -1,167 +1,167 @@ -/*****************************************************************************
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.modelexplorer.tests.dragdrop;
-
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.emf.common.command.CompoundCommand;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.jface.util.LocalSelectionTransfer;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ViewerDropAdapter;
-import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EObjectTreeElement;
-import org.eclipse.papyrus.sysml.modelexplorer.tests.common.AbstractModelExplorerTest;
-import org.eclipse.papyrus.sysml.modelexplorer.tests.utils.EditorUtils;
-import org.eclipse.papyrus.views.modelexplorer.CustomCommonViewer;
-import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView;
-import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
-import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService;
-import org.eclipse.ui.navigator.CommonDropAdapter;
-import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
-import org.junit.Assert;
-import org.junit.Before;
-
-/**
- * Abstract Class to implement diagram drag and drop tests.
- */
-public class AbstractDragDropTest extends AbstractModelExplorerTest {
-
- /**
- * 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());
- }
-
- public List<CompoundCommand> getListOfDropCommands(EObject sourceElement, EObject targetElement) throws Exception {
- // init source object
- EObjectTreeElement sourceMEI = null;
- if(sourceElement instanceof Diagram) {
- sourceMEI = findSemanticModelElementItem((Diagram)sourceElement);
- } else {
- sourceMEI = findSemanticModelElementItem(sourceElement);
- }
- EObjectTreeElement targetMEI = null;
- if(targetElement instanceof Diagram) {
- targetMEI = findSemanticModelElementItem((Diagram)targetElement);
- } else {
- targetMEI = findSemanticModelElementItem(targetElement);
- }
- if(sourceElement instanceof Diagram) {
- selectAndRevealDiagram((Diagram)sourceElement);
- } else {
- selectAndReveal(sourceElement);
- }
- ModelExplorerView modelExplorerView = null;
- ModelExplorerPageBookView bookViewPart = (ModelExplorerPageBookView)NavigatorUtils.findViewPart(ModelExplorerPageBookView.VIEW_ID);
- if(bookViewPart != null) {
- modelExplorerView = (ModelExplorerView)bookViewPart.getActiveView();
- Assert.assertNotNull("Impossible to find model explorer view", modelExplorerView);
- }
- NavigatorDnDService dndService = (NavigatorDnDService)modelExplorerView.getNavigatorContentService().getDnDService();
- Assert.assertNotNull("Impossible to find dnd service", dndService);
- CommonDropAdapter commonDropAdapter = ((CustomCommonViewer)modelExplorerView.getCommonViewer()).getDropAdapter();
- CommonDropAdapterAssistant[] commonDropAdapterAssistants = dndService.findCommonDropAdapterAssistants(targetMEI, (IStructuredSelection)modelExplorerView.getCommonViewer().getSelection());
- List<CompoundCommand> results = new ArrayList<CompoundCommand>();
- for(CommonDropAdapterAssistant assistant : commonDropAdapterAssistants) {
- // try to adapt to a Papyrus drop assistant. If not, send a warning
- if(!(assistant instanceof org.eclipse.papyrus.views.modelexplorer.dnd.CommonDropAdapterAssistant)) {
- fail("this test expects that only papyrus drop assistants are provided for papyrus model explorer");
- }
- org.eclipse.papyrus.views.modelexplorer.dnd.CommonDropAdapterAssistant papyrusAssistant = ((org.eclipse.papyrus.views.modelexplorer.dnd.CommonDropAdapterAssistant)assistant);
- Field currentOperationField = ViewerDropAdapter.class.getDeclaredField("currentOperation");
- Assert.assertNotNull(currentOperationField);
- currentOperationField.setAccessible(true);
- currentOperationField.set(commonDropAdapter, DND.DROP_MOVE);
- System.err.println(commonDropAdapter.getCurrentOperation()); // should be 2
- Field currentLocationField = ViewerDropAdapter.class.getDeclaredField("currentLocation");
- Assert.assertNotNull(currentLocationField);
- currentLocationField.setAccessible(true);
- currentLocationField.set(commonDropAdapter, ViewerDropAdapter.LOCATION_ON);
- System.err.println(commonDropAdapter.getCurrentLocation()); // should be 3
- LocalSelectionTransfer.getTransfer().setSelection(modelExplorerView.getCommonViewer().getSelection());
- CompoundCommand command = papyrusAssistant.getDrop(targetMEI);
- results.add(command);
- }
- return results;
- }
-
- public void testExecutableDropOfDiagram(Diagram sourceElement, EObject targetElement) throws Exception {
- Assert.assertFalse("Editor should not be dirty at the beginning of the test", EditorUtils.getEditor().isDirty());
- EObject initialDiagramContainer = sourceElement.getElement();
- // find command for the drag / drop (source, target)
- List<CompoundCommand> dropCommands = getListOfDropCommands(sourceElement, targetElement);
- // create only one compound command
- CompoundCommand executableCommand = new CompoundCommand();
- for(CompoundCommand cc : dropCommands) {
- executableCommand.append(cc);
- }
- getEditingDomain().getCommandStack().execute(executableCommand);
- // check results
- Assert.assertEquals("Context of the diagram should be the target: " + printElement(targetElement), targetElement, sourceElement.getElement());
- Assert.assertNotNull("diagram should still be contained in a resource", sourceElement.eResource());
- // try to undo
- getEditingDomain().getCommandStack().undo();
- Assert.assertEquals("Context of the diagram should be the initial value: " + printElement(initialDiagramContainer), initialDiagramContainer, sourceElement.getElement());
- // try to redo
- getEditingDomain().getCommandStack().redo();
- // check results
- Assert.assertEquals("Context of the diagram should be the target: " + printElement(targetElement), targetElement, sourceElement.getElement());
- Assert.assertNotNull("diagram should still be contained in a resource", sourceElement.eResource());
- // undo to go to previous state
- getEditingDomain().getCommandStack().undo();
- Assert.assertEquals("Context of the diagram should be the initial value: " + printElement(initialDiagramContainer), initialDiagramContainer, sourceElement.getElement());
-
- Assert.assertFalse("Editor should not be dirty at the end of the test", EditorUtils.getEditor().isDirty());
- }
-
- public void testUnexecutableDropOfDiagram(Diagram sourceElement, EObject targetElement) throws Exception {
- // find command for the drag / drop (source, target)
- List<CompoundCommand> dropCommands = getListOfDropCommands(sourceElement, targetElement);
- // create only one compound command
- // boolean that indicates that the command can really be not executable
- boolean notexecutable = true;
- for(CompoundCommand cc : dropCommands) {
- if(cc != null && !cc.isEmpty()) {
- if(cc.canExecute()) {
- notexecutable = false;
- }
- }
- }
- Assert.assertTrue("It should be impossible to move " + printElement(sourceElement) + " on " + printElement(targetElement), notexecutable);
- }
-}
+/***************************************************************************** + * 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: + * + * CEA LIST - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.modelexplorer.tests.dragdrop; + +import static org.junit.Assert.fail; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.emf.common.command.CompoundCommand; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ViewerDropAdapter; +import org.eclipse.papyrus.emf.facet.custom.metamodel.v0_2_0.internal.treeproxy.EObjectTreeElement; +import org.eclipse.papyrus.sysml.modelexplorer.tests.common.AbstractModelExplorerTest; +import org.eclipse.papyrus.sysml.modelexplorer.tests.utils.EditorUtils; +import org.eclipse.papyrus.views.modelexplorer.CustomCommonViewer; +import org.eclipse.papyrus.views.modelexplorer.ModelExplorerPageBookView; +import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView; +import org.eclipse.papyrus.views.modelexplorer.NavigatorUtils; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService; +import org.eclipse.ui.navigator.CommonDropAdapter; +import org.eclipse.ui.navigator.CommonDropAdapterAssistant; +import org.junit.Assert; +import org.junit.Before; + +/** + * Abstract Class to implement diagram drag and drop tests. + */ +public class AbstractDragDropTest extends AbstractModelExplorerTest { + + /** + * 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()); //$NON-NLS-1$ + } + + public List<CompoundCommand> getListOfDropCommands(EObject sourceElement, EObject targetElement) throws Exception { + // init source object + EObjectTreeElement sourceMEI = null; + if(sourceElement instanceof Diagram) { + sourceMEI = findSemanticModelElementItem((Diagram)sourceElement); + } else { + sourceMEI = findSemanticModelElementItem(sourceElement); + } + EObjectTreeElement targetMEI = null; + if(targetElement instanceof Diagram) { + targetMEI = findSemanticModelElementItem((Diagram)targetElement); + } else { + targetMEI = findSemanticModelElementItem(targetElement); + } + if(sourceElement instanceof Diagram) { + selectAndRevealDiagram((Diagram)sourceElement); + } else { + selectAndReveal(sourceElement); + } + ModelExplorerView modelExplorerView = null; + ModelExplorerPageBookView bookViewPart = (ModelExplorerPageBookView)NavigatorUtils.findViewPart(ModelExplorerPageBookView.VIEW_ID); + if(bookViewPart != null) { + modelExplorerView = (ModelExplorerView)bookViewPart.getActiveView(); + Assert.assertNotNull("Impossible to find model explorer view", modelExplorerView); //$NON-NLS-1$ + } + NavigatorDnDService dndService = (NavigatorDnDService)modelExplorerView.getNavigatorContentService().getDnDService(); + Assert.assertNotNull("Impossible to find dnd service", dndService); //$NON-NLS-1$ + CommonDropAdapter commonDropAdapter = ((CustomCommonViewer)modelExplorerView.getCommonViewer()).getDropAdapter(); + CommonDropAdapterAssistant[] commonDropAdapterAssistants = dndService.findCommonDropAdapterAssistants(targetMEI, (IStructuredSelection)modelExplorerView.getCommonViewer().getSelection()); + List<CompoundCommand> results = new ArrayList<CompoundCommand>(); + for(CommonDropAdapterAssistant assistant : commonDropAdapterAssistants) { + // try to adapt to a Papyrus drop assistant. If not, send a warning + if(!(assistant instanceof org.eclipse.papyrus.views.modelexplorer.dnd.CommonDropAdapterAssistant)) { + fail("this test expects that only papyrus drop assistants are provided for papyrus model explorer"); //$NON-NLS-1$ + } + org.eclipse.papyrus.views.modelexplorer.dnd.CommonDropAdapterAssistant papyrusAssistant = ((org.eclipse.papyrus.views.modelexplorer.dnd.CommonDropAdapterAssistant)assistant); + Field currentOperationField = ViewerDropAdapter.class.getDeclaredField("currentOperation"); + Assert.assertNotNull(currentOperationField); + currentOperationField.setAccessible(true); + currentOperationField.set(commonDropAdapter, DND.DROP_MOVE); + System.err.println(commonDropAdapter.getCurrentOperation()); // should be 2 + Field currentLocationField = ViewerDropAdapter.class.getDeclaredField("currentLocation"); + Assert.assertNotNull(currentLocationField); + currentLocationField.setAccessible(true); + currentLocationField.set(commonDropAdapter, ViewerDropAdapter.LOCATION_ON); + System.err.println(commonDropAdapter.getCurrentLocation()); // should be 3 + LocalSelectionTransfer.getTransfer().setSelection(modelExplorerView.getCommonViewer().getSelection()); + CompoundCommand command = papyrusAssistant.getDrop(targetMEI); + results.add(command); + } + return results; + } + + public void testExecutableDropOfDiagram(Diagram sourceElement, EObject targetElement) throws Exception { + Assert.assertFalse("Editor should not be dirty at the beginning of the test", EditorUtils.getEditor().isDirty()); //$NON-NLS-1$ + EObject initialDiagramContainer = sourceElement.getElement(); + // find command for the drag / drop (source, target) + List<CompoundCommand> dropCommands = getListOfDropCommands(sourceElement, targetElement); + // create only one compound command + CompoundCommand executableCommand = new CompoundCommand(); + for(CompoundCommand cc : dropCommands) { + executableCommand.append(cc); + } + getEditingDomain().getCommandStack().execute(executableCommand); + // check results + Assert.assertEquals("Context of the diagram should be the target: " + printElement(targetElement), targetElement, sourceElement.getElement()); //$NON-NLS-1$ + Assert.assertNotNull("diagram should still be contained in a resource", sourceElement.eResource()); //$NON-NLS-1$ + // try to undo + getEditingDomain().getCommandStack().undo(); + Assert.assertEquals("Context of the diagram should be the initial value: " + printElement(initialDiagramContainer), initialDiagramContainer, sourceElement.getElement()); //$NON-NLS-1$ + // try to redo + getEditingDomain().getCommandStack().redo(); + // check results + Assert.assertEquals("Context of the diagram should be the target: " + printElement(targetElement), targetElement, sourceElement.getElement()); //$NON-NLS-1$ + Assert.assertNotNull("diagram should still be contained in a resource", sourceElement.eResource()); //$NON-NLS-1$ + // undo to go to previous state + getEditingDomain().getCommandStack().undo(); + Assert.assertEquals("Context of the diagram should be the initial value: " + printElement(initialDiagramContainer), initialDiagramContainer, sourceElement.getElement()); //$NON-NLS-1$ + + Assert.assertFalse("Editor should not be dirty at the end of the test", EditorUtils.getEditor().isDirty()); //$NON-NLS-1$ + } + + public void testUnexecutableDropOfDiagram(Diagram sourceElement, EObject targetElement) throws Exception { + // find command for the drag / drop (source, target) + List<CompoundCommand> dropCommands = getListOfDropCommands(sourceElement, targetElement); + // create only one compound command + // boolean that indicates that the command can really be not executable + boolean notexecutable = true; + for(CompoundCommand cc : dropCommands) { + if(cc != null && !cc.isEmpty()) { + if(cc.canExecute()) { + notexecutable = false; + } + } + } + Assert.assertTrue("It should be impossible to move " + printElement(sourceElement) + " on " + printElement(targetElement), notexecutable); //$NON-NLS-1$ //$NON-NLS-2$ + } +} diff --git a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/utils/EditorUtils.java b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/utils/EditorUtils.java index b6ff508f5c3..c026ac2656d 100644 --- a/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/utils/EditorUtils.java +++ b/tests/junit/plugins/sysml/org.eclipse.papyrus.sysml.modelexplorer.tests/test/org/eclipse/papyrus/sysml/modelexplorer/tests/utils/EditorUtils.java @@ -1,75 +1,75 @@ -/*****************************************************************************
- * 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.utils;
-
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
-
-
-/**
- * Utility class for tests
- */
-public class EditorUtils {
-
- /**
- * Retrieves current active editor
- *
- * @return current active editor
- * @throws Exception
- * exception thrown in case of issue
- */
- public static IEditorPart getEditor() throws Exception {
- RunnableWithResult<IEditorPart> runnable;
-
- Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<IEditorPart>() {
-
- public void run() {
- IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- setResult(editor);
- }
- });
-
- return runnable.getResult();
- }
-
- public static DiagramEditor getDiagramEditor() throws Exception {
-
- ServicesRegistry serviceRegistry = (ServicesRegistry)getEditor().getAdapter(ServicesRegistry.class);
- try {
- return (DiagramEditor)ServiceUtils.getInstance().getNestedActiveIEditorPart(serviceRegistry);
-
- } catch (ServiceException e) {
- throw new Exception("Unable to retrieve service.", e);
- } catch (ClassCastException e) {
- throw new Exception("Active diagram is not a DiagramEditor." + e.getMessage(), e);
- }
- }
-
- public static DiagramEditPart getDiagramEditPart() throws Exception {
-
- try {
- return getDiagramEditor().getDiagramEditPart();
-
- } catch (NullPointerException e) {
- throw new Exception("Could not find diagram edit part.", e);
- }
- }
-
-}
+/***************************************************************************** + * 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.utils; + +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.core.services.ServicesRegistry; +import org.eclipse.papyrus.infra.core.utils.ServiceUtils; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.PlatformUI; + + +/** + * Utility class for tests + */ +public class EditorUtils { + + /** + * Retrieves current active editor + * + * @return current active editor + * @throws Exception + * exception thrown in case of issue + */ + public static IEditorPart getEditor() throws Exception { + RunnableWithResult<IEditorPart> runnable; + + Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<IEditorPart>() { + + public void run() { + IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); + setResult(editor); + } + }); + + return runnable.getResult(); + } + + public static DiagramEditor getDiagramEditor() throws Exception { + + ServicesRegistry serviceRegistry = (ServicesRegistry)getEditor().getAdapter(ServicesRegistry.class); + try { + return (DiagramEditor)ServiceUtils.getInstance().getNestedActiveIEditorPart(serviceRegistry); + + } catch (ServiceException e) { + throw new Exception("Unable to retrieve service.", e); //$NON-NLS-1$ + } catch (ClassCastException e) { + throw new Exception("Active diagram is not a DiagramEditor." + e.getMessage(), e); //$NON-NLS-1$ + } + } + + public static DiagramEditPart getDiagramEditPart() throws Exception { + + try { + return getDiagramEditor().getDiagramEditPart(); + + } catch (NullPointerException e) { + throw new Exception("Could not find diagram edit part.", e); //$NON-NLS-1$ + } + } + +} |