Home » Modeling » TMF (Xtext) » AbstractXtextTests and EPackage load
AbstractXtextTests and EPackage load [message #643821] |
Wed, 08 December 2010 11:57 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Re: AbstractXtextTests and EPackage load [message #643842 is a reply to message #643821] |
Wed, 08 December 2010 13:31 |
Ed Merks 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 |
|
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
HOME: http://www.lorenzobettini.it
TDD Book: https://leanpub.com/tdd-buildautomation-ci
Xtext Book: https://www.packtpub.com/application-development/implementing-domain-specific-languages-xtext-and-xtend-second-edition
|
|
|
Goto Forum:
Current Time: Tue Apr 23 12:26:17 GMT 2024
Powered by FUDForum. Page generated in 0.03023 seconds
|