Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » AbstractXtextTests and EPackage load
AbstractXtextTests and EPackage load [message #643821] Wed, 08 December 2010 11:57 Go to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi

I have a test class which inherits from AbstractXtextTests

inside this class I have two test methods which call another method
which performs these operations to load a genmodel (the variable model
is an instance of the model corresponding to the DSL)

URI uri = URI.createURI(genmodel);

ResourceSet resourceSet = model.eResource().getResourceSet();
Map<String, Object> extensionToFactoryMap = resourceSet
..getResourceFactoryRegistry().getExtensionToFactoryMap();

if (!extensionToFactoryMap.containsKey("genmodel")) {
EcoreResourceFactoryImpl ecoreFactory = new EcoreResourceFactoryImpl();
extensionToFactoryMap.put("genmodel", ecoreFactory);
GenModelPackage.eINSTANCE.eClass();
}

Resource resource = resourceSet.getResource(uri, true);

this code snippet works if I run one of the two test methods, but if I
run the entire test class as a suite, the second method fails with an
error like the following

org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1Diagnos ticWrappedException:
org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri
'http://www.eclipse.org/emf/2002/GenModel' not found.
( file:///home/bettini/work/xtext/typesystem/org.eclipse.xtext .typesystem.generator.tests/models/FJ.genmodel,
9, 58)

I can only think this is due to the way tearDown() is implemented in
AbstractXtextTests?

Note that the above two test methods produce the same error also if I
exchange their order: the second method in order always fails...

any clue please?

thanks in advance
Lorenzo


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: AbstractXtextTests and EPackage load [message #643842 is a reply to message #643821] Wed, 08 December 2010 13:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Lorenzo,

You'd be better to run as a plugin JUnit test. Failing that, the idiom
GenModelPackage.eINSTANCE.eClass() ensures that the GenModelPackage is
initialized and registered in the global registry, so in the failing
case, it seems likely that nothing is ensuring that this happens...


Lorenzo Bettini wrote:
> Hi
>
> I have a test class which inherits from AbstractXtextTests
>
> inside this class I have two test methods which call another method
> which performs these operations to load a genmodel (the variable model
> is an instance of the model corresponding to the DSL)
>
> URI uri = URI.createURI(genmodel);
>
> ResourceSet resourceSet = model.eResource().getResourceSet();
> Map<String, Object> extensionToFactoryMap = resourceSet
> .getResourceFactoryRegistry().getExtensionToFactoryMap();
>
> if (!extensionToFactoryMap.containsKey("genmodel")) {
> EcoreResourceFactoryImpl ecoreFactory = new
> EcoreResourceFactoryImpl();
> extensionToFactoryMap.put("genmodel", ecoreFactory);
> GenModelPackage.eINSTANCE.eClass();
> }
>
> Resource resource = resourceSet.getResource(uri, true);
>
> this code snippet works if I run one of the two test methods, but if I
> run the entire test class as a suite, the second method fails with an
> error like the following
>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1Diagnos ticWrappedException:
> org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri
> 'http://www.eclipse.org/emf/2002/GenModel' not found.
> ( file:///home/bettini/work/xtext/typesystem/org.eclipse.xtext .typesystem.generator.tests/models/FJ.genmodel,
> 9, 58)
>
> I can only think this is due to the way tearDown() is implemented in
> AbstractXtextTests?
>
> Note that the above two test methods produce the same error also if I
> exchange their order: the second method in order always fails...
>
> any clue please?
>
> thanks in advance
> Lorenzo
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: AbstractXtextTests and EPackage load [message #644066 is a reply to message #643842] Thu, 09 December 2010 10:20 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Thanks for your answer Ed.

what worries me is that it works when the first method is invoked, but
not when the second one is invoked (and it does not depend on the
methods themselves but on the order they are executed in the test
suite); so I was curious about that: probably the tearDown method of
the abstract test class in xtext tears down too much ;)

cheers
Lorenzo

On 12/08/2010 02:31 PM, Ed Merks wrote:
> Lorenzo,
>
> You'd be better to run as a plugin JUnit test. Failing that, the idiom
> GenModelPackage.eINSTANCE.eClass() ensures that the GenModelPackage is
> initialized and registered in the global registry, so in the failing
> case, it seems likely that nothing is ensuring that this happens...
>
>
> Lorenzo Bettini wrote:
>> Hi
>>
>> I have a test class which inherits from AbstractXtextTests
>>
>> inside this class I have two test methods which call another method
>> which performs these operations to load a genmodel (the variable model
>> is an instance of the model corresponding to the DSL)
>>
>> URI uri = URI.createURI(genmodel);
>>
>> ResourceSet resourceSet = model.eResource().getResourceSet();
>> Map<String, Object> extensionToFactoryMap = resourceSet
>> .getResourceFactoryRegistry().getExtensionToFactoryMap();
>>
>> if (!extensionToFactoryMap.containsKey("genmodel")) {
>> EcoreResourceFactoryImpl ecoreFactory = new EcoreResourceFactoryImpl();
>> extensionToFactoryMap.put("genmodel", ecoreFactory);
>> GenModelPackage.eINSTANCE.eClass();
>> }
>>
>> Resource resource = resourceSet.getResource(uri, true);
>>
>> this code snippet works if I run one of the two test methods, but if I
>> run the entire test class as a suite, the second method fails with an
>> error like the following
>>
>> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1Diagnos ticWrappedException:
>> org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri
>> 'http://www.eclipse.org/emf/2002/GenModel' not found.
>> ( file:///home/bettini/work/xtext/typesystem/org.eclipse.xtext .typesystem.generator.tests/models/FJ.genmodel,
>> 9, 58)
>>
>> I can only think this is due to the way tearDown() is implemented in
>> AbstractXtextTests?
>>
>> Note that the above two test methods produce the same error also if I
>> exchange their order: the second method in order always fails...
>>
>> any clue please?
>>
>> thanks in advance
>> Lorenzo
>>
>>


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Previous Topic:XText 2 and refactoring
Next Topic:Validation problem with UriBasedReader and several model files
Goto Forum:
  


Current Time: Tue Apr 23 12:26:17 GMT 2024

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

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

Back to the top