Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » JUnit + ResourceSetListener
JUnit + ResourceSetListener [message #1837232] Mon, 25 January 2021 16:03 Go to next message
Grischa Liebel is currently offline Grischa LiebelFriend
Messages: 2
Registered: January 2021
Junior Member
Hi EMFers!

We are writing a customised ResourceSetListener (to log changes on Papyrus Models) and are trying to unit test the thing (essentially writing regression tests to see whether it reacts to "the right" changes).

To do so, we are trying to programmatically create ResourceSetChangeEvents in JUnit. Currently, this fails with an IllegalArgumentException, because we are unable to retrieve the TransactionalEditingDomain we are trying to retrieve (through TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain()).

Does anyone have input how you would go about testing these Listeners, or examples of such tests? I haven't manage to find anything suitable...

Cheers,
Grischa
Re: JUnit + ResourceSetListener [message #1837236 is a reply to message #1837232] Mon, 25 January 2021 16:41 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
Senior Member

Hi, Grischa,

If you're testing extensions of Papyrus, you may find it useful to employ the org.eclipse.papyrus.junit.utils.rules.ModelSetFixture class in your tests. This creates a complete (as complete as you need it) ModelSet for consistency with the Papyrus editing environment. Then your tests can drive changes in the resources in this fixture, and the TransactionalEditingDomain that manages the ModelSet will send the events that your listeners need.

This may be the easiest strategy to get working, because it provides all of the usual machinery and you can use Papyrus to create models to drive your tests.

Alternatively, mocking frameworks like PowerMock may be able to mock classes such as ResourceSetChangeEvent so that you can supply your tests with only the absolute minimum required of the API. I have not tried this in my own tests but I don't see why it shouldn't work. Mocking frameworks generally employ low-level JVM APIs to constructs objects, etc. so that assertions like the one giving you the IllegalArgumentException would be bypassed.

HTH,
Christian
Re: JUnit + ResourceSetListener [message #1837263 is a reply to message #1837236] Tue, 26 January 2021 12:44 Go to previous message
Grischa Liebel is currently offline Grischa LiebelFriend
Messages: 2
Registered: January 2021
Junior Member
Great, thanks Christian! We will try the ModelSetFixture :)

Cheers,
Grischa
Previous Topic:EOperation body annotation in subclass
Next Topic:Resolve an EClass that is a Proxy
Goto Forum:
  


Current Time: Fri Apr 26 13:11:13 GMT 2024

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

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

Back to the top