Unit Test for a Language which cross-references an Ecore model [message #1745193] |
Thu, 06 October 2016 04:58  |
Eclipse User |
|
|
|
Dear all,
given a xtext grammar which references an ecore model such as the following works just fine when running Eclipse.
Model:
'MyModel' myModel=[ecore::EPackage] '{' ... '}'
;
However, how do I unit test such a language? I came across some previous threads which discussed the testing of languages with cross-references to other xtext languages.
There you had to create a ResourceSet and pass it to the ParseHelper<>.parse method. Unfortunately, that does not work for Ecore resources because they cannot be casted to XtextResources and therefore "resource.contents.head.assertNoIssues" results in a ClassCastException: "org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl$1 cannot be cast to org.eclipse.xtext.resource.XtextResource".
Is there another way to create a ResourceSet with an Ecore model?
class LanguageParsingTest {
@Inject extension ParseHelper<MyModel>
@Inject extension ValidationTestHelper
@Inject
Provider<XtextResourceSet> resourceSetProvider;
@Test
def void testParsing() {
val fooPackage = EcoreFactory::eINSTANCE.createEPackage
fooPackage.name = "foo"
fooPackage.nsPrefix ="foo"
fooPackage.nsURI = "http://foo"
val resourceSet = resourceSetProvider.get
val resource = resourceSet.createResource(URI.createURI("foo.ecore"))
resource.contents.add(fooPackage)
resource.save(null)
resourceSet.getPackageRegistry().put(fooPackage.getNsURI(), fooPackage);
resource.load(null);
resource.contents.head.assertNoIssues
val model = '''MyModel foo { }'''.parse(resourceSet)
model.assertNotNull
model.assertNoErrors
}
}
Thank you very much for your help!
[Updated on: Thu, 06 October 2016 13:59] by Moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03962 seconds