Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » JUnit testing action contribution
JUnit testing action contribution [message #731667] Sun, 02 October 2011 11:20 Go to next message
Eclipse UserFriend
Originally posted by: Patrick Roemer

Hi,

I hope this is the right group for this question.

In my plugin, I have a contributed action for IJavaProject instances:

<extension point="org.eclipse.ui.popupMenus">
<objectContribution
objectClass="org.eclipse.jdt.core.IJavaProject"
id="myproject.naturecontrib">
<menu
label="My Nature"
path="additions"
id="myproject.naturemenu">
<separator
name="myproject.naturegroup">
</separator>
</menu>
</objectContribution>
<objectContribution
adaptable="true"
id="myproject.addnatureactioncontrib"
objectClass="org.eclipse.jdt.core.IJavaProject">
<action
label="Add my nature"
class="myproject.action.AddMyNature"
enablesFor="1"
menubarPath="myproject.naturemenu/naturegroup"
id="myproject.addnatureaction">
</action>
</objectContribution>
</extension>

(visibility and further contributions/actions left out here.)

Now I'd like to write a plugin JUnit test that ensures that this action
is registered with IJavaProject (and that it is triggered properly and
does the right thing, i.e. adds a nature to the project). I already have
a JUnit test rigging that creates a "blank" project in the test workspace.

I certainly don't want to go for "robot" style UI testing, so I could
imagine two potential approaches:

- Programmatically select the project node in the package explorer's
tree viewer (I already have that), and then somehow trigger the action
associated with this selection - but I have no idea how to do the
latter. Further, since the entry on the "main" popup menu is only a
group, I'd somehow have to gain access to the sub menu and repeat
whatever dance is necessary there.

- Pass an IJavaProject instance to whatever registry keeps track of
object contributions, ask for the set of contributions associated with
this instance, ensure that it contains a proper delegate for my entry
and trigger it. Again, I have no idea where to look for this "registry"
- there's ObjectActionContributorManager, but it's internal.

Any insight is appreciated. I'm pretty sure I'm not the first one who'd
want to implement a test like this, but my Google Fu seems to have lost
me, and diving into the debugger hasn't helped me much so far, either.
If there's more appropriate ways to achieve test coverage for this
scenario, I'd love to hear about those, too, of course.

Best regards and thanks in advance,
Patrick
Re: JUnit testing action contribution [message #733382 is a reply to message #731667] Tue, 04 October 2011 15:39 Go to previous message
Eclipse UserFriend
Originally posted by: Patrick Roemer

Responding to myself:

> - Programmatically select the project node in the package explorer's
> tree viewer (I already have that), and then somehow trigger the action
> associated with this selection - but I have no idea how to do the
> latter. Further, since the entry on the "main" popup menu is only a
> group, I'd somehow have to gain access to the sub menu and repeat
> whatever dance is necessary there.

This can be solved by starting with #getMenu() on the tree and recursing
down into the menu item's #getMenu(). The trick is to issue an SWT.Show
event for each menu to get it populated. Menu items can be selected by
checking the id of their #getData(), cast to IContributionItem (not
nice, but probably less fragile than relying on the label text).

Best regards,
Patrick
Previous Topic:initial results trying to develop a basic plugin
Next Topic:API baseline & target platform
Goto Forum:
  


Current Time: Thu Apr 25 22:34:48 GMT 2024

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

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

Back to the top