Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 214214 Details for
Bug 370119
Old welcome support appears when the "new" intro is defined
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
JUnit Test Case for the issue
org.eclipse.ui.internal.WorkbenchWindow_370119-JUnitTest.patch (text/plain), 9.22 KB, created by
Victor Rubezhny
on 2012-04-18 19:37:22 EDT
(
hide
)
Description:
JUnit Test Case for the issue
Filename:
MIME Type:
Creator:
Victor Rubezhny
Created:
2012-04-18 19:37:22 EDT
Size:
9.22 KB
patch
obsolete
>Index: Eclipse UI Tests/org/eclipse/ui/tests/commands/Bug370119Test.java >=================================================================== >RCS file: Eclipse UI Tests/org/eclipse/ui/tests/commands/Bug370119Test.java >diff -N Eclipse UI Tests/org/eclipse/ui/tests/commands/Bug370119Test.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse UI Tests/org/eclipse/ui/tests/commands/Bug370119Test.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,248 @@ >+/******************************************************************************* >+ * Copyright (c) 2012 IBM Corporation and others. >+ * 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: >+ * IBM Corporation - initial API and implementation >+ ******************************************************************************/ >+ >+package org.eclipse.ui.tests.commands; >+ >+import java.lang.reflect.Method; >+ >+import org.eclipse.core.commands.AbstractHandler; >+import org.eclipse.core.commands.ExecutionEvent; >+import org.eclipse.core.commands.ExecutionException; >+import org.eclipse.jface.action.Action; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.swt.widgets.Event; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; >+import org.eclipse.ui.commands.ICommand; >+import org.eclipse.ui.handlers.IHandlerActivation; >+import org.eclipse.ui.handlers.IHandlerService; >+import org.eclipse.ui.internal.WorkbenchWindow; >+import org.eclipse.ui.internal.actions.CommandAction; >+import org.eclipse.ui.tests.harness.util.UITestCase; >+ >+/** >+ * >+ * @since 3.5 >+ * >+ */ >+public class Bug370119Test extends UITestCase { >+ // you can find these commands in org.eclipse.ui.tests/plugin.xml >+ private static final String PREFIX = "tests.commands.global."; >+ private static final String CMD_ID = PREFIX + "Command1"; >+ private static final String ACT1_ID = PREFIX + "Action1"; >+ private static final String ACT2_ID = PREFIX + "Action2"; >+ >+ private IHandlerService handlerService; >+ TestCommandAction testCommandAction; >+ TestCommandActionHandler testCommandActionHandler; >+ IHandlerActivation testCommandActionActivation; >+ TestAction testAction; >+ >+ >+ interface ITestAction { >+ void clear(); >+ boolean isExecuted(); >+ } >+ >+ private static class TestCommandAction extends CommandAction implements >+ IWorkbenchAction, ITestAction { >+ private boolean executed = false; >+ >+ public TestCommandAction(String commandId, >+ IWorkbenchWindow window) { >+ super(window, commandId); >+ setActionDefinitionId(commandId); >+ } >+ >+ public void run() { >+ runWithEvent(null); >+ } >+ >+ public void runWithEvent(Event event) { >+ executed = true; >+ } >+ >+ public void clear() { >+ executed = false; >+ } >+ >+ public boolean isExecuted() { >+ return executed; >+ } >+ } >+ >+ private static class TestAction extends Action implements >+ IWorkbenchAction, ITestAction { >+ private boolean executed = false; >+ >+ public TestAction(String commandId) { >+ super(commandId); >+ setActionDefinitionId(commandId); >+ } >+ >+ public void dispose() { >+ } >+ >+ public void run() { >+ runWithEvent(null); >+ } >+ >+ public void runWithEvent(Event event) { >+ executed = true; >+ } >+ >+ public void clear() { >+ executed = false; >+ } >+ >+ public boolean isExecuted() { >+ return executed; >+ } >+ } >+ >+ /* >+ * Creates an action to be used along with ActionHandler instance in Global Action Handlers mapping >+ */ >+ public TestAction createTestAction(String commandID, String actionID) { >+ TestAction action = new TestAction(commandID); >+ action.setId(actionID); >+ action.setText(actionID); >+ return action; >+ } >+ >+ /* >+ * Creates an action to be used with IActionCommandMappingService mapping >+ */ >+ public TestCommandAction createTestCommandAction(IWorkbenchWindow window, String commandID, String actionID) { >+ TestCommandAction action = new TestCommandAction(commandID, window); >+ action.setId(actionID); >+ action.setText(actionID); >+ return action; >+ } >+ >+ private static class TestCommandActionHandler extends AbstractHandler { >+ TestCommandAction commandAction; >+ /** >+ * >+ */ >+ public TestCommandActionHandler(TestCommandAction commandAction) { >+ this.commandAction = commandAction; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) >+ */ >+ public Object execute(ExecutionEvent event) throws ExecutionException { >+ commandAction.run(); >+ return null; >+ } >+ } >+ >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.ui.tests.harness.util.UITestCase#doSetUp() >+ */ >+ protected void doSetUp() throws Exception { >+ super.doSetUp(); >+ handlerService = (IHandlerService) fWorkbench >+ .getService(IHandlerService.class); >+ >+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); >+ if (window != null) { >+ testCommandAction = createTestCommandAction(window, CMD_ID, ACT1_ID); >+ testCommandActionHandler = new TestCommandActionHandler(testCommandAction); >+ testCommandActionActivation = handlerService.activateHandler(CMD_ID, testCommandActionHandler); >+ testAction = createTestAction(CMD_ID, ACT2_ID); >+ } >+ } >+ >+ /* >+ * (non-Javadoc) >+ * >+ * @see org.eclipse.ui.tests.harness.util.UITestCase#doTearDown() >+ */ >+ protected void doTearDown() throws Exception { >+ if (testCommandActionActivation != null) { >+ handlerService.deactivateHandler(testCommandActionActivation); >+ testCommandActionActivation = null; >+ } >+ >+ super.doTearDown(); >+ } >+ >+ /** >+ * @param testName >+ */ >+ public Bug370119Test(String testName) { >+ super(testName); >+ } >+ >+ /* >+ * Invokes the method void registerGlobalAction(IAction globalAction) on WorkbenchWindow instance >+ * >+ * @param action The action to be registered >+ * @param window The instance of WorkbenchWindow >+ */ >+ private void invokeRegisterGlobalAction(IAction action, WorkbenchWindow window) { >+ try { >+ Method m = WorkbenchWindow.class.getDeclaredMethod("registerGlobalAction", new Class[] {IAction.class}); //$NON-NLS-1$ >+ m.setAccessible(true); >+ m.invoke(window, new Object[] {action}); >+ } catch (Exception e) { >+ fail("An error occured while invoking registerGlobalAction() method on WorkbenchWindow instance!", e); >+ } >+ } >+ >+ /* >+ * Test performs the following checks: >+ * - Registers the Action within the WorkbenchWindow (ActionHandler will be created and registered) >+ * - Asserts that the Action is registered and can be executed >+ * - Registers the CommandAction within the WorkbenchWindow (no ActionHandler is to be created, the old one is to be removed) >+ * - Asserts that the CommandAction is registered and can be executed as well as the old ActionHandler is removed and isn't used anymore >+ */ >+ >+ public void testActionRegistration() throws Exception { >+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); >+ assertNotNull("Workbench Window instance doesn't exist!", window); >+ assertTrue("Workbench Window is not instance of WorkbenchWindow", (window instanceof >+ WorkbenchWindow)); >+ WorkbenchWindow wWindow = (WorkbenchWindow)window; >+ >+ // Register Action (ActionHandler instance will be created for the Action) >+ invokeRegisterGlobalAction(testAction, wWindow); >+ >+ // Make sure that testAction can be executed >+ ICommand cmd = fWorkbench.getCommandSupport().getCommandManager().getCommand(CMD_ID); >+ assertNotNull("Test Command not found for ID: " + CMD_ID, cmd); >+ >+ cmd.execute(null); >+ assertTrue("Test Action is not executed but should be!", testAction.isExecuted()); >+ assertFalse("Test Command Action is executed but shouldn't be!", testCommandAction.isExecuted()); >+ >+ testAction.clear(); // Clear execution flag >+ testCommandAction.clear(); // Clear execution flag >+ >+ // Register Command Action (ActionHandler instance will not be created) >+ invokeRegisterGlobalAction(testCommandAction, wWindow); >+ // Make sure that testAction can be executed >+ cmd = fWorkbench.getCommandSupport().getCommandManager().getCommand(CMD_ID); >+ assertNotNull("Test Command not found for ID: " + CMD_ID, cmd); >+ >+ cmd.execute(null); >+ assertTrue("Test Command Action is not executed but should be!", testCommandAction.isExecuted()); >+ assertFalse("Test Action is executed but shouldn't be!", testAction.isExecuted()); >+ } >+} >Index: Eclipse UI Tests/org/eclipse/ui/tests/commands/CommandsTestSuite.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/commands/CommandsTestSuite.java,v >retrieving revision 1.25 >diff -u -r1.25 CommandsTestSuite.java >--- Eclipse UI Tests/org/eclipse/ui/tests/commands/CommandsTestSuite.java 25 May 2009 20:52:54 -0000 1.25 >+++ Eclipse UI Tests/org/eclipse/ui/tests/commands/CommandsTestSuite.java 18 Apr 2012 23:34:28 -0000 >@@ -48,5 +48,6 @@ > addTest(new TestSuite(ActionDelegateProxyTest.class)); > addTest(new TestSuite(ToggleStateTest.class)); > addTest(new TestSuite(RadioStateTest.class)); >+ addTest(new TestSuite(Bug370119Test.class)); > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 370119
:
210260
|
213497
|
213548
|
213549
|
213576
| 214214