|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2005 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.tests.dynamicplugins; |
| 12 |
|
| 13 |
import java.util.Collections; |
| 14 |
|
| 15 |
import org.eclipse.core.commands.Command; |
| 16 |
import org.eclipse.core.commands.ExecutionEvent; |
| 17 |
import org.eclipse.core.commands.ExecutionException; |
| 18 |
import org.eclipse.core.commands.NotHandledException; |
| 19 |
import org.eclipse.core.commands.common.NamedHandleObject; |
| 20 |
import org.eclipse.core.commands.common.NotDefinedException; |
| 21 |
import org.eclipse.jface.bindings.Binding; |
| 22 |
import org.eclipse.jface.bindings.TriggerSequence; |
| 23 |
import org.eclipse.jface.bindings.keys.KeySequence; |
| 24 |
import org.eclipse.jface.bindings.keys.ParseException; |
| 25 |
import org.eclipse.jface.contexts.IContextIds; |
| 26 |
import org.eclipse.ui.commands.ICommandService; |
| 27 |
import org.eclipse.ui.contexts.IContextService; |
| 28 |
import org.eclipse.ui.internal.IWorkbenchConstants; |
| 29 |
import org.eclipse.ui.keys.IBindingService; |
| 30 |
|
| 31 |
/** |
| 32 |
* Tests whether the "org.eclipse.ui.commands" extension point can be added and |
| 33 |
* removed dynamically. |
| 34 |
* |
| 35 |
* @since 3.1.1 |
| 36 |
*/ |
| 37 |
public final class CommandsExtensionDynamicTest extends DynamicTestCase { |
| 38 |
|
| 39 |
/** |
| 40 |
* Constructs a new instance of <code>CommandsExtensionDynamicTest</code>. |
| 41 |
* |
| 42 |
* @param testName |
| 43 |
* The name of the test; may be <code>null</code>. |
| 44 |
*/ |
| 45 |
public CommandsExtensionDynamicTest(final String testName) { |
| 46 |
super(testName); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Returns the full-qualified identifier of the extension to be tested. |
| 51 |
* |
| 52 |
* @return The extension identifier; never <code>null</code>. |
| 53 |
*/ |
| 54 |
protected final String getExtensionId() { |
| 55 |
return "commandsExtensionDynamicTest.testDynamicCommandAddition"; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Returns the unqualified identifier of the extension point to be tested. |
| 60 |
* |
| 61 |
* @return The extension point identifier; never <code>null</code>. |
| 62 |
*/ |
| 63 |
protected final String getExtensionPoint() { |
| 64 |
return IWorkbenchConstants.PL_COMMANDS; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Returns the relative location of the folder on disk containing the |
| 69 |
* plugin.xml file. |
| 70 |
* |
| 71 |
* @return The relative install location; never <code>null</code>. |
| 72 |
*/ |
| 73 |
protected final String getInstallLocation() { |
| 74 |
return "data/org.eclipse.commandsExtensionDynamicTest"; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Tests whether the items defined in the extension point can be added and |
| 79 |
* removed dynamically. It tests that the data doesn't exist, and then loads |
| 80 |
* the extension. It tests that the data then exists, and unloads the |
| 81 |
* extension. It tests that the data then doesn't exist. |
| 82 |
* |
| 83 |
* @throws ParseException |
| 84 |
* If "M1+W" can't be parsed by the extension point. |
| 85 |
*/ |
| 86 |
public final void testCommands() throws ParseException { |
| 87 |
final IBindingService bindingService = (IBindingService) getWorkbench() |
| 88 |
.getAdapter(IBindingService.class); |
| 89 |
final ICommandService commandService = (ICommandService) getWorkbench() |
| 90 |
.getAdapter(ICommandService.class); |
| 91 |
final IContextService contextService = (IContextService) getWorkbench() |
| 92 |
.getAdapter(IContextService.class); |
| 93 |
final TriggerSequence triggerSequence = KeySequence.getInstance("M1+W"); |
| 94 |
NamedHandleObject namedHandleObject; |
| 95 |
Binding[] bindings; |
| 96 |
Command command; |
| 97 |
boolean found; |
| 98 |
|
| 99 |
assertTrue(!"monkey".equals(bindingService.getActiveScheme().getId())); |
| 100 |
found = false; |
| 101 |
bindings = bindingService.getBindings(); |
| 102 |
if (bindings != null) { |
| 103 |
for (int i = 0; i < bindings.length; i++) { |
| 104 |
final Binding binding = bindings[i]; |
| 105 |
if ("monkey".equals(binding.getSchemeId()) |
| 106 |
&& IContextIds.CONTEXT_ID_WINDOW.equals(binding |
| 107 |
.getContextId()) |
| 108 |
&& "monkey".equals(binding.getParameterizedCommand() |
| 109 |
.getId()) && binding.getPlatform() == null |
| 110 |
&& binding.getLocale() == null |
| 111 |
&& binding.getType() == Binding.SYSTEM |
| 112 |
&& triggerSequence.equals(binding.getTriggerSequence())) { |
| 113 |
found = true; |
| 114 |
|
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
assertTrue(!found); |
| 119 |
namedHandleObject = bindingService.getScheme("monkey"); |
| 120 |
try { |
| 121 |
namedHandleObject.getName(); |
| 122 |
fail(); |
| 123 |
} catch (final NotDefinedException e) { |
| 124 |
assertTrue(true); |
| 125 |
} |
| 126 |
namedHandleObject = commandService.getCategory("monkey"); |
| 127 |
try { |
| 128 |
namedHandleObject.getName(); |
| 129 |
fail(); |
| 130 |
} catch (final NotDefinedException e) { |
| 131 |
assertTrue(true); |
| 132 |
} |
| 133 |
command = commandService.getCommand("monkey"); |
| 134 |
try { |
| 135 |
command.execute(new ExecutionEvent(Collections.EMPTY_MAP, null, |
| 136 |
null)); |
| 137 |
fail(); |
| 138 |
} catch (final ExecutionException e) { |
| 139 |
fail(); |
| 140 |
} catch (final NotHandledException e) { |
| 141 |
assertTrue(true); |
| 142 |
} |
| 143 |
try { |
| 144 |
command.getName(); |
| 145 |
fail(); |
| 146 |
} catch (final NotDefinedException e) { |
| 147 |
assertTrue(true); |
| 148 |
} |
| 149 |
namedHandleObject = contextService.getContext("context"); |
| 150 |
try { |
| 151 |
namedHandleObject.getName(); |
| 152 |
fail(); |
| 153 |
} catch (final NotDefinedException e) { |
| 154 |
assertTrue(true); |
| 155 |
} |
| 156 |
namedHandleObject = contextService.getContext("scope"); |
| 157 |
try { |
| 158 |
namedHandleObject.getName(); |
| 159 |
fail(); |
| 160 |
} catch (final NotDefinedException e) { |
| 161 |
assertTrue(true); |
| 162 |
} |
| 163 |
|
| 164 |
getBundle(); |
| 165 |
|
| 166 |
assertTrue("monkey".equals(bindingService.getActiveScheme().getId())); |
| 167 |
found = false; |
| 168 |
bindings = bindingService.getBindings(); |
| 169 |
if (bindings != null) { |
| 170 |
for (int i = 0; i < bindings.length; i++) { |
| 171 |
final Binding binding = bindings[i]; |
| 172 |
if ("monkey".equals(binding.getSchemeId()) |
| 173 |
&& IContextIds.CONTEXT_ID_WINDOW.equals(binding |
| 174 |
.getContextId()) |
| 175 |
&& "monkey".equals(binding.getParameterizedCommand() |
| 176 |
.getId()) && binding.getPlatform() == null |
| 177 |
&& binding.getLocale() == null |
| 178 |
&& binding.getType() == Binding.SYSTEM |
| 179 |
&& triggerSequence.equals(binding.getTriggerSequence())) { |
| 180 |
found = true; |
| 181 |
|
| 182 |
} |
| 183 |
} |
| 184 |
} |
| 185 |
assertTrue(found); |
| 186 |
namedHandleObject = bindingService.getScheme("monkey"); |
| 187 |
try { |
| 188 |
assertTrue("Monkey".equals(namedHandleObject.getName())); |
| 189 |
} catch (final NotDefinedException e) { |
| 190 |
fail(); |
| 191 |
} |
| 192 |
command = commandService.getCommand("monkey"); |
| 193 |
try { |
| 194 |
command.execute(new ExecutionEvent(Collections.EMPTY_MAP, null, |
| 195 |
null)); |
| 196 |
} catch (final ExecutionException e) { |
| 197 |
fail(); |
| 198 |
} catch (final NotHandledException e) { |
| 199 |
fail(); |
| 200 |
} |
| 201 |
try { |
| 202 |
assertEquals("Monkey", command.getName()); |
| 203 |
} catch (final NotDefinedException e) { |
| 204 |
fail(); |
| 205 |
} |
| 206 |
namedHandleObject = commandService.getCommand("monkey"); |
| 207 |
try { |
| 208 |
assertTrue("Monkey".equals(namedHandleObject.getName())); |
| 209 |
} catch (final NotDefinedException e) { |
| 210 |
fail(); |
| 211 |
} |
| 212 |
namedHandleObject = contextService.getContext("context"); |
| 213 |
try { |
| 214 |
assertTrue("Monkey".equals(namedHandleObject.getName())); |
| 215 |
} catch (final NotDefinedException e) { |
| 216 |
fail(); |
| 217 |
} |
| 218 |
namedHandleObject = contextService.getContext("scope"); |
| 219 |
try { |
| 220 |
assertTrue("Monkey".equals(namedHandleObject.getName())); |
| 221 |
} catch (final NotDefinedException e) { |
| 222 |
fail(); |
| 223 |
} |
| 224 |
|
| 225 |
removeBundle(); |
| 226 |
|
| 227 |
assertTrue(!"monkey".equals(bindingService.getActiveScheme().getId())); |
| 228 |
found = false; |
| 229 |
bindings = bindingService.getBindings(); |
| 230 |
if (bindings != null) { |
| 231 |
for (int i = 0; i < bindings.length; i++) { |
| 232 |
final Binding binding = bindings[i]; |
| 233 |
if ("monkey".equals(binding.getSchemeId()) |
| 234 |
&& IContextIds.CONTEXT_ID_WINDOW.equals(binding |
| 235 |
.getContextId()) |
| 236 |
&& "monkey".equals(binding.getParameterizedCommand() |
| 237 |
.getId()) && binding.getPlatform() == null |
| 238 |
&& binding.getLocale() == null |
| 239 |
&& binding.getType() == Binding.SYSTEM |
| 240 |
&& triggerSequence.equals(binding.getTriggerSequence())) { |
| 241 |
found = true; |
| 242 |
|
| 243 |
} |
| 244 |
} |
| 245 |
} |
| 246 |
assertTrue(!found); |
| 247 |
namedHandleObject = bindingService.getScheme("monkey"); |
| 248 |
try { |
| 249 |
namedHandleObject.getName(); |
| 250 |
fail(); |
| 251 |
} catch (final NotDefinedException e) { |
| 252 |
assertTrue(true); |
| 253 |
} |
| 254 |
namedHandleObject = commandService.getCategory("monkey"); |
| 255 |
try { |
| 256 |
namedHandleObject.getName(); |
| 257 |
fail(); |
| 258 |
} catch (final NotDefinedException e) { |
| 259 |
assertTrue(true); |
| 260 |
} |
| 261 |
command = commandService.getCommand("monkey"); |
| 262 |
try { |
| 263 |
command.execute(new ExecutionEvent(Collections.EMPTY_MAP, null, |
| 264 |
null)); |
| 265 |
fail(); |
| 266 |
} catch (final ExecutionException e) { |
| 267 |
fail(); |
| 268 |
} catch (final NotHandledException e) { |
| 269 |
assertTrue(true); |
| 270 |
} |
| 271 |
try { |
| 272 |
command.getName(); |
| 273 |
fail(); |
| 274 |
} catch (final NotDefinedException e) { |
| 275 |
assertTrue(true); |
| 276 |
} |
| 277 |
namedHandleObject = contextService.getContext("context"); |
| 278 |
try { |
| 279 |
namedHandleObject.getName(); |
| 280 |
fail(); |
| 281 |
} catch (final NotDefinedException e) { |
| 282 |
assertTrue(true); |
| 283 |
} |
| 284 |
namedHandleObject = contextService.getContext("scope"); |
| 285 |
try { |
| 286 |
namedHandleObject.getName(); |
| 287 |
fail(); |
| 288 |
} catch (final NotDefinedException e) { |
| 289 |
assertTrue(true); |
| 290 |
} |
| 291 |
} |
| 292 |
} |