diff options
| author | Florian Barbin | 2015-11-19 15:20:19 +0000 |
|---|---|---|
| committer | Florian Barbin | 2015-11-30 14:27:12 +0000 |
| commit | 1f1c1d1e0171172cd6f17e7250e0ee7516b26280 (patch) | |
| tree | edf17fa1c97f8c33c2f84205bf998a09b1365b5c | |
| parent | c79daf76b4b70387e65db6d32b8308013b6dac9c (diff) | |
| download | org.eclipse.sirius-1f1c1d1e0171172cd6f17e7250e0ee7516b26280.tar.gz org.eclipse.sirius-1f1c1d1e0171172cd6f17e7250e0ee7516b26280.tar.xz org.eclipse.sirius-1f1c1d1e0171172cd6f17e7250e0ee7516b26280.zip | |
[481573] Adds SWTBot test
Bug: 481573
Change-Id: I067d2437525056a8f7a7517ead3ba4523733e4e2
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
3 files changed, 335 insertions, 0 deletions
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java index 4257f475bd..1fd1f4c790 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java @@ -56,6 +56,7 @@ import org.eclipse.sirius.tests.swtbot.modelexplorer.RepresentationVisibilityAft import org.eclipse.sirius.tests.swtbot.tabbar.LockedTabBarTest; import org.eclipse.sirius.tests.swtbot.tabbar.NotInvisibleTabBarTest; import org.eclipse.sirius.tests.swtbot.tabbar.TabBarTest; +import org.eclipse.sirius.tests.swtbot.tabbar.TabbarContributorExtensionTest; import org.eclipse.sirius.tests.swtbot.table.SetPropertyOfTableTreeByPropertiesViewTest; import org.eclipse.sirius.tests.swtbot.uml.CopyPasteLayoutOfLabelOfBorderedNodeTest; import org.eclipse.sirius.tests.swtbot.uml.CopyPasteLayoutOfPortsWithConflictWithNotPastedPortsTest; @@ -188,6 +189,7 @@ public class AllTestSuite extends TestCase { suite.addTestSuite(LockedModelExplorerTest.class); suite.addTestSuite(SnapAllShapesTest.class); suite.addTestSuite(MoveEdgeGroupTest.class); + suite.addTestSuite(TabbarContributorExtensionTest.class); } /** diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/TabbarContributorExtensionTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/TabbarContributorExtensionTest.java new file mode 100644 index 0000000000..345133b61d --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/TabbarContributorExtensionTest.java @@ -0,0 +1,208 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.swtbot.tabbar; + +import java.io.ByteArrayInputStream; + +import org.eclipse.core.internal.registry.ExtensionRegistry; +import org.eclipse.core.runtime.ContributorFactoryOSGi; +import org.eclipse.core.runtime.IContributor; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.sirius.common.tools.api.util.ReflectionHelper; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramListEditPart; +import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramNameEditPart; +import org.eclipse.sirius.diagram.ui.edit.api.part.IDDiagramEditPart; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.ExtensionPointTabbarContributorProvider; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.tabbar.Tabbar; +import org.eclipse.sirius.ext.base.Option; +import org.eclipse.sirius.tests.swtbot.Activator; +import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase; +import org.eclipse.sirius.tests.swtbot.support.api.business.UIResource; +import org.eclipse.sirius.tests.swtbot.support.api.condition.CheckSelectedCondition; +import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotSiriusDiagramEditor; +import org.eclipse.sirius.tests.swtbot.support.utils.SWTBotUtils; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart; +import org.eclipse.ui.PlatformUI; + +/** + * Test case to check the tabbar extension point. See + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=481573 + * + * @author Florian Barbin + */ +@SuppressWarnings("restriction") +public class TabbarContributorExtensionTest extends AbstractSiriusSwtBotGefTestCase { + + // We don't need a specific diagram so we reuse an existing one. + private static final String REPRESENTATION_INSTANCE_NAME = "aaaa package entities"; + + private static final String REPRESENTATION_NAME = "Entities"; + + private static final String MODEL = "tc2216.ecore"; + + private static final String SESSION_FILE = "tc2216.aird"; + + private static final String VSM_FILE = "tc2216.odesign"; + + private static final String DATA_UNIT_DIR = "data/unit/portPositionStability/tc-2216/"; + + private static final String FILE_DIR = "/"; + + private static final String PLUGIN_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?eclipse version=\"3.4\"?><plugin><extension id=\"customTabbar\" point=\"" + + ExtensionPointTabbarContributorProvider.EXTENSION_ID + + "\"><tabbarContributor class=\"org.eclipse.sirius.tests.swtbot.tabbar.TabbarContributorSample\"></tabbarContributor></extension></plugin>"; + + @Override + protected void onSetUpBeforeClosingWelcomePage() throws Exception { + copyFileToTestProject(Activator.PLUGIN_ID, DATA_UNIT_DIR, MODEL, SESSION_FILE, VSM_FILE); + } + + @Override + protected void onSetUpAfterOpeningDesignerPerspective() throws Exception { + + sessionAirdResource = new UIResource(designerProject, FILE_DIR, SESSION_FILE); + localSession = designerPerspective.openSessionFromFile(sessionAirdResource); + + } + + /** + * Test that the default tabbar is properly displayed when no contributor is + * provided. + */ + public void testTabbarCountWithoutContributor() { + editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), REPRESENTATION_NAME, REPRESENTATION_INSTANCE_NAME, DDiagram.class); + selectDiagramElement(); + SWTBotUtils.waitAllUiEvents(); + int count = getTabbarItemsCount(); + assertEquals("Unexpected number of tabbar contribution items", 28, count); + selectDiagram(); + SWTBotUtils.waitAllUiEvents(); + count = getTabbarItemsCount(); + assertEquals("Unexpected number of tabbar contribution items", 19, count); + selectEdge(); + SWTBotUtils.waitAllUiEvents(); + count = getTabbarItemsCount(); + assertEquals("Unexpected number of tabbar contribution items", 28, count); + } + + /** + * Tests that the custom tabbar is properly displayed when it is installed + * via extension point. + */ + public void testCustomTabbarContributor() { + registerExtension(); + editor = (SWTBotSiriusDiagramEditor) openRepresentation(localSession.getOpenedSession(), REPRESENTATION_NAME, REPRESENTATION_INSTANCE_NAME, DDiagram.class); + selectDiagramElement(); + SWTBotUtils.waitAllUiEvents(); + int count = getTabbarItemsCount(); + assertEquals("The custom tabbar should be registered", 24, count); + selectDiagram(); + SWTBotUtils.waitAllUiEvents(); + count = getTabbarItemsCount(); + assertEquals("The custom tabbar should be registered", 15, count); + selectEdge(); + SWTBotUtils.waitAllUiEvents(); + count = getTabbarItemsCount(); + assertEquals("The custom tabbar should be registered", 0, count); + } + + private int getTabbarItemsCount() { + DDiagramEditorImpl edit = (DDiagramEditorImpl) editor.getReference().getEditor(false); + Tabbar tabbar = edit.getTabbar(); + Option<Object> toolbarOption = ReflectionHelper.getFieldValueWithoutException(tabbar, "toolBar"); + final ToolBar toolBar = (ToolBar) toolbarOption.get(); + + RunnableWithResult<Integer> result = new RunnableWithResult<Integer>() { + int result = 0; + + @Override + public void run() { + result = new Integer(toolBar.getItemCount()); + } + + @Override + public Integer getResult() { + return result; + } + + @Override + public void setStatus(IStatus status) { + + } + + @Override + public IStatus getStatus() { + return null; + } + }; + PlatformUI.getWorkbench().getDisplay().syncExec(result); + int count = result.getResult(); + return count; + } + + private void selectDiagramElement() { + // Select a diagram element named "loooooooooooong name is very long" + editor.reveal("loooooooooooong name is very long"); + CheckSelectedCondition cs = new CheckSelectedCondition(editor, "loooooooooooong name is very long", AbstractDiagramListEditPart.class); + editor.click("loooooooooooong name is very long"); + bot.waitUntil(cs); + } + + private void selectEdge() { + // Select the edge named "[0..1] ref0" + editor.reveal("[0..1] ref0"); + CheckSelectedCondition cs = new CheckSelectedCondition(editor, "[0..1] ref0", AbstractDiagramNameEditPart.class); + editor.click("[0..1] ref0"); + bot.waitUntil(cs); + } + + private void selectDiagram() { + SWTBotGefEditPart diagPart = editor.rootEditPart().children().iterator().next(); + IDDiagramEditPart part = (IDDiagramEditPart) diagPart.part(); + CheckSelectedCondition cs = new CheckSelectedCondition(editor, part); + editor.select(diagPart); + bot.waitUntil(cs); + } + + /** + * Installs dynamically the tabbar extension. + */ + private void registerExtension() { + IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); + IContributor contributor = ContributorFactoryOSGi.createContributor(Activator.getDefault().getBundle()); + extensionRegistry.addContribution(new ByteArrayInputStream(PLUGIN_XML.getBytes()), contributor, false, null, null, ((ExtensionRegistry) extensionRegistry).getTemporaryUserToken()); + } + + /** + * Remove the installed extension (if it exists). + */ + private void removeExtension() { + IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); + IExtension extension = extensionRegistry.getExtension(ExtensionPointTabbarContributorProvider.EXTENSION_ID, Activator.PLUGIN_ID + ".customTabbar"); + if (extension != null) { + extensionRegistry.removeExtension(extension, ((ExtensionRegistry) extensionRegistry).getTemporaryUserToken()); + } + } + + @Override + protected void tearDown() throws Exception { + removeExtension(); + super.tearDown(); + } + +} diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/TabbarContributorSample.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/TabbarContributorSample.java new file mode 100644 index 0000000000..7d310e5e6e --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/tabbar/TabbarContributorSample.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.swtbot.tabbar; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart; +import org.eclipse.jface.action.IContributionItem; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDDiagramEditPart; +import org.eclipse.sirius.diagram.ui.edit.api.part.IAbstractDiagramNodeEditPart; +import org.eclipse.sirius.diagram.ui.tools.api.editor.tabbar.AbstractTabbarContributor; + +/** + * Example of Tabbar Contributor used to test the extension point. + * + * @author fbarbin + * + */ +public class TabbarContributorSample extends AbstractTabbarContributor { + + private ArrayList<IContributionItem> diagramContributionItems; + + private ArrayList<IContributionItem> diagramElementContributionItems; + + @Override + public List<IContributionItem> getContributionItems(ISelection selection, IDiagramWorkbenchPart part, ToolBarManager manager) { + List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); + if (selection instanceof IStructuredSelection) { + Object firstElement = ((IStructuredSelection) selection).getFirstElement(); + if (firstElement instanceof AbstractDDiagramEditPart) { + contributionItems = getDiagramContributionItem(part, manager); + } else if (firstElement instanceof IAbstractDiagramNodeEditPart) { + contributionItems = getDiagramElementContributionItem(part, manager); + } + } + return contributionItems; + } + + @Override + public boolean accept(ISelection selection) { + boolean accept = false; + if (selection == null) { + accept = true; + } else if (selection instanceof IStructuredSelection) { + Object firstElement = ((IStructuredSelection) selection).getFirstElement(); + if (firstElement instanceof AbstractDDiagramEditPart || firstElement instanceof IAbstractDiagramNodeEditPart) { + accept = true; + } + } + return accept; + } + + @Override + public List<IContributionItem> getContributionItems(IDiagramWorkbenchPart part, ToolBarManager manager) { + return getDiagramContributionItem(part, manager); + } + + private List<IContributionItem> getDiagramContributionItem(IDiagramWorkbenchPart part, ToolBarManager manager) { + if (diagramContributionItems == null) { + diagramContributionItems = new ArrayList<IContributionItem>(); + diagramContributionItems.add(createArrangeMenuManager(part)); + diagramContributionItems.add(createSelectMenuManager()); + diagramContributionItems.add(createLayerContribution(part, manager)); + diagramContributionItems.add(createZoomInContribution(part)); + diagramContributionItems.add(createZoomOutContribution(part)); + diagramContributionItems.add(createZoomContribution(part)); + diagramContributionItems.add(createSelectPinnedElementsContribution(part)); + diagramContributionItems.add(createSelectHiddenElementsContribution(part)); + diagramContributionItems.add(createFilterContribution(part, manager)); + diagramContributionItems.add(createPasteLayoutContribution(part)); + diagramContributionItems.add(createRefreshContribution()); + diagramContributionItems.add(createSaveAsImageContributionItem()); + diagramContributionItems.add(createLayoutingModeContributionItem(part)); + diagramContributionItems.add(createCopyAppearancePropertiesContribution(part)); + diagramContributionItems.add(createCopyLayoutContribution(part)); + } + return diagramContributionItems; + } + + private List<IContributionItem> getDiagramElementContributionItem(IDiagramWorkbenchPart part, ToolBarManager manager) { + if (diagramElementContributionItems == null) { + diagramElementContributionItems = new ArrayList<IContributionItem>(); + diagramElementContributionItems.add(createArrangeMenuManager(part)); + diagramElementContributionItems.add(createAlignMenuManager()); + diagramElementContributionItems.add(createHideElementLabelContribution(part)); + diagramElementContributionItems.add(createHideElementContribution(part)); + diagramElementContributionItems.add(createDeleteFromDiagramContribution(part)); + diagramElementContributionItems.add(createDeleteFromModelContribution(part)); + IContributionItem pinElementContributionItem = createPinElementContribution(part); + diagramElementContributionItems.add(pinElementContributionItem); + diagramElementContributionItems.add(createUnPinElementContribution(part, pinElementContributionItem)); + diagramElementContributionItems.add(createFontColorContribution(part)); + diagramElementContributionItems.add(createPasteLayoutContribution(part)); + diagramElementContributionItems.add(createBoldFontStyleContribution(part)); + diagramElementContributionItems.add(createItalicFontStyleContribution(part)); + diagramElementContributionItems.add(createFontDialogContribution(part)); + diagramElementContributionItems.add(createFillColorContribution(part)); + diagramElementContributionItems.add(createLineColorPropertyContribution(part)); + diagramElementContributionItems.add(createResetStylePropertyContribution(part)); + diagramElementContributionItems.add(createSetStyleToWorkspaceImageContribution(part)); + diagramElementContributionItems.add(createSaveAsImageContributionItem()); + diagramElementContributionItems.add(createDistributeContribution()); + diagramElementContributionItems.add(createLayoutingModeContributionItem(part)); + diagramElementContributionItems.add(createRouterContribution()); + diagramElementContributionItems.add(createCopyAppearancePropertiesContribution(part)); + diagramElementContributionItems.add(createCopyLayoutContribution(part)); + diagramElementContributionItems.add(createSizeBothContribution(part)); + diagramElementContributionItems.add(createAutoSizeContribution(part)); + } + return diagramElementContributionItems; + } + +} |
