Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Junit testing command execution?
Junit testing command execution? [message #334775] Fri, 27 February 2009 00:52 Go to next message
Eclipse UserFriend
I'm trying to write a junit test that executes a command. When I run
the test, I get the following error:

org.eclipse.core.commands.NotEnabledException: Trying to execute the
disabled command my.command.id

My command handler is enabled when the selection count is one or more,
and I'm calling viewer.setSelection() in the unit test. The command
and handler work properly when running the UI. Any ideas on what I'm
doing wrong in the junit test?

Bryan
Re: Junit testing command execution? [message #334784 is a reply to message #334775] Fri, 27 February 2009 09:20 Go to previous messageGo to next message
Eclipse UserFriend
if your viewer is the ISelectionProvider for your site (usually done
with getSite().setSelectionProvider(viewer) in createPartControl(*)) it
would normally be OK.

When you set the selection, the selection provider updates the
"selection" variable which causes the IEvaluationService to re-evaluate
all enabledWhen expressions that use selection (or the default variable).

When you are calling viewer.setSelection(*), are you setting it to an
ISelection containing one of your model objects?

For some things like TreeViewers, they set the selection on the widget
and then get the selection from the widget. That might not be processed
without spinning the display loop:

while (display.readAndDispatch()) ;

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: Junit testing command execution? [message #334794 is a reply to message #334784] Fri, 27 February 2009 10:52 Go to previous messageGo to next message
Eclipse UserFriend
Paul, thanks for the reply. I tryied adding

while (display.readAndDispatch()) ;

and that didn't help. When I execute the command with

handlerService.executeCommand("my.command.id", null);

I see in the debugger the value of "selection" inside WithExpression is
empty so the fundamental problem is that the selection variable is not
being updated.

I'm setting the selection by calling:

view.setSelection(new StructuredSelection(object));

The view is registered with the siet as an ISelectionProvider. The
call to setSelection() on the view delegates to a TableViewer on which
the view is registered as a selection changed listener. In the
debugger, I see view's selectionChanged() function get called before I
execute the command. Here is the view's selectionChanged()

public void selectionChanged(SelectionChangedEvent event)
{
for (ISelectionChangedListener listener : selectionListeners)
listener.selectionChanged(event);

updateStatus();
}

(Aside: I know the TableViewer can be registered as a selection
provider, but there's a technical reason that I can't do that)

When steppiing through the selectionChanged() function above, I see
several listeners get called. Is there a good breakpoint I can set to
see the code that is supposed to update the "selection" variable?

Bryan
Re: Junit testing command execution? [message #334803 is a reply to message #334794] Fri, 27 February 2009 12:51 Go to previous messageGo to next message
Eclipse UserFriend
org.eclipse.ui.internal.services.CurrentSelectionSourceProvi der should
be providing the selection to the IEvaluationService (in 3.4)

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm
Re: Junit testing command execution? [message #334815 is a reply to message #334803] Sat, 28 February 2009 23:22 Go to previous message
Eclipse UserFriend
Paul, thanks for the pointer. I was able to debug my problem and my
unit test is now passing.

Bryan

On 2009-02-27 11:51:25 -0600, Paul Webster <pwebster@ca.ibm.com> said:

> org.eclipse.ui.internal.services.CurrentSelectionSourceProvi der should
> be providing the selection to the IEvaluationService (in 3.4)
>
> PW
Previous Topic:PartInitException at a plugin view
Next Topic:Custom marker icon ignored in problems view
Goto Forum:
  


Current Time: Wed Mar 26 11:54:18 EDT 2025

Powered by FUDForum. Page generated in 0.03567 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top